Using the OWL API, how to get a class or an individual name

I can get OWLClass and access this information. Classes and people along with the prefix.
Is there a way to get rid of the prefix?
For instance:

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>

I want just Mon Dad

UPDATE:
Thanks Ignazio.
I found that the key is a method getIRI().

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());
}
+4
source share
4 answers

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

Please note, however, that not all entities have such a name, since Iri can legitimately end / or #

+3
source

: getFragment() . getShortForm().

+2

OWLEntity.getIRI().getShortForm().

0
source

I extracted the class names into the list as follows,
get the ontology from the disk and assign the type to the variable o; OWLOntology o; And created a list for adding classes as follows List listofclass = new ArrayList (); Then add the following codes

    Collection<OWLClass> classes = o.getClassesInSignature();

//getting class names in the ontology
    for (OWLClass owlClass : classes) {
            System.out.println(owlClass.getIRI().getShortForm());
            listofClass.add(owlClass.getIRI().getShortForm());
      }
        return listofClass;
    }
0
source

All Articles