-
Notifications
You must be signed in to change notification settings - Fork 15
Closed
Description
graphdb.jsonld.get causes an error when the jsonld document being retrieved has a '@type' property that is an array.
This is the LD document I was attempting to retreive: http://dbpedia.org/data/Ratatat.jsonld
Here is the error (I logged it then threw it):
{ name: 'jsonld.CompactError',
message: 'Could not expand input before compaction.',
details:
{ cause:
{ name: 'jsonld.SyntaxError',
message: 'Invalid JSON-LD syntax; "@type" value must a string, an array of strings, or an empty object.',
details: [Object] } } }
/home/ameen/Desktop/Projects/journalism/jsonld/test.js:239
if (err) throw err;
^
jsonld.CompactError: Could not expand input before compaction.
at /home/ameen/Desktop/Projects/journalism/jsonld/node_modules/levelgraph-jsonld/node_modules/jsonld/js/jsonld.js:137:23
at /home/ameen/Desktop/Projects/journalism/jsonld/node_modules/levelgraph-jsonld/node_modules/jsonld/js/jsonld.js:381:16
at finished (/home/ameen/Desktop/Projects/journalism/jsonld/node_modules/levelgraph-jsonld/node_modules/jsonld/js/jsonld.js:5838:7)
at _retrieveContextUrls.retrieve (/home/ameen/Desktop/Projects/journalism/jsonld/node_modules/levelgraph-jsonld/node_modules/jsonld/js/jsonld.js:5844:7)
at _retrieveContextUrls (/home/ameen/Desktop/Projects/journalism/jsonld/node_modules/levelgraph-jsonld/node_modules/jsonld/js/jsonld.js:5953:3)
at expand (/home/ameen/Desktop/Projects/journalism/jsonld/node_modules/levelgraph-jsonld/node_modules/jsonld/js/jsonld.js:326:5)
at /home/ameen/Desktop/Projects/journalism/jsonld/node_modules/levelgraph-jsonld/node_modules/jsonld/js/jsonld.js:304:5
at process._tickCallback (node.js:415:13)
At first I thought it might be an issue with jsonld, but using jsonld.expand on the document directly produced no errors.
The problem lies with the jsonld document that is being passed to jsonld.expand in levelgraph - more specifically, in how the ['@type'] array is expanded from the triples.
This is the block responsible for expanding the type array from triples.
if (triple.predicate === RDFTYPE) {
if (acc[triple.subject]['@type']) {
acc[triple.subject]['@type'] = [acc[triple.subject]['@type']];
acc[triple.subject]['@type'].push(triple.object);
} else {
acc[triple.subject]['@type'] = triple.object;
}
cb(null, acc);
}When this line is removed, it works for me
acc[triple.subject]['@type'] = [acc[triple.subject]['@type']];Otherwise my ['@type'] array ends up looking something like this:
"@type": [
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
[
"http://dbpedia.org/class/yago/Abstraction100002137",
"http://dbpedia.org/class/yago/AmericanHouseMusicGroups"
],
"http://dbpedia.org/class/yago/AmericanPost-rockGroups"
],
"http://dbpedia.org/class/yago/Communication100033020"
],
"http://dbpedia.org/class/yago/Couple113743605"
],
"http://dbpedia.org/class/yago/DefiniteQuantity113576101"
],
"http://dbpedia.org/class/yago/Device107068844"
],
"http://dbpedia.org/class/yago/Digit113741022"
],
"http://dbpedia.org/class/yago/ElectronicMusicDuos"
],
"http://dbpedia.org/class/yago/ElectronicMusicGroupsFromNewYork"
],
"http://dbpedia.org/class/yago/ExpressiveStyle107066659"
],
"http://dbpedia.org/class/yago/Group100031264"
],
"http://dbpedia.org/class/yago/Integer113728499"
],
"http://dbpedia.org/class/yago/Measure100033615"
],
"http://dbpedia.org/class/yago/Number113582013"
],
"http://dbpedia.org/class/yago/Onomatopoeia107104574"
],
"http://dbpedia.org/class/yago/Onomatopoeias"
],
"http://dbpedia.org/class/yago/RhetoricalDevice107098193"
],
"http://dbpedia.org/class/yago/Two113743269"
],
"http://dbpedia.org/ontology/Agent"
],
"http://dbpedia.org/ontology/Band"
],
"http://dbpedia.org/ontology/Organisation"
],
"http://schema.org/MusicGroup"
],
"http://schema.org/Organization"
],
"http://www.w3.org/2002/07/owl#Thing"
]Metadata
Metadata
Assignees
Labels
No labels