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
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));
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.