使用推理器获取 InverseObjectProperty

Get InverseObjectProperty with a reasoner

如何使用推理器查询对象 属性 的逆?

例如,一个人可以拥有一把枪,反之亦然:

<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();
}

这个函数是获取逆向对象的直接简单的方法吗属性?

reasoner.getInverseObjectProperties(relation).getEntities() 返回的 OWLObjectPropertyExpression 个实例已经是 relation 的倒数。它们中的每一个都被推断为您输入的倒数 - 它们可以彼此等效。