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

Triples containing Variable result in invalid turtle #383

Open
mrkvon opened this issue Apr 3, 2024 · 5 comments
Open

Triples containing Variable result in invalid turtle #383

mrkvon opened this issue Apr 3, 2024 · 5 comments

Comments

@mrkvon
Copy link

mrkvon commented Apr 3, 2024

When creating a triple with Variables in it, and then writing it as text/turtle, the outcome is invalid turtle.

const writer = new Writer({ format: 'text/turtle' })
writer.addQuad(new Quad(new Variable('a'), new NamedNode(foaf.knows), new Variable('c')))
writer.end((err, result) => {
  console.log(result)
})

This yields

?a <http://xmlns.com/foaf/0.1/knows> ?c.

which is invalid turtle.

Along the argumentation in #165, this could rather throw error or gracefully drop the triples containing Variable.

@mrkvon mrkvon changed the title Triples with Variable result in invalid turtle Triples containing Variable result in invalid turtle Apr 3, 2024
@RubenVerborgh
Copy link
Member

Working as intended (writer always expects valid input), but we can indeed accept a PR along the lines of #165 to perform optional input sanitization.

@mrkvon
Copy link
Author

mrkvon commented Apr 3, 2024

Indeed relevant only if a feature like #339 (comment) is included.

@bergos
Copy link
Member

bergos commented Apr 3, 2024

May I throw in one of my recent blog posts RDF/JS for Data Processing. Summary of the blog post: Validation is a spectrum, and what is valid RDF depends on the context. That's why I like a modular approach, and rdf-validation could be one building block. Nevertheless, if a media type is given, it's legit that a serializer validates that the output is according to the spec. But I would recommend using flags, as mentioned in #339, to control the behavior, and ideally there is no performance impact.

@nichtich
Copy link

With N3 it's easy to accidently transform valid RDF into invalid RDF if the output format supports a smaller part of RDF. Examples include variables (this issue), graphs (#339) and relative IRIs (not mentioned yet). I'd welcome a general flag to make sure a writer only emits valid data.

@nichtich
Copy link

A filter function for each output format to maps a Quad to a (possibly reduced) Quad or null would also help. For instance TurtleFilter would remove the named graph of a Quad and return null if any of subject, object, predicate is a variable.

In any case the documentation should mention current behaviour here similar to the statement on parsing:

By default, N3.Parser parses a permissive superset of Turtle, TriG, N-Triples, and N-Quads.
For strict compatibility with any of those languages, pass a format argument upon creation:

The current documentation is misleading:

By default, N3.Writer writes Turtle (or TriG if some quads are in a named graph).

yes.

To write N-Triples (or N-Quads) instead, pass a format argument upon creation:

This does not ensure strict compatibility like the Parser does. It's a design choice but reading the documentation one might assume strict writing as well.

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

4 participants