简体   繁体   English

测试OWL类是否是属性的域/范围

[英]Test whether a OWL class is a domain/range of a property

In the example hasProperty from owl-api repository: 示例中,来自owl-api存储库的hasProperty

To test whether the instances of a class must have a property we create a some values from restriction and then ask for the satisfiability of the class interesected with the complement of this some values from restriction. 为了测试一个类的实例是否必须具有一个属性,我们从限制条件中创建了一些值,然后要求该类的满足性与限制条件中的一些值的补充相交。 If the intersection is satisfiable then the instances of the class don't have to have the property, otherwise, they do. 如果交集是可满足的,则该类的实例不必具有该属性,否则,它们就可以。

So to check if a class is a domain of an object property, I can use the snippet bellow: 因此,要检查类是否是对象属性的域,可以使用以下代码段:

OWLDataFactory dataFactory = manager.getOWLDataFactory();
OWLClassExpression restriction = dataFactory.getOWLObjectSomeValuesFrom(objectProperty, dataFactory.getOWLThing());
OWLClassExpression complement = dataFactory.getOWLObjectComplementOf(restriction);
OWLClassExpression intersection = dataFactory.getOWLObjectIntersectionOf(cls, complement);
boolean hasObjectProperty = !reasoner.isSatisfiable(intersection);

I want to know how to check if a class is a range of an object property, and if it is a domain of a data property. 我想知道如何检查一个类是否是对象属性的范围,以及它是否是数据属性的域。 Can I use the following snippet (based on the example above) for checking data property domains? 我可以使用以下代码段(基于上面的示例)检查数据属性域吗?

OWLClassExpression restriction = dataFactory.getOWLDataSomeValuesFrom(dataProperty, dataFactory.getOWLThing());
OWLClassExpression complement = dataFactory.getOWLDataComplementOf(restriction);
OWLClassExpression intersection = dataFactory.getOWLDataIntersectionOf(cls, complement);
boolean hasDataProperty = !reasoner.isSatisfiable(intersection);

The example does not do what you are looking for - it checks whether it is necessary for instances of a class to have a property assertion with a specific property. 该示例不执行您想要的操作-它检查类的实例是否必须具有带有特定属性的属性声明。 The condition you are trying to verify is a weaker one - whether, given a property assertion, a class C is inferred to be a type for the subject (or the object, for the range case) of the assertion. 您尝试验证的条件是一个较弱的条件-给定一个属性断言,是否将类C推断为该断言的主题(或对象,对于范围情况)的类型。

This can be done in a simpler way (both code and complexity), checking if the domain of the property is a superclass of the class you're interested in - or, if you want to check whether a class C is exactly the domain, you can check if the two classes are equivalent. 这可以通过更简单的方式(包括代码和复杂性)来完成,检查属性的域是否是您感兴趣的类的超类-或者,如果您要检查C类是否正是该域,您可以检查两个类是否相等。

Example: 例:

OWLOntology o = ... //root ontology for the reasoner
OWLReasoner r = ...
OWLObjectProperty p = ...
for (OWLObjectPropertyDomainAxiom ax: o.getObjectPropertyDomainAxioms(p)) {
    OWLClassExpression c = ax.getDomain();
    NodeSet<OWLClass> allSubClasses = r.getSubClasses(c, false);
    Node<OWLClass> allEquivalentClasses = r.getEquivalentClasses(c);
}

For domain of data properties you just need to switch from object to data properties in the example, for range of object properties, you'll search for object property range axioms. 对于数据属性域,您仅需要在示例中将对象属性切换为数据属性,对于对象属性范围,您将搜索对象属性范围公理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM