Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get subclasses of a class OwlApi

There is a way to find all named subclasses of a class without using a reasoner for (OWLClass child : reasoner.getSubClasses(clazz, true).getFlattened() ) and without doing inference just by using axioms? Thank you

like image 400
Nina Avatar asked Sep 14 '25 10:09

Nina


1 Answers

Using owl-api the ontology can be query to get all subClasses axioms. Then you filter the result to retain only the named classes.

for (final OWLSubClassOfAxiom subClasse : ontology.getAxioms(AxiomType.SUBCLASS_OF))
{
    if (subClasse.getSuperClass() instanceof OWLClass 
         && subClasse.getSubClass() instanceof OWLClass)
    {
        System.out.println(subClasse.getSubClass() 
             + " extends " + subClasse.getSuperClass());
    }
}

Using Jena, you can list statement, add look for the "subClassOf" predicate, then as in owl-api you filter to get only non-annoymous objects.

final StmtIterator it = model.listStatements();
while (it.hasNext())
{
    final Statement s = it.next();
    if (s.getPredicate().equals(RDFS.subClassOf) && !s.getObject().isAnon())
            System.out.println(s.getSubject() + " extends " + s.getObject());
}
like image 168
Galigator Avatar answered Sep 16 '25 00:09

Galigator