apache / jena

Apache Jena
https://jena.apache.org/
Apache License 2.0
1.1k stars 647 forks source link

Error when printing rdf-star to RDF/XML #2733

Open william-vw opened 6 days ago

william-vw commented 6 days ago

Version

5.1.0

What happened?

Reading rdf-star code into a Model and subsequently writing it to an output stream using the default format (RDF/XML) causes an error. It does not cause an error when writing to TURTLE or N-TRIPLES.

If RDF/XML it is not supported as an output format for rdf-star, then a more suitable exception could be thrown. I imagine some people (even those who know better) will do this by accident now and again as it is the default option.

Relevant output and stacktrace

Code:

Model m = ModelFactory.createDefaultModel();

String rdf = 
    "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n"
    + "@prefix dc: <http://purl.org/dc/terms/> .\n"
    + "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"
    + "@prefix : <http://example.com/> .\n"
    + "\n"
    + "<p1> a :Person ;\n"
    + ":birthDate \"1901\" {| :source <wikidata/p1> |} .";

m.read(new ByteArrayInputStream(rdf.getBytes()), "http://example.com/", "TTL");

// m.write(System.out, "N-TRIPLES");
m.write(System.out);

Stack trace:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "uri" is null
    at org.apache.jena.util.SplitIRI.splitNamespaceXML10(SplitIRI.java:477)
    at org.apache.jena.util.SplitIRI.splitXML10(SplitIRI.java:286)
    at org.apache.jena.rdfxml.xmloutput.impl.SplitRDFXML.splitXML10(SplitRDFXML.java:36)
    at org.apache.jena.rdfxml.xmloutput.impl.Unparser.getXMLNameSpace(Unparser.java:1183)
    at org.apache.jena.rdfxml.xmloutput.impl.Unparser.isLocalReference(Unparser.java:1200)
    at org.apache.jena.rdfxml.xmloutput.impl.Unparser.hasProperties(Unparser.java:1279)
    at org.apache.jena.util.iterator.FilterIterator.hasNext(FilterIterator.java:57)
    at org.apache.jena.rdfxml.xmloutput.impl.Unparser.wObjStar(Unparser.java:354)
    at org.apache.jena.rdfxml.xmloutput.impl.Unparser.wRDF(Unparser.java:340)
    at org.apache.jena.rdfxml.xmloutput.impl.Unparser.write(Unparser.java:244)
    at org.apache.jena.rdfxml.xmloutput.impl.RDFXML_Abbrev.writeBody(RDFXML_Abbrev.java:127)
    at org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter.writeXMLBody(BaseXMLWriter.java:471)
    at org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:447)
    at org.apache.jena.rdfxml.xmloutput.impl.BaseXMLWriter.write(BaseXMLWriter.java:434)
    at org.apache.jena.riot.adapters.AdapterRDFWriter.write(AdapterRDFWriter.java:64)
    at org.apache.jena.riot.RDFWriter.write$(RDFWriter.java:256)
    at org.apache.jena.riot.RDFWriter.output(RDFWriter.java:215)
    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.adapters.RDFWriterRIOT.write(RDFWriterRIOT.java:87)
    at org.apache.jena.rdf.model.impl.ModelCom.write(ModelCom.java:243)
    at Main.main(Main.java:27)

Are you interested in making a pull request?

None

afs commented 6 days ago

Apache Jena as released supports RDF-Star CG, not RDF 1.2. There is no "pretty" output for Turtle-star/CG for annotations.

RDF/XML input or output is not supported (or for that matter defined).

RDF-Star CG is "experimental" and may be withdrawn at any time. It will be withdrawn in favour of RDF 1.2. RDF 1.2 is not compatible with RDF-star CG.

FWIW It also does not work in RDF 1.2 (nor is it defined).

@william-vw - you know the current state but for the audience:

A critical decision that will affect RDF/XML-Star is whether triple terms are allowed in the subject position or not.

If the WG decides that triple terms are only allowed in the object position, then parseType="triple" is a possible design otherwise a significant change in RDF/XML will be needed for compound elements as subjects and hence may not happen.