rdflib.js
rdflib.js copied to clipboard
Fix for `BlankNode` as `NamedNode` when parsing JSON-LD #555
The JSON-LD parser currently uses the JSON-LD flattening algorithm of jsonld.js
. This algorithm assigns @id
attributes to blank nodes, but the JSON-LD parser only creates a BlankNode
when no @id
is present.
This means that currently, the blank nodes in JSON-LD are interpreted as NamedNode
, which is incorrect.
This pull request does the following:
- Add a check to see whether the
@id
value starts with_:
. - If it does, it is a
BlankNode
, otherwise it is aNamedNode
. - If it is a blank node, strip it from the
_:
as this will be added by the instantiation of theBlankNode
class. - Make sure to perform this check whenever a new object node is created (there were three separate checks in the code)
This fixes #555
Also raised an issue in rdf-canonize
(https://github.com/digitalbazaar/rdf-canonize/issues/45) to flag the problem that blank node identifiers generated by jsonld.js
are not unique across loads (this is the cause of issue #405 )
@RinkeHoekstra CI fails. If I only add your first commit https://github.com/linkeddata/rdflib.js/pull/558/commits/e0d332e0cb53207bbb0879626b6dc1f19e4b1b3f it does not fail locally
I think you should only keep this one and make other PR for your last 2 commits that are not directly related so I can merge your PR.
resolved with https://github.com/linkeddata/rdflib.js/pull/589/commits/17052b62209a92112d21a01dd8d2cd2f5fde16a3