semantic-webontologyprotegeowl-api

OWLAPI access objectProperty value in a superClass axiom


I can get access to sueprClass expression by below command.(running OWLAPI v5) enter image description here

 ont.getSubClassAxiomsForSubClass(cls).forEach(x->x.getSuperClass().getSignature()
    )

each loop returns like:

[<http://www.co-ode.org/ontologies/pizza/pizza.owl#PizzaBase>, <http://www.co-ode.org/ontologies/pizza/pizza.owl#hasBase>]

the result is contained of objectProperty value(s) IRI and objectProperty itself IRI.
now i need to catch objectProperty value that is http://...#PizzaBase.
It means get all value in result Set but not the last one that is objectProperty IRI.

I can transform command to an array (...getSignature().toArray()) and access its values (except last value that is objectproperty IRI).
is there any better way or a method to do this?


Solution

  • Write an OWLObjectVisitor that implements the visit(OWLObjectSomeValuesFrom ce) and call x.getSuperClass().accept(visitor); Then you can access the object property on the ce parameter.

    For this case, you could also just cast the result of x.getSuperClass() to OWLObjectSomeValuesFrom, since you already know where and what type the expression you want to access is. If you needed to do this on a more general way, using visitors is a more flexible approach.