Search code examples
javaowl-api

How to get Individuals set of Object Property with OWLAPI


Please, I want to parse the following ontology with java program using OWLAPI.

   <ObjectPropertyAssertion>
        <ObjectProperty IRI="http://onto1#creator"/>
        <NamedIndividual IRI="Mark1"/>
        <NamedIndividual IRI="Car1"/>
    </ObjectPropertyAssertion>
    <ObjectPropertyAssertion>
        <ObjectProperty IRI="http://onto1#creator"/>
        <NamedIndividual IRI="Mark2"/>
        <NamedIndividual IRI="Car2"/>
    </ObjectPropertyAssertion>

The output:

  • Mark1 --> Car1
  • Mark2 --> Car2

Thank you in advance for your help


Solution

  • You need to first extract the individuals in your ontology, and then ask OWL API to find the values of the object properties assigned to these individuals:

        Set<OWLNamedIndividual> inds=localOntology.getIndividualsInSignature();
        for (OWLNamedIndividual ind: inds){
            System.out.println(ind.getObjectPropertyValues(localOntology));
        }