Search code examples
javaowlowl-api

OWL API: Good substitution for isSubclassOf method


Hello,

I am using the Java OWL API (version 5) and want to check if a class is a subclass of another class. Right now I am doing this by getting all superclasses of the intended subclass and check if this list contains the intended superclass. This approach works, but I need to do this for a lot if classes and if my ontology gets bigger, it's not really efficient.

It seems that there was an isSubclassOf(.., ..) method in OWLClassReasoner in previous releases of the OWL API. But in the current version both aren't present anymore.

Am I overlooking something and if not, is there a more efficient method to accomplish this task?


Solution

  • OWLClassReasoner is an OWLAPI 2 class - last release for OWLAPI 2 was around 2009, I believe, so it's fair to say that code is obsolete.

    With a real reasoner (i.e., one of HermiT or Openllet for OWLAPI 5 - they can be found on Maven Central) you can use the following code:

    OWLReasoner reasoner = ...
    OWLClass a = ...
    OWLClass b = ...
    boolean bIsSuperclass = reasoner.getSuperClasses(a, false).containsEntity(b);