rdfjs / N3.js

Lightning fast, spec-compatible, streaming RDF for JavaScript
http://rdf.js.org/N3.js/
Other
676 stars 127 forks source link

Add support for empty graphs in the subject and object positions #374

Open Dexagod opened 7 months ago

Dexagod commented 7 months ago

This PR contains a fix for parsing empty graphs in subject and object positions when parsing empty graphs.

I added some test cases that check for empty graphs in the subject and object position, both in the default graph, and contained in a subgraph.

Note that this does NOT work for empty graphs in the predicate position. I have added tests for these as well, but they are commented out at the moment.

RubenVerborgh commented 7 months ago

@Dexagod Are empty graphs supported by both N3 (seems yes) and RDF-star (citation needed)? If not, we will need a check on content type.

RubenVerborgh commented 7 months ago

(I might be overcautious here, and maybe this code doesn't hit with RDF-star; just want to be sure.)

jeswr commented 7 months ago

@Dexagod indeed we will only want to do this in N3 mode and error otherwise.

@RubenVerborgh this PR is not about RDF-Star; it is specifically for N3 content types in order to align with the decisions made in https://github.com/w3c/N3/issues/185 & https://github.com/rdfjs/types/issues/37 in the next major release.

In particular note that there are now N3 spec tests for what has been implemented here https://github.com/w3c/N3/pull/202.

RubenVerborgh commented 7 months ago

Ack about it being for N3; just want to make sure it doesn't fire at the wrong time. But perhaps _readFormulaTail is only accessed in N3 mode in any case.

Dexagod commented 7 months ago

Yep, synced on it with Jos and I indeed was mistaken. I'm setting it straight atm in terms of the true needing to be injected directly instead of with rdf:value. I'll double check to make sure the routine only fires in N3 mode.

Dexagod commented 7 months ago

Empty graphs are now correctly represented as "true"^^xsd:boolean.

I checked and the _readFormulaTail function is only called in N3 mode.

Should I check if RDF-star is enabled and throw an error in case it is?

jeswr commented 7 months ago

Should I check if RDF-star is enabled and throw an error in case it is?

No, I do not think we should error when N3 and star are both enabled. There is just no particular behavior we have to comply with as there is no N3-star spec.