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
Blank nodes defined in RDF are converted as Relative IRI Node #474
Comments
When I tried with the option Specifically, const jsonld = require('jsonld');
const rdfDoc = `
<http://example.org#book1> <http://purl.org/dc/terms/description> "this is book 1" .
<http://example.org#book1> <http://purl.org/dc/terms/hasPart> _:b0 .
<http://example.org#book1> <http://purl.org/dc/terms/hasPart> _:b1 .
<http://example.org#book1> <http://purl.org/dc/terms/title> "book 1" .
_:b0 <http://purl.org/dc/terms/title> "section 1" .
_:b1 <http://purl.org/dc/terms/title> "section 2" .
`;
(async () => {
let jsondoc = await jsonld.fromRDF(rdfDoc, {format: 'application/n-quads'});
console.log("<<Encode:RDF2JSONLD>>");
console.log(JSON.stringify(jsondoc, null, 2); // output1
let rdfDataset = await jsonld.toRDF(jsondoc, {format: 'application/n-quads'});
console.log("<<Decode:JSONLD2RDF>>");
console.log(rdfDataset);
})() results in
and the re-decoded RDF does match the original one.
|
I found that using Lines 57 to 119 in 20e2286
According to the description of BlankNode interface in RDF/JS Spec,
The library "n3" complies with this spec and consequently the "@id" of BlankNode in JSON-LD become non-"_:xxx" form |
Looks like I'm not sure how interoperability is supposed to work between implementations as far as blank nodes go. They are kind of tricky. How can code know what is a blank node if it doesn't have a known special naming pattern? In JSON-LD, the terminology section says blank nodes have the Have you tried the setting |
Oops! I corrected Unfortunately, I tried the setting // Parse RDF and stdout the {termType, id , value} of subjects.
Readable.from(`_:b0 <http://purl.org/dc/terms/title> "section 1" .`)
.pipe(new N3.StreamParser({ format:'N-Quad', blankNodePrefix: '_:' }))
// .pipe(new N3.StreamParser({ format:'Turtle', blankNodePrefix: '_:' }))
.pipe(new Transform({
writableObjectMode: true,
transform(quad, encoding, done){
const subject = quad.subject;
this.push("Subject "+JSON.stringify({termType:subject.termType, id: subject.id, value: subject.value})+'\n');
done();
}
}))
.pipe(process.stdout);
// >> Subject {"termType":"BlankNode","id":"_:b0","value":"b0"} According to the Term interface in RDF/JS, there is termType member and it is likely that we can know which one is blank node. Anyway it seems good to use |
results in
and the re-decoded RDF does not match the original one.
Why blank nodes in RDF are encoded as Relative IRI Node?
Are there any way to encode blank nodes in RDF as objects with "@id" in the form of "_:xxx" ?
The text was updated successfully, but these errors were encountered: