Search code examples
semantic-webowlowl-api

Using OWL API, how to get class or individual name


I can get OWLClass and access the information. The classes and individuals are along with prefix.
Is there any method to get rid of prefix?
For example:

OWLClass cls = factory.getOWLClass(":Person", pm);
for (OWLIndividual indiv : cls.getIndividuals(onto)) {
    System.out.println(indiv.toString());
}

print:
<http://www.co-ode.org/ontologies/ont.owl#Mon>
<http://www.co-ode.org/ontologies/ont.owl#Dad>

What I want is just Mon Dad

UPDATE:
Thank you Ignazio.
I found that the key is getIRI() method.

for (OWLIndividual indiv : owlclass.getIndividuals(onto)) {
    System.out.println(indiv.asOWLNamedIndividual().getIRI().getFragment());
}

for (OWLClassExpression expre : owlclass.getSubClasses(onto)) {
    System.out.println(expre.asOWLClass().getIRI().getFragment());
}

Solution

  • For entities, you can do this with OWLEntity.getIRI().getFragment().

    Note however that not all entities have a name of this kind, as an Iri can legitimately end with / or #