From e0d332e0cb53207bbb0879626b6dc1f19e4b1b3f Mon Sep 17 00:00:00 2001 From: Rinke Hoekstra Date: Mon, 18 Jul 2022 12:38:24 +0200 Subject: [PATCH 1/4] Added check for Blank Node id that should fix #555 --- src/jsonldparser.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/jsonldparser.js b/src/jsonldparser.js index 5fbc9503d..2fd81dbcf 100644 --- a/src/jsonldparser.js +++ b/src/jsonldparser.js @@ -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 + return kb.rdfFactory.blankNode(obj['@id']); + } else { + // This object is a Named Node + return kb.rdfFactory.namedNode(obj['@id']); + } } if (Object.prototype.hasOwnProperty.call(obj, '@language')) { From b6724efb47f426ebad5378a046eb7465db146a3b Mon Sep 17 00:00:00 2001 From: Rinke Hoekstra Date: Mon, 18 Jul 2022 14:01:01 +0200 Subject: [PATCH 2/4] Using the standard jsonldObjectToTerm function for each term to ensure consistency. --- src/jsonldparser.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/jsonldparser.js b/src/jsonldparser.js index 2fd81dbcf..faa1da2ed 100644 --- a/src/jsonldparser.js +++ b/src/jsonldparser.js @@ -23,8 +23,8 @@ export function jsonldObjectToTerm (kb, obj) { if (Object.prototype.hasOwnProperty.call(obj, '@id')) { if (obj['@id'].startsWith('_:')) { - // This object is a Blank Node - return kb.rdfFactory.blankNode(obj['@id']); + // 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']); @@ -43,14 +43,17 @@ export function jsonldObjectToTerm (kb, obj) { return kb.rdfFactory.literal(obj['@value']) } - return kb.rdfFactory.literal(obj) + // I'm not sure we should return a literal if we don't have any of the above. + // I think this should be a blank node by default + return kb.rdfFactory.BlankNode(); + // return kb.rdfFactory.literal(obj) } /** * 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) @@ -90,9 +93,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') { From cb2090083040d5f1d906605829193a8a8245a21d Mon Sep 17 00:00:00 2001 From: Rinke Hoekstra Date: Tue, 19 Jul 2022 09:34:35 +0200 Subject: [PATCH 3/4] Will return literal anyway as this is a separate discussion. --- src/jsonldparser.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/jsonldparser.js b/src/jsonldparser.js index faa1da2ed..e4c6f1213 100644 --- a/src/jsonldparser.js +++ b/src/jsonldparser.js @@ -43,10 +43,7 @@ export function jsonldObjectToTerm (kb, obj) { return kb.rdfFactory.literal(obj['@value']) } - // I'm not sure we should return a literal if we don't have any of the above. - // I think this should be a blank node by default - return kb.rdfFactory.BlankNode(); - // return kb.rdfFactory.literal(obj) + return kb.rdfFactory.literal(); } /** From 8ae780e577f09c63b8935f4d16eee4eaeacac479 Mon Sep 17 00:00:00 2001 From: Rinke Hoekstra Date: Tue, 19 Jul 2022 10:50:55 +0200 Subject: [PATCH 4/4] Added `prepare` hook for building directly from source (GitHub) --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index e6f5c44c6..5baf4af0f 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,7 @@ "build:browser": "webpack --progress", "build:types": "tsc --emitDeclarationOnly -d --moduleResolution node --declarationDir lib", "doc": "typedoc --out ./doc ./src/index.ts --excludePrivate --excludeInternal --tsconfig ./tsconfig.json", + "prepare": "npm run build && npm run build:types && npm run build:browser && npm run build:esm", "prepublishOnly": "npm ci && npm run build && npm run build:types && npm run build:browser && npm run build:esm", "postversion": "git push --follow-tags", "start": "webpack serve --port 4800",