I am having an issue with the OWL API when trying to display the URI + Name between < !-- -- > without it also adding the URI+Name to other sections.
For instance, I am using the pizza ontology as my source and the ontology file shows the below set of code for individuals.
<!-- Individual: http://www.co-ode.org/ontologies/pizza/pizza.owl#America -->
<owl:Thing rdf:about="#America">
<rdf:type rdf:resource="#Country"/>
</owl:Thing>
Using the code below I get pretty much the same thing but the URI is still missing from between the <-- #America-->, I can just add the iri+name to the getOWLClass method but that will end up giving me the URI+Name between the < !-- -- > and also on the namedIndividual i.e. rdf:about = http://www.co-ode.org/ontologies/pizza/pizza.owl#America instead of just #America.
OWLClass tClass = dataFactory.getOWLClass(IRI.create("#Country"));
OWLNamedIndividual tIndividual = dataFactory.getOWLNamedIndividual(IRI.create("#America"));
OWLClassAssertionAxiom classAssertion = dataFactory.getOWLClassAssertionAxiom(tClass, tIndividual);
manager.addAxiom(ontology, classAssertion);
Output:
<!-- #America -->
<owl:NamedIndividual rdf:about="#America">
<rdf:type rdf:resource="#Country"/>
</owl:NamedIndividual>
What it is supposed to be:
<!-- http://www.co-ode.org/ontologies/pizza/pizza.owl#America -->
<owl:NamedIndividual rdf:about="#America">
<rdf:type rdf:resource="#Country"/>
</owl:NamedIndividual>
What am I missing and how do I get it to look like the correct way like in the pizza ontology? I am using OWL API 4.0.
EDIT:
Based on Ignazio's suggestion I made a change with no success, here is the code. Again I am using the OWL API 4, the URI is still not being added to the comment < ! -- #America -- >.
OWLClass tClass = dataFactory.getOWLClass(IRI.create("#Country"));
OWLNamedIndividual tIndividual = dataFactory.getOWLNamedIndividual(IRI.create("#America"));
OWLClassAssertionAxiom classAssertion = dataFactory.getOWLClassAssertionAxiom(tClass, tIndividual);
XMLWriterPreferences.getInstance().setUseNamespaceEntities(true);
OWLDocumentFormat format = m.getOntologyFormat(ontology);
format.asPrefixOWLOntologyFormat()
.setPrefix("ns:",
"http://www.co-ode.org/ontologies/pizza/pizza.owl#");
try
{
m.addAxiom(ontology, classAssertion);
m.saveOntology(ontology, format, new SystemOutDocumentTarget());
} catch (OWLOntologyStorageException e)
{
e.printStackTrace();
System.exit(0);
}
I am still pretty new to this, sorry if I am being redundant.
Output Still Without URI + #America in < ! -- #America -- >:
<!-- #America-->
<owl:NamedIndividual rdf:about="#America">
<rdf:type rdf:resource="#Country"/>
</owl:NamedIndividual>
You're trying to output relative IRIs in the RDF/XML. OWL API does not support that (except by actually creating entities with relative IRIs as you do in your code. However, the resulting ontology violates OWL 2 profiles).
You can get a similar result with entities:
XMLWriterPreferences.getInstance().setUseNamespaceEntities(true);
ontology.getFormat()
.asPrefixOWLOntologyFormat()
.setPrefix("ns:",
"http://www.co-ode.org/ontologies/pizza/pizza.owl#");
And save ontology at that point.