owlcs / owlapi

OWL API main repository
821 stars 315 forks source link

Casting Problem #1079

Closed shyamaW closed 1 year ago

shyamaW commented 1 year ago

Hello

I would appreciate it if you could assist me in solving the below mention problem.

In the below code, the line "else if (isSubClassesOfvisisted(visited, (OWLClass) superClass.getSuperClass())) {", shows the exception as output: owl:Thing Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: uk.ac.manchester.cs.owl.owlapi.OWLObjectSomeValuesFromImpl cannot be cast to org.semanticweb.owlapi.model.OWLClass

How to resolve this problem?


for (OWLSubClassOfAxiom superClass : supClassList) { // System.out.println(superClass.getSuperClass()); if (visited.contains(superClass.getSuperClass())) { visited.add(subClass); value = true; } else if (isSubClassesOfvisisted(visited, (OWLClass) superClass.getSuperClass())) { value = true; visited.add(subClass); } else { value = false; } }

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: uk.ac.manchester.cs.owl.owlapi.OWLObjectSomeValuesFromImpl cannot be cast to org.semanticweb.owlapi.model.OWLClass

ignazio1977 commented 1 year ago

Hi, you're trying to cast an OWLClassExpression to OWLClass (in this case it's an existential restriction, i.e., SomeValuesFrom) You should check if the object is anonymous or not before casting it.

shyamaW commented 1 year ago

Thank you very much for your explanation. Got it :)