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

RDFJS compliance: blank node values should not be prepended by _: #244

Closed
pietercolpaert opened this issue Apr 24, 2018 · 7 comments
Closed

Comments

@pietercolpaert
Copy link

RDFJS defines in its specification that:

value blank node name as a string, without any serialization specific prefixes, e.g. when parsing, if the data was sourced from Turtle, remove "_:", if it was sourced from RDF/XML, do not change the blank node name (example: "blank3")

However, jsonld.js does not remove _: when executing the toRDF code. This can be found in multiple places. One example:

termType: id.startsWith('_:') ? 'BlankNode' : 'NamedNode',

@pietercolpaert pietercolpaert changed the title RDFJS compliance: blank nodes not prepended by a _: RDFJS compliance: blank node values should not be prepended by _: Apr 24, 2018
rubensworks pushed a commit to ddvlanck/rdf-parser-jsonld that referenced this issue Aug 31, 2018
This contains fixes for the following open
non-RDFJS-compliance issues in jsonld:
* digitalbazaar/jsonld.js#243
* digitalbazaar/jsonld.js#244
@dlongley
Copy link
Member

Closing as not a bug. If there's an actual bug here, please re-open and provide a test case with expected output and actual output that does not match.

@joeltg
Copy link

joeltg commented Aug 9, 2020

I also care about this issue! Right now, anybody trying to integrate jsonld.js with any other popular RDF library like n3.js has to manually run some snippet like this on the output of toRDF:

const dataset = await jsonld.toRDF(doc, {})
for (const quad of dataset) {
	if (quad.subject.value.startsWith("_:")) {
		quad.subject.value = quad.subject.value.slice(2)
	}
	if (quad.object.value.startsWith("_:")) {
		quad.object.value = quad.object.value.slice(2)
	}
	if (quad.graph.value.startsWith("_:")) {
		quad.graph.value = quad.graph.value.slice(2)
	}
}
// *now* we can import `dataset` into an n3.js store...

... which is really annoying!

A concrete test case would be:

jsonld.toRDF({ "http://schema.org/knows": { "@id": "_:b1" } }, {})

which produces

[
  {
    subject: { termType: 'BlankNode', value: '_:b0' },
    predicate: { termType: 'NamedNode', value: 'http://schema.org/knows' },
    object: { termType: 'BlankNode', value: '_:b1' },
    graph: { termType: 'DefaultGraph', value: '' }
  }
]

but should produce

[
  {
    subject: { termType: 'BlankNode', value: 'b0' },
    predicate: { termType: 'NamedNode', value: 'http://schema.org/knows' },
    object: { termType: 'BlankNode', value: 'b1' },
    graph: { termType: 'DefaultGraph', value: '' }
  }
]

The relevant portion of the RDFJS spec was quoted in the original comment - the jsonld.js documentation doesn't explicitly mention RDFJS anywhere as far as I can tell, but it's clearly the intended representation.

Edit: I should add that I'd be happy to open a pull request fixing this in lib/toRdf.js if you're interested, although I don't understand the rest of the codebase well enough to know if anything else depends on the current behavior

@tpluscode
Copy link
Contributor

@pietercolpaert would you mind reopening this? This is in fact a problem which bit me more than once

@pietercolpaert
Copy link
Author

I cannot re-open this very issue - please check with @dlongley who indicated a couple of years ago a new issue with a proposal for a PR with a test case will do the trick.

Today I just use https://github.com/rubensworks/jsonld-streaming-parser.js instead

@tpluscode
Copy link
Contributor

tpluscode commented Feb 26, 2024

So do I, mostly. But for a quick hack, jsonld.promises.toRDF is tempting given its simplicity. And then _:_: happens :)

@dlongley
Copy link
Member

PR #548 might address this, I'm not sure.

@davidlehn
Copy link
Member

The rdf-canonize internals were changed to hopefully address this issue around here: digitalbazaar/rdf-canonize@b36b1c9. Fixing and updating jsonld.js to use the newer rdf-canonize has dragged on longer than expected (we're busy). Hopefully when that is merged it will fix the issue. That PR could certainly use some testing if you have the time.

Also I don't think jsonld.promises is needed anymore? The main calls should be async.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants