Search code examples
rdfsemantic-webowlowl-apireasoning

How to retrieve all classes connected by an object property given some other class?


Assuming there are several class definitions in an ontology:

<owl:Class rdf:about="&ontX;A">
    <rdfs:label>A</rdfs:label>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="&ontY;hasCapability"/>
            <owl:someValuesFrom rdf:resource="&ontY;CapabilityB"/>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="&ontY;hasCapability"/>
            <owl:someValuesFrom rdf:resource="&ontY;CapabilityC"/>
        </owl:Restriction>
    </rdfs:subClassOf>
</owl:Class>

How to retrieve all capabilities for a given class. In the the above example, for the given class A, CapabilityB and CapabilityC should be returned.

&ontY;CapabilityB and &ontY;CapabilityC are classes in another ontology. The ontologies cannot be changed.

OWL API and a reasoner may be used for the query.


Solution

  • Write an OWLObjectVisitor that collects the fillers for all some values restrictions mentioned in the super classes of the input class, then get all subclasses of each filler, those will be the capability classes compatible with these restrictions.