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

Fix for BlankNode as NamedNode when parsing JSON-LD #555 #558

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/jsonldparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ export function jsonldObjectToTerm (kb, obj) {
}

if (Object.prototype.hasOwnProperty.call(obj, '@id')) {
return kb.rdfFactory.namedNode(obj['@id'])
if (obj['@id'].startsWith('_:')) {
// This object is a Blank Node.. pass the id without the preceding _:
return kb.rdfFactory.blankNode(obj['@id'].substring(2));
} else {
// This object is a Named Node
return kb.rdfFactory.namedNode(obj['@id']);
}
}

if (Object.prototype.hasOwnProperty.call(obj, '@language')) {
Expand All @@ -37,14 +43,14 @@ export function jsonldObjectToTerm (kb, obj) {
return kb.rdfFactory.literal(obj['@value'])
}

return kb.rdfFactory.literal(obj)
return kb.rdfFactory.literal();
}

/**
* Adds the statements in a json-ld list object to {kb}.
*/
function listToStatements (kb, obj) {
const listId = obj['@id'] ? kb.rdfFactory.namedNode(obj['@id']) : kb.rdfFactory.blankNode()
const listId = jsonldObjectToTerm(kb, obj);

const items = obj['@list'].map((listItem => jsonldObjectToTerm(kb, listItem)))
const statements = arrayToStatements(kb.rdfFactory, listId, items)
Expand Down Expand Up @@ -84,9 +90,7 @@ export default function jsonldParser (str, kb, base, callback) {


function processResource(kb, base, flatResource) {
const id = flatResource['@id']
? kb.rdfFactory.namedNode(flatResource['@id'])
: kb.rdfFactory.blankNode()
const id = jsonldObjectToTerm(kb, flatResource);

for (const property of Object.keys(flatResource)) {
if (property === '@id') {
Expand Down