I'm trying to create a individual (instance) using Jena with the method below:
public void createInstance(String name) {
String NS = ontology.getNsPrefixURI("http://james.miranda.br/Onto");
OntClass class = ontology.createClass(NS + "Requisito");
Individual instance = class.createIndividual(NS + name);
System.out.println("Instance created:" + instance.getURI());
}
ontology
is a OntModel instance based on this ontology (some terms are in Portuguese). This method is not working, because the getNsPrefixURI
is returning null.
When I iterate over the classes using the code below:
ExtendedIterator<OntClass> classIterator = ontology.listClasses();
while (classIterator.hasNext()) {
OntClass ontClass = classIterator.next();
System.out.println(ontClass.toString());
}
the (partial) result is:
http://james.miranda.br/Onto#Requisito
http://james.miranda.br/Onto#Micro
http://james.miranda.br/Onto#Certo
Using getNsPrefixURI("")
I have the NS http://www.w3.org/2002/07/owl
and my method does not work too. I was looking for how to define the base uri here in SO, but the solution did not work in my case.
Trying to get the all the namespaces, I used the code:
Map<String,String> list = ontology.getNsPrefixMap();
System.out.println(list.toString());
The result is: {=http://www.w3.org/2002/07/owl#, xsd=http://www.w3.org/2001/XMLSchema#, rdfs=http://www.w3.org/2000/01/rdf-schema#, owl=http://www.w3.org/2002/07/owl#, rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns#}
.
I didn't receive the prefix for "http://james.miranda.br/Onto". Should it be declared anywhere?
Are there anything wrong with my code?