4

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());
}
crazytomcat
  • 607
  • 1
  • 7
  • 12

4 Answers4

3

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 #

Ignazio
  • 10,504
  • 1
  • 14
  • 25
3

A little update : getFragment() is deprecated now. I use getShortForm() instead.

JC R
  • 314
  • 2
  • 10
0

I have faced the same problem and used OWLEntity.getIRI().getShortForm().

josliber
  • 43,891
  • 12
  • 98
  • 133
Batman22
  • 376
  • 4
  • 25
0

I retrieved class names into a List as follows
get ontology from the disk and assign to variable o Type ; OWLOntology o; And Created list to add 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;
    }