Rod LN
Rod LN

Reputation: 115

How to obtain ALL namespaces used in Jena RDF Model

I'm using com.hp.hpl.jena.rdf.model.Model.listNameSpaces() to obtain the namespaces in a Jena RDF model.

But I've noticed that the model can contain statement objects with namespaces not listed by the listNameSpaces method.

For example, the camera graph (http://www-users.cs.york.ac.uk/~jc/teaching/arin/camera.owl.turtle) contains the following objects, but their namespace does not appear in the namespace list:

http://www.dbpedia.org/resource/ Nikon http://www.w3.org/2001/XMLSchema# decimal

Does anybody know why those two ns would not be listed? Thanks.

//condensed code:

Model model = ModelFactory.createDefaultModel();
RDFReader reader = model.getReader("TURTLE");
InputStream in = FileManager.get().open("http://www-users.cs.york.ac.uk/~jc/teaching/arin/camera.owl.turtle");
reader.read(model, in, null);

NsIterator listNameSpaces = model.listNameSpaces();
while (listNameSpaces.hasNext())
{
  System.out.println("Namespace from iterator: " + listNameSpaces.next());
}

Upvotes: 2

Views: 951

Answers (1)

Ben Companjen
Ben Companjen

Reputation: 1453

The API documentation for that method says:

The namespaces returned are those of (a) every URI used as a property in the model and (b) those of every URI that appears as the object of an rdf:type statement.

Since dbpedia:Nikon and xsd:decimal are used as object and type of a Literal, respectively, the method doesn't return the namespace.

The docs also state:

(You probably don't want this method; more likely you want the PrefixMapping methods that Model supports.)

They are documented here.

Upvotes: 6

Related Questions