Ostrzyciel commented on issue #2578:
URL: https://github.com/apache/jena/issues/2578#issuecomment-2233481730

   @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:
   
   <details>
   
           Empty output for null graph in TriG/pretty
           Failed to write null graph in JSON-LD-11/pretty
           org.apache.jena.shared.JenaException: Exception while writing 
JSON-LD 1.1
                at 
org.apache.jena.riot.writer.JsonLD11Writer.write$(JsonLD11Writer.java:123)
                at 
org.apache.jena.riot.writer.JsonLD11Writer.write(JsonLD11Writer.java:73)
                at org.apache.jena.riot.RDFWriter.write$(RDFWriter.java:261)
                at org.apache.jena.riot.RDFWriter.output(RDFWriter.java:219)
                at org.apache.jena.riot.RDFWriter.output(RDFWriter.java:158)
                at 
org.apache.jena.riot.RDFWriterBuilder.output(RDFWriterBuilder.java:207)
                at org.apache.jena.riot.RDFDataMgr.write$(RDFDataMgr.java:809)
                at org.apache.jena.riot.RDFDataMgr.write(RDFDataMgr.java:754)
                at org.example.Main.main(Main.java:68)
           Caused by: java.lang.NullPointerException: Cannot invoke 
"org.apache.jena.graph.Node.isBlank()" because "node" is null
                at 
org.apache.jena.riot.system.JenaTitanium.resource(JenaTitanium.java:133)
                at 
org.apache.jena.riot.system.JenaTitanium.lambda$convert$0(JenaTitanium.java:60)
                at 
org.apache.jena.atlas.iterator.Iter$IterMap.lambda$forEachRemaining$0(Iter.java:432)
                at 
org.apache.jena.mem2.store.fast.FastArrayBunch$1.forEachRemaining(FastArrayBunch.java:164)
                at 
org.apache.jena.mem2.iterator.IteratorOfJenaSets.forEachRemaining(IteratorOfJenaSets.java:71)
                at 
org.apache.jena.atlas.iterator.Iter$IterMap.forEachRemaining(Iter.java:432)
                at 
org.apache.jena.atlas.iterator.Iter.forEachRemaining(Iter.java:927)
                at 
org.apache.jena.atlas.iterator.IteratorConcat.forEachRemaining(IteratorConcat.java:99)
                at 
org.apache.jena.riot.system.JenaTitanium.convert(JenaTitanium.java:49)
                at 
org.apache.jena.riot.writer.JsonLD11Writer.write$(JsonLD11Writer.java:91)
                ... 8 more
           
           To serialize                       Format                   
Status/deserialized
           null graph                         TriG/pretty              empty 
output   
           null graph                         JSON-LD-11/pretty        
serialization failed
           null graph                         N-Quads/utf-8            
Quad.defaultGraphNodeGenerated
           null graph                         RDF-PROTO                null 
graph     
           null graph                         RDF-THRIFT               triple 
instead of quad
           Quad.defaultGraphNodeGenerated     TriG/pretty              
Quad.defaultGraphNodeGenerated
           Quad.defaultGraphNodeGenerated     JSON-LD-11/pretty        triple 
instead of quad
           Quad.defaultGraphNodeGenerated     N-Quads/utf-8            
Quad.defaultGraphNodeGenerated
           Quad.defaultGraphNodeGenerated     RDF-PROTO                triple 
instead of quad
           Quad.defaultGraphNodeGenerated     RDF-THRIFT               triple 
instead of quad
           Quad.defaultGraphIRI               TriG/pretty              
Quad.defaultGraphNodeGenerated
           Quad.defaultGraphIRI               JSON-LD-11/pretty        triple 
instead of quad
           Quad.defaultGraphIRI               N-Quads/utf-8            
Quad.defaultGraphNodeGenerated
           Quad.defaultGraphIRI               RDF-PROTO                triple 
instead of quad
           Quad.defaultGraphIRI               RDF-THRIFT               triple 
instead of quad
   
   </details>
   
   - TriG and N-Quads parsers output `Quad.defaultGraphNodeGenerated`
   - JSON-LD and Thrift parsers output a triple instead of a quad
   - Protobuf parser behaves like Thrift, except the case where the file was 
serialized from a quad that had null for the graph, then the parser output is 
also null.
   
   So, to summarize (please correct me if I'm wrong here):
   
   - Parsers when handling quads that the source file explicitly specifies as 
being in the default graph, should call `StreamRDF.quad(Quad(_, _, _, 
Quad.defaultGraphNodeGenerated))` – this is something to fix in my parser.
   - Parsers when handling triples that may or may not be in the default graph, 
should call `StreamRDF.triple`.
   - Writers when handling triples should write them as triples.
   - Writers when handling quads:
     - If `quad.isTriple()`, should output a triple (if the format supports 
it), or a quad in the default graph otherwise.
     - If `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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to