On 23/02/2019 23:43, Chris Tomlinson wrote:
Hi Andy,
On Feb 23, 2019, at 3:14 PM, Andy Seaborne <a...@apache.org> wrote:
I thought xml:base has to be enabled in the RDF/XML writer, it's no on by
default.
https://jena.apache.org/documentation/io/rdfxml_howto.html#advanced-rdfxml-output
<https://jena.apache.org/documentation/io/rdfxml_howto.html#advanced-rdfxml-output>
Ah! Thanks very much for pointing to docs on org.apache.jena.rdf.model.RDFWriter .
Indeed setting the “xmlbase” property causes an xml:base to be included in the
<rdf:RDF/> header as desired:
org.apache.jena.rdf.model.RDFWriter rdfw = m.getWriter("RDF/XML");
rdfw.setProperty("xmlbase", "http://purl.bdrc.io/ontology/ext/auth/");
rdfw.write(m, System.out, "http://purl.bdrc.io/ontology/ext/auth/");
Are there any particular issues to be aware of when using
org.apache.jena.rdf.model.RDFWriter vs org.apache.jena.riot.RDFWriter which
underlies {Model, OntModel}.write?
Not really - they use the same code underneath.
The latter doesn’t support a property to include xml:base in the output.
There is an example of how to set properties for RDFWriter -- pass in a
context.
https://github.com/apache/jena/blob/master/jena-arq/src-examples/arq/examples/riot/ExRIOT_RDFXML_WriteProperties.java
which shows "showXmlDeclaration" in use. Add/change to "xmlbase"
Andy
However, we are wanting to ensure that there is an explicit baseURI present in
the resulting serialization.
Out of curiosity, why do you want that?
Using ":" instead of a "base" seems quite common.
There are third party tools, such as TopBraid Composer FE, SE and ME, that require
an explicit xml:base when resolving an owl:imports via the web - i.e., there is no
matching local file - rather than using the URI in the owl:imports as the baseURI
for the document. As I read the RDF/XML syntax spec the client is supposed to use
the document URL for the baseURI when no xml:base is present. The TBC uses an
"Accept: application/rdf+xml, text/turtle” and with such a list RDF/XML is
selected (the service can provide both serializations).
A solution, when serializing as RDF/XML, might be to use Model.write(OutputStream,
“RDF/XML", null) or Model.write(OutputStream, “RDF/XML”), which forces absolute
paths to be used in the output; however, without the (unnecessary) xml:base, TBC
fails silently to load the imports. By comparison, Protégé has no problem correctly
following owl:imports.
We’re just trying to provide proper content negotiation and accommodate the
dictum that the client makes it right.
Based on the javadoc for Model.write parameter, base:
base The base uri to use when writing relative URI's. null means use only
absolute URI's. This is used for relative URIs that would be resolved against
the document retrieval URL. For some values of lang, this value may be included
in the output.
It is unclear of what use a non-null value for XML/RDF is since the resulting
output has no xml:base, the URL of the doc can not be necessarily relied on,
and the output is rendered ambiguous since relative URIs can’t be resolved
unless perhaps the default namespace, denoted by “:”, is used..
The write w/ an explicit baseURI could output an explicit xml:base (as an @base
is written for Turtle) or as also suggested by the javadoc simply use the
supplied baseURI to construct the proper URIs for values of rdf:about etc on
output.
Andy
Thank you,
Chris
On 23/02/2019 00:42, Martynas Jusevičius wrote:
Sorry, can't run the test case right now.
No I'm thinking RDF/XML :) But the prefixes are only used for
properties, not subject (@rdf:about) or object (@rdf:resource) values.
What would you gain by adding an xml:base? You could shorten
prfx:lcl-name to just lcl-name by setting xml:base to prfx: namespace
URI, but that would only work for a single namespace.
And not sure how much sense it makes to compare RDF/XML with Turtle
because the former builds on XML which has its own namespace
mechanism. But maybe I'm completely misunderstanding what you are
trying to do :)
On Sat, Feb 23, 2019 at 12:18 AM Chris Tomlinson
<chris.j.tomlin...@gmail.com> wrote:
No.
If you run the test case you see that RDF/XML writes out xmlns defns of
prefixes and uses the prefixes in the serialization. Perhaps you are thinking
of n-triples.
Thanks,
Chris
On Feb 22, 2019, at 16:52, Martynas Jusevičius <marty...@atomgraph.com> wrote:
Isn't it so that RDF/XML writer always writes absolute URIs, so
xml:base is unnecessary because it would have no effect anyway?
On Fri, Feb 22, 2019 at 11:20 PM Chris Tomlinson
<chris.j.tomlin...@gmail.com> wrote:
Hello,
We are trying to serve various ontology files in a variety of serializations,
principally RDF/XML and Turtle.
The specs indicate that if the baseURI for an ontology is the URL by which the
ontology is retrieved then it is not required that the producer include an
explicit xml:base or @base or similar in the serialization.
However, we are wanting to ensure that there is an explicit baseURI present in
the resulting serialization.
This is because not all tools respect the injunction to use the URL that was
used to retrieve the ontology as the baseURI if there is not an explicit
xml:base or @base and so on in the serialization.
The question is that Model.write(OutputStream, Language, baseURI) includes an
@base when the language is “TURTLE“ in the serialization but when the language
is “RDF/XML” we do not see an xml:base in the result. (same happens when
OntModel is used and when RDFWriter is used.)
The docs indicate that the baseURI param is to be used to specify what URI
should be used to serialize relative URIs and says nothing about including
xml:base or @base; yet, we see the @base for Turtle and no xml:base for RDF/XML.
This is an issue when a tool requests RDF/XML before Turtle in accept headers
and requires that there be an xml:base in the RDF/XML serialization. Noting
that RDF/XML is the only required serialization.
What procedure should be used to “force” an @base or xml:base uniformly?
Here is a small test case that shows the issue:
https://github.com/buda-base/lds-pdi/blob/master/src/test/java/io/bdrc/ldspdi/test/ModelWriteTest.java
<https://github.com/buda-base/lds-pdi/blob/master/src/test/java/io/bdrc/ldspdi/test/ModelWriteTest.java>
Thank you,
Chris