khiat
khiat

Reputation: 13

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:

Thank you in advance for your help

Upvotes: 1

Views: 1389

Answers (2)

Kunal Khaladkar
Kunal Khaladkar

Reputation: 493

Alternatively you can use an OWLDataFactory as

OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getDataFactory();
 Set<OWLNamedIndividual> inds = localOntology.getIndividualsInSignature();
    for (OWLNamedIndividual ind: inds){
        System.out.println(ind.getObjectPropertyValues(factory.getOWLObjectProperty(IRI.create("Put the iri of the property here")), localOntology));
    }

Although keep in mind System.out.println(ind.getObjectPropertyValues(factory.getOWLObjectProperty(IRI.create("Put the iri of the property here")), localOntology)); returns a Set<OWLIndividual>
This has the benefit of looking for exactly the property you want to use as opposed to all the properties on a particular individual.

Upvotes: 0

Artemis
Artemis

Reputation: 3301

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));
    }

Upvotes: 2

Related Questions