如何使用推理器查询对象属性的反转?
例如,一个人可以拥有枪,反之亦然:
<Declaration>
<ObjectProperty IRI="#hasOwner"/>
</Declaration>
<Declaration>
<ObjectProperty IRI="#hasGun"/>
</Declaration>
<InverseObjectProperties>
<ObjectProperty IRI="#hasOwner"/>
<ObjectProperty IRI="#hasGun"/>
</InverseObjectProperties>
因为有简单的公理,我试图想出一个简单的星函数来处理这个问题:
OWLObjectProperty getOWLInverseRelation(OWLReasoner reasoner, OWLObjectProperty relation) {
Set<OWLObjectPropertyExpression> inverseRelationExprs = reasoner.getInverseObjectProperties(relation).getEntities();
if (inverseRelationExprs.size() != 2) return null;
Iterator<OWLObjectPropertyExpression> inverseRelationExprIter = inverseRelationExprs.iterator();
OWLObjectPropertyExpression inverseRelationExpr = inverseRelationExprIter.next();
if (inverseRelationExpr.getNamedProperty().getIRI().getShortForm().equals(relation.getIRI().getShortForm()))
inverseRelationExpr = inverseRelationExprIter.next();
return inverseRelationExpr.asOWLObjectProperty();
}
这个函数是获得逆对象属性的直接而简单的方法吗?
答案 0 :(得分:1)
OWLObjectPropertyExpression
返回的reasoner.getInverseObjectProperties(relation).getEntities()
个实例已经是relation
的反转。推断它们中的每一个都是您输入的反转 - 它们可以相互等同。