Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph missing from outer Quads when parsing JSON-LD-star #120

Open
futpib opened this issue Oct 28, 2023 · 1 comment
Open

Graph missing from outer Quads when parsing JSON-LD-star #120

futpib opened this issue Oct 28, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@futpib
Copy link

futpib commented Oct 28, 2023

Running the code below logs an equivalent of this RDF-star (notice that 2nd and 3rd quads are missing the 4th "graph" element):

<http://foo/bob> <http://foo/knows> <http://foo/alice> <http://foo/graphid> .
<<<http://foo/bob> <http://foo/knows> <http://foo/alice> <http://foo/graphid>>> <http://foo/accordingTo> <http://foo/alice> .
<http://foo/bob> <http://foo/claims> <<<http://foo/bob> <http://foo/knows> <http://foo/alice> <http://foo/graphid>>> .

But it seems that this RDF-star is expected:

<http://foo/bob> <http://foo/knows> <http://foo/alice> <http://foo/graphid> .
<<<http://foo/bob> <http://foo/knows> <http://foo/alice> <http://foo/graphid>>> <http://foo/accordingTo> <http://foo/alice> <http://foo/graphid> .
<http://foo/bob> <http://foo/claims> <<<http://foo/bob> <http://foo/knows> <http://foo/alice> <http://foo/graphid>>> <http://foo/graphid> .
const { Readable } = require('stream');
const { JsonLdParser } = require('jsonld-streaming-parser');

// This is example 6 from https://json-ld.github.io/json-ld-star/#example-reversing-annotations
// modified by wrapping everything into a "@graph"
const document = {
    "@context": {
        "@base": "http://foo/",
        "@vocab": "http://foo/",
        "accordingTo": {"@type": "@id"},
        "claimedBy": {"@reverse": "http://foo/claims", "@type": "@id"}
    },
    "@id": "graphid",
    "@graph": {
        "@id": "bob",
        "knows": {
            "@id": "alice",
            "@annotation": {
                "accordingTo": "alice",
                "claimedBy": "bob"
            }
        }
    }
};

const input = new Readable.from([ JSON.stringify(document) ]);
const parser = (new JsonLdParser()).import(input);

parser.on('data', (quad) => {
    console.log(quad);
});

new Promise((resolve, reject) => {
    parser.on('end', resolve);
    parser.on('error', reject);
});
Exact output

Quad {
  termType: 'Quad',
  value: '',
  subject: NamedNode { termType: 'NamedNode', value: 'http://foo/bob' },
  predicate: NamedNode { termType: 'NamedNode', value: 'http://foo/knows' },
  object: NamedNode { termType: 'NamedNode', value: 'http://foo/alice' },
  graph: NamedNode { termType: 'NamedNode', value: 'http://foo/graphid' }
}
Quad {
  termType: 'Quad',
  value: '',
  subject: Quad {
    termType: 'Quad',
    value: '',
    subject: NamedNode { termType: 'NamedNode', value: 'http://foo/bob' },
    predicate: NamedNode { termType: 'NamedNode', value: 'http://foo/knows' },
    object: NamedNode { termType: 'NamedNode', value: 'http://foo/alice' },
    graph: NamedNode { termType: 'NamedNode', value: 'http://foo/graphid' }
  },
  predicate: NamedNode { termType: 'NamedNode', value: 'http://foo/accordingTo' },
  object: NamedNode { termType: 'NamedNode', value: 'http://foo/alice' },
  graph: DefaultGraph { termType: 'DefaultGraph', value: '' }
}
Quad {
  termType: 'Quad',
  value: '',
  subject: NamedNode { termType: 'NamedNode', value: 'http://foo/bob' },
  predicate: NamedNode { termType: 'NamedNode', value: 'http://foo/claims' },
  object: Quad {
    termType: 'Quad',
    value: '',
    subject: NamedNode { termType: 'NamedNode', value: 'http://foo/bob' },
    predicate: NamedNode { termType: 'NamedNode', value: 'http://foo/knows' },
    object: NamedNode { termType: 'NamedNode', value: 'http://foo/alice' },
    graph: NamedNode { termType: 'NamedNode', value: 'http://foo/graphid' }
  },
  graph: DefaultGraph { termType: 'DefaultGraph', value: '' }
}

@rubensworks rubensworks added the bug Something isn't working label Oct 30, 2023
@rubensworks
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants