Search code examples
javaowlontologyowl-api

Print subclasses of all defined classes without printing the unsatisfied classes


i am new to OWLAPi , i am using Jfact1.2.1 reasoner.

In my ontology there are two unsatisfiable classes . I want to print all the subclasses without these two unsatisfied classes. I've made some codes using array and i was successful however, i didn't like this array thing as i can not use it for other unknown ontologies which might have more than 2 unsatisfiable classes.

So my question is, is there a way to print out all the subclasses of defined classes without having the unsitisfiable classes present in them? i really need someone's help as i've tried everything. If anyone is interested in the array method i've used to the codes are below

OWLClass[] array = new OWLClass[3];
int i=0;

Node<OWLClass> bottomNode = reasoner.getUnsatisfiableClasses();

    Set<OWLClass> unsatisfiable = bottomNode.getEntitiesMinusBottom();


        for (OWLClass cls : unsatisfiable) {


            array[i]= cls;
            i++;
        }
    for (OWLClass c : myOntology.getClassesInSignature()) {
NodeSet<OWLClass> subClasses = reasoner.getSubClasses(c, True);

        for (OWLClass subClass : subClasses.getFlattened()) {
if (subClass.isBottomEntity()|| subClass.equals(array[0])|| 
     subClass.equals(array[1])|| subClass.equals(array[2])){


      continue;

else{
    System.out.println(subClass.getIRI().getFragment() + "\tsubclass of\t" 
   + c.getIRI().getFragment());
 }
}
}

Solution

  • Replace

    if (subClass.isBottomEntity()|| subClass.equals(array[0])|| 
     subClass.equals(array[1])|| subClass.equals(array[2])){
    

    with

    if (subClass.isBottomEntity()|| unsatisfiable.contains(subclass)) {
    

    which has the same effect. There's no need for you to copy the unsatisfiable set out to an array.