How to get the object property values for the specified individual?

∥☆過路亽.° 提交于 2020-01-17 05:38:10

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/32548780/how-to-get-the-object-property-values-for-the-specified-individual

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!