Closed Ostrzyciel closed 3 months ago
I agree that this looks like a bug, a PR to fix this would be welcome
Hi @Ostrzyciel - thank you for the detailed report. your example code works fine on my machine.
The JSON-LD is a plain old bug. The quad.isTriple()
is not handled.
The three choices have slightly different meanings:
null
(constant Quad.tripleInQuad
) is for sending triples where a quad is expected. It is internal.Quad.defaultGraphIRI
is the contract name of the default graph for applications.Quad.defaultGraphNodeGenerated
is an internal name (but not parsers) where a quad is for the default graph.The last two are covered by Quad.isDefaultGraph(node)
. They are different (external/.internal) although only slightly so maybe it wasn't necessary to split the concepts.
The other cases need tracking down and checking.
The deserialized Quad.defaultGraphIRI
is consequence of DatasetGraph.find
, not the serialization/deserialization. The parser output goes to a StreamRDF
where triples and quads have different handlers.
@afs Thank you for the detailed answer, that actually explains a lot!
I've updated the code to read directly from StreamRDF
instead of constructing a dataset – the results now are different:
Quad.defaultGraphNodeGenerated
So, to summarize (please correct me if I'm wrong here):
StreamRDF.quad(Quad(Quad.defaultGraphNodeGenerated, _, _, _))
– this is something to fix in my parser.StreamRDF.triple
.quad.isTriple()
, should output a triple (if the format supports it), or a quad in the default graph otherwise.Quad.isDefaultGraph()
, should output a quad in the default graph (if the format supports it), or a triple otherwise.I will try to fix the JSON-LD and TriG issues in a PR.
Version
5.0.0
What happened?
To be honest, I don't know if this is a bug or I'm just horribly confused. I wrote a deserializer for Jena that outputs quads with "null" in the graph term position when it's a default graph. When I then tried to serialize such a dataset using RIOT's serializers, I've noticed that for JSON-LD 1.1 the serialization fails completely, while for others it works.
I dug deeper and found out that Jena has 3 ways to represent the default graph:
null
,Quad.defaultGraphIRI
, andQuad.defaultGraphNodeGenerated
. I read the javadoc of the latter two and honestly, I still don't fully understand what's the difference. I then checked how the different RIOT writer implementations handle the different flavors of default graphs.The code is here (Apache 2.0): https://github.com/Ostrzyciel/jena-default-graphs/blob/main/jena-default-graphs/src/main/java/org/example/Main.java
Output is attached below.
N-Quads, RDF-PROTO, RDF-THRIFT serialize/deserialize the default graph correctly in all three variants. JSON-LD 1.1 fails with a null pointer exception for the null variant (easy fix). TriG fails silently and just outputs nothing for the null variant (also likely to be an easy fix).
All parsers output
Quad.defaultGraphIRI
which I guess makes it the "right" choice when implementing parsers.What I don't know is if this is a bug at all or I'm just being confused. If this is a bug, I can happily fix the null handling in TriG and JSON-LD.
Relevant output and stacktrace
Are you interested in making a pull request?
Yes