On 28/04/16 16:46, Scoggan, Tom wrote:
Thanks, Andy. Is the answer to this question "no" as well?
Is there an alternative to model.listNameSpaces() that will also return
namespaces used in URI's in the object position of triples?
Tom,
"no" though the question is not well defined.
Namespaces exist if and only if they are declared.
In the real data there are no namespaces, all data is URIs.
Namespaces are held in the separate prefix mapping.
Namespaces are applied when writing out the data.
You can list all the objects and calculate a possible namespace URI
using the code in SplitIRI.
Andy
-----Original Message-----
From: Andy Seaborne [mailto:[email protected]]
Sent: Thursday, April 28, 2016 11:18 AM
To: [email protected]
Subject: Re: Namespace prefixes in Jena Models
Importance: High
On 28/04/16 15:56, Scoggan, Tom wrote:
When writing a Model to an RDF string, I currently do something like this:
1. Use the model.listNameSpaces() method to get the list of namespaces
used --- this doesn't include namespaces used in URI's in the object position
of triples
Model.listNamespaces list the names set on the model. Either in the
data when read in, or set by the application.
2. Manually add the missing namespaces for URI's in the object position of
triples
Namespaces are not necessary - they are a convenience for presentation
(and that works better in Turtle than RDF/XML). Choosing the prefix or
namespace name
[except for properties in RDF/XML which can only be written with qnames]
3. Assign prefixes to each namespace
Something somewhere is going to have to choose nice prefixes.
4. Use the model.setNsPrefixes(prefixToNamespaceMap) method to update the
Model accordingly
5. Write the Model to an RDF string
Is there any way to avoid step 3 by having Jena auto-generate prefixes for
namespaces used within the model (including URI's in the object position)? If
not, is there an alternative to model.listNameSpaces() that will also return
namespaces used in URI's in the object position of triples?
Set them in the input data.
Or keep a Turtle file that is only prefixes and parse it into any model
your create. Parsing a file sets the prefixes so if your data is
N-triples, say, and you want to see it in pretty turtle, just add in
some extra, domain specific, prefixes.
Andy
Thanks!
----------------------------------------------------------------------
This message, and any attachments, is for the intended recipient(s) only, may
contain information that is privileged, confidential and/or proprietary and
subject to important terms and conditions available at
http://www.bankofamerica.com/emaildisclaimer. If you are not the intended
recipient, please delete this message.