Search code examples
javaowlontologyowl-api

How to retrieve properties that were instantiated by owl class instance in OWL API?


Using the OWL API, I'm trying to check whether a sub-class has actually instantiated the object properties that set it apart from those it inherits from the parent class.

Is there a way to get the properties an instance has defined? My current approach is attempting to get the instances of an OWLClass as follows:

// OWLClass o_class <---valid OWLClass object (e.g. City, Capital, etc)
Set<OWLNamedIndividual> o_instances = reasoner.getInstances(o_class, true).getFlattened();
for (OWLNamedIndividual> inst : o_instances) {
    //get set of properties defined by each instance
}

I've tried a few different methods, to no avail. inst.getObjectPropertiesInSignature() returns nothing. An sample of one of the OWL files I'm using is shown below:

<owl:Class rdf:ID="City">
    <owl:Restriction>
        <owl:onProperty>
            <owl:ObjectProperty rdf:about="#hasAccommodation"/>
        </owl:onProperty>
        <owl:someValuesFrom rdf:resource="#LuxuryHotel"/>
    </owl:Restriction>
 </owl:Class>

 <owl:Class rdf:ID="Capital">
     <rdfs:subClassOf>
        <owl:Restriction>
          <owl:someValuesFrom rdf:resource="#Museums"/>
          <owl:onProperty>
            <owl:ObjectProperty rdf:about="#hasActivity"/>
          </owl:onProperty>
        </owl:Restriction>
     </rdfs:subClassOf>
     <rdfs:subClassOf rdf:resource="#City"/>
 </owl:Class>

<Capital rdf:ID="Canberra">
    <hasAccommodation rdf:resource="#FourSeasons"/>
</Capital>
<Capital rdf:ID="Sydney">
    <hasAccommodation rdf:resource="#FourSeasons"/>
    <hasActivity rdf:resource="#CoolMuseum"/>
</Capital>

In the example above, I'd like to be able to detect that Canberra doesn't use the property hasActivity, while Sydney does. I'm not sure how to properly obtain those properties and compare them. For brevity, I excluded the lines for the FourSeasons and Museum stuff. I hope I've explained this decently enough.


Solution

  • Use the getObjectPropertyValues(OWLOntology ontology) method which is provided by the OWLIndividual Interface. It will return a Map with ObjectPropertyExpression as key and a Set of OWLIndivdual as value.