I have an ontology, created using Protegé 4.3.0, and I would use the OWL-API in order to get the object property values (ie. a set of OWLNamedIndividual
objects) for the specified individual and object property expression.
Set<OWLNamedIndividual> values = reasoner.getObjectPropertyValues(individual, hasPart).getFlattened();
Unfortunately the above instruction return no items, since in my ontology the association between individuals is via some sub object properties of hasPart
object property.
UPDATE: In the last few hours I had found the following solution in order to get the sub object properties related to a specified OWLNamedIndividual
.
private Set<OWLObjectProperty> getRelatedSubObjectProperties(OWLNamedIndividual individual) {
HashSet<OWLObjectProperty> relatedObjectProperties = new HashSet<>();
HashSet<OWLObjectPropertyExpression> subProperties = new HashSet<>();
subProperties.addAll(hasPart.getSubProperties(ontology));
Set<OWLClass> types = reasoner.getTypes(individual, true).getFlattened();
for (OWLObjectPropertyExpression property : subProperties) {
Set<OWLClassExpression> domains = property.getDomains(ontology);
for (OWLClassExpression domain : domains) {
if (types.contains(domain.asOWLClass())) {
relatedObjectProperties.add(property.asOWLObjectProperty());
}
}
}
return relatedObjectProperties;
}
Then I would get the object property values as follows:
for (OWLObjectProperty property : getRelatedSubObjectProperties(individual)) {
Set<OWLNamedIndividual> values = reasoner.getObjectPropertyValues(individual, property).getFlattened();
if (values != null) {
for (OWLNamedIndividual value : values) {
// a value associated to the individual
}
}
}
How can I solve this problem?
The documentation for
getObjectPropertyValues()
does not explicitly state that subproperties will be taken into account, so the behaviour here might be reasoner dependent. Which reasoner are you using?One workaround is to get all subproperties of the property you're using and loop through all of them, so that you'll obtain all results.