测试 OWL class 是否是 属性 的 domain/range
Test whether a OWL class is a domain/range of a property
在 the example hasProperty
来自 owl-api 存储库:
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.
所以要检查 class 是否是对象 属性 的域,我可以使用下面的代码片段:
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);
我想知道如何检查 class 是否是对象 属性 的范围,以及它是否是数据 属性 的域。我可以使用以下代码段(基于上面的示例)来检查数据 属性 个域吗?
OWLClassExpression restriction = dataFactory.getOWLDataSomeValuesFrom(dataProperty, dataFactory.getOWLThing());
OWLClassExpression complement = dataFactory.getOWLDataComplementOf(restriction);
OWLClassExpression intersection = dataFactory.getOWLDataIntersectionOf(cls, complement);
boolean hasDataProperty = !reasoner.isSatisfiable(intersection);
该示例不满足您的要求 - 它检查是否 需要 使 class 的实例具有 属性 断言具有特定的 属性。您要验证的条件较弱 - 给定 属性 断言,是否将 class C 推断为主题(或对象,对于范围情况)的类型断言。
这可以通过更简单的方式完成(代码和复杂性),检查 属性 的域是否是您感兴趣的 class 的超级class在 - 或者,如果你想检查 class C 是否 恰好是 域,你可以检查两个 classes 是否等价。
示例:
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);
}
对于数据属性域,您只需在示例中从对象属性切换到数据属性,对于对象属性范围,您将搜索对象 属性 范围公理。
在 the example hasProperty
来自 owl-api 存储库:
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.
所以要检查 class 是否是对象 属性 的域,我可以使用下面的代码片段:
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);
我想知道如何检查 class 是否是对象 属性 的范围,以及它是否是数据 属性 的域。我可以使用以下代码段(基于上面的示例)来检查数据 属性 个域吗?
OWLClassExpression restriction = dataFactory.getOWLDataSomeValuesFrom(dataProperty, dataFactory.getOWLThing());
OWLClassExpression complement = dataFactory.getOWLDataComplementOf(restriction);
OWLClassExpression intersection = dataFactory.getOWLDataIntersectionOf(cls, complement);
boolean hasDataProperty = !reasoner.isSatisfiable(intersection);
该示例不满足您的要求 - 它检查是否 需要 使 class 的实例具有 属性 断言具有特定的 属性。您要验证的条件较弱 - 给定 属性 断言,是否将 class C 推断为主题(或对象,对于范围情况)的类型断言。
这可以通过更简单的方式完成(代码和复杂性),检查 属性 的域是否是您感兴趣的 class 的超级class在 - 或者,如果你想检查 class C 是否 恰好是 域,你可以检查两个 classes 是否等价。
示例:
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);
}
对于数据属性域,您只需在示例中从对象属性切换到数据属性,对于对象属性范围,您将搜索对象 属性 范围公理。