rdfjs / N3.js

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

Serialize subject and predicate literals correctly #330

Open joachimvh opened 1 year ago

joachimvh commented 1 year ago

Closes https://github.com/rdfjs/N3.js/issues/329

This does have as disadvantage that invalid turtle will be generated if quads get added to the writer that can not be represented in turtle. If that is a problem, an alternative solution would be to have variants of the writer, similarly to how n-quads get handled, where the turtle version throws an error if it encounters a literal in the subject/predicate position and the N3 version handles it correctly. Let me know what you prefer and I can update the PR.

RubenVerborgh commented 1 year ago

invalid turtle will be generated if quads get added to the writer that can not be represented in turtle

I wonder if this has repercussions for #339; should we have a generic flag for "out of syntax features"?

jeswr commented 1 year ago

I wonder if this has repercussions for https://github.com/rdfjs/N3.js/pull/339; should we have a generic flag for "out of syntax features"?

...perhaps, though I worry about performance degradation doing it internally; we could just supply validTurtleQuad, validN3Quad etc. functions that consumers can optionally pass their data through first to validate.

jeswr commented 1 year ago

As an aside - are there any RDF syntaxes that don't support a shortand in the subject or object position? If not then the following logic could just be moved to _encodeTerm https://github.com/rdfjs/N3.js/blob/c7540c4c5cd4fe40447dd90a683e1ea878e75519/src/N3Writer.js#L207

joachimvh commented 1 year ago

As an aside - are there any RDF syntaxes that don't support a shortand in the subject or object position?

Turtle only allows it in the predicate position.