Skip to content

Commit

Permalink
Bugfix in RDFJS triples bridge to json-ld framing
Browse files Browse the repository at this point in the history
  • Loading branch information
pietercolpaert committed Jan 6, 2022
1 parent b80aaa2 commit 38082ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions lib/ldfetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,21 @@ module.exports = class extends EventEmitter {
var objects = {"@graph": []};
var graphs = {};
for (var triple of triples) {
let subjectURI = triple.subject.value;
let objectURI = triple.object.value;
//Json-LD lib uses underscores when blanknode
if (triple.subject.termType === 'BlankNode') {
triple.subject.value = '_:' + triple.subject.value;
}
if (triple.predicate.termType === 'BlankNode') {
triple.predicate.value = '_:' + triple.predicate.value;
subjectURI = '_:' + triple.subject.value;
}
if (triple.object.termType === 'BlankNode') {
triple.object.value = '_:' + triple.object.value;
}
if (triple.graph.termType === 'BlankNode') {
triple.graph.value = '_:' + triple.graph.value;
objectURI = '_:' + triple.object.value;
}

if (triple.graph.value && !graphs[triple.graph.value])
graphs[triple.graph.value] = {"@id": triple.graph.value, "@graph" : []};

var obj = {
"@id" : triple.subject.value,
"@id" : subjectURI,
};
if (triple.object.termType === 'Literal') {
obj[triple.predicate.value] = {"@value" : triple.object.value};
Expand All @@ -68,14 +66,18 @@ module.exports = class extends EventEmitter {
if (triple.object.datatype)
obj[triple.predicate.value]["@type"] = triple.object.datatype.value;
} else if (triple.predicate.value === 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type') {
obj["@type"] = triple.object.value;
obj["@type"] = objectURI;
} else {
obj[triple.predicate.value] = {"@id": triple.object.value};
obj[triple.predicate.value] = {"@id": objectURI};
}
if (!triple.graph.value) {
objects["@graph"].push(obj);
} else {
graphs[triple.graph.value]["@graph"].push(obj);
let graphURI = triple.graph.value;
if (triple.graph.termType === 'BlankNode') {
graphURI = '_:' + triple.graph.value;
}
graphs[graphURI]["@graph"].push(obj);
}
}
objects["@graph"].push(Object.values(graphs));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ldfetch",
"version": "1.2.2",
"version": "1.2.4",
"description": "Linked Data Fetch HTTP RDF library for NodeJS and browser",
"bin": "bin/ldfetch.js",
"main": "lib/ldfetch.js",
Expand Down

0 comments on commit 38082ad

Please sign in to comment.