Using OWL API, how to get class or individual name
Asked Answered
N

4

5

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());
}
Norward answered 18/7, 2014 at 9:12 Comment(0)
I
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 #

Indebted answered 18/7, 2014 at 12:16 Comment(0)
H
4

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

Hiett answered 26/8, 2015 at 12:1 Comment(0)
I
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 #

Indebted answered 18/7, 2014 at 12:16 Comment(0)
S
0

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

Subtreasury answered 14/9, 2015 at 6:54 Comment(0)
A
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;
    }
Archibaldo answered 19/7, 2019 at 10:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.