Rdf 使用OWL推理器推断域/范围
如何使用推理器推断给定数据/对象属性的OWL域/范围 例如,我有两个类Rdf 使用OWL推理器推断域/范围,rdf,drools,semantic-web,owl,owl-api,Rdf,Drools,Semantic Web,Owl,Owl Api,如何使用推理器推断给定数据/对象属性的OWL域/范围 例如,我有两个类Rat,Bird和一个数据属性hasName。我希望这些类是hasName的唯一域: <Declaration><Class IRI="#Rat"/></Declaration> <Declaration><Class IRI="#Bird"/></Declaration> <Declaration><DataProperty IRI="
Rat
,Bird
和一个数据属性hasName
。我希望这些类是hasName
的唯一域:
<Declaration><Class IRI="#Rat"/></Declaration>
<Declaration><Class IRI="#Bird"/></Declaration>
<Declaration><DataProperty IRI="#hasName"/></Declaration>
<DataPropertyDomain>
<DataProperty IRI="#hasName"/>
<ObjectUnionOf>
<Class IRI="#Rat"/>
<Class IRI="#Bird"/>
</ObjectUnionOf>
</DataPropertyDomain>
我可以使用owl api手动提取域,读取hasName
的DataPropertyDomainAxioms
,以获取Rat
,Bird
类。但是我将无法得到其他可推断的类(例如,Rat
有一个等价的类Mouse
)
因此,我想使用推理引擎来推断结果,例如:
- 推理者:隐士,事实++
- SQWRL规则引擎:Drools
有什么方法可以实现这样的结果吗?您定义为域的类是匿名类(两个命名类的联合),因此它不能由
OWLReasoner
的实现返回
要解决此限制,您可以搜索属性的断言域的子类-因此,使用OWLOntology::getDataPropertyDomainAxioms(OWLDataProperty)
您将从根本体检索联合;使用OWLReasoner::getsubclass(OWLClassExpression,false)
您将能够检索包含析取子类的所有节点。每个节点将包含一组等效类;在您的例子中,我希望看到一个包含{Rat,Mouse}
的节点和一个包含{Bird}
的节点
编辑:添加示例以回答评论
OWLOntology o = ... //root ontology for the reasoner
OWLReasoner r = ...
OWLDataProperty p = ...
for (OWLDataPropertyDomainAxiom ax: o.getDataPropertyDomainAxioms(p)) {
OWLClassExpression c = ax.getDomain();
NodeSet<OWLClass> allSubClasses = r.getSubClasses(c, false);
// allSubClasses contains all named subclasses of the domain
}
owlo=//推理机的根本体
OWLR=。。。
OWLDataProperty p=。。。
对于(OWLDataPropertyDomainAxiom ax:o.GetDataPropertyDomainAxiom(p)){
OWLClassExpression c=ax.getDomain();
NodeSet allsubclass=r.getsubclass(c,false);
//AllSubclass包含域的所有命名子类
}
正如@AKSW在评论中所建议的那样,OWLReasoner
在其任何方法中都不返回匿名表达式,这是因为这些方法中的匿名表达式是无限的:例如,给定任何类,该类都有无限的匿名子类。证据太长,无法在这里复制,但在描述逻辑的文章和书籍中很容易找到
因此,当设计
OWLReasoner
时,选择是使推理不完整(通过只返回或多或少任意的匿名表达式集)、不可判定(通过返回无限集)还是将其仅限于命名类。后者被认为是最佳解决方案。您定义为域的类是匿名类(两个命名类的联合),因此它不能由OWLReasoner
的实现返回
要解决此限制,您可以搜索属性的断言域的子类-因此,使用OWLOntology::getDataPropertyDomainAxioms(OWLDataProperty)
您将从根本体检索联合;使用OWLReasoner::getsubclass(OWLClassExpression,false)
您将能够检索包含析取子类的所有节点。每个节点将包含一组等效类;在您的例子中,我希望看到一个包含{Rat,Mouse}
的节点和一个包含{Bird}
的节点
编辑:添加示例以回答评论
OWLOntology o = ... //root ontology for the reasoner
OWLReasoner r = ...
OWLDataProperty p = ...
for (OWLDataPropertyDomainAxiom ax: o.getDataPropertyDomainAxioms(p)) {
OWLClassExpression c = ax.getDomain();
NodeSet<OWLClass> allSubClasses = r.getSubClasses(c, false);
// allSubClasses contains all named subclasses of the domain
}
owlo=//推理机的根本体
OWLR=。。。
OWLDataProperty p=。。。
对于(OWLDataPropertyDomainAxiom ax:o.GetDataPropertyDomainAxiom(p)){
OWLClassExpression c=ax.getDomain();
NodeSet allsubclass=r.getsubclass(c,false);
//AllSubclass包含域的所有命名子类
}
正如@AKSW在评论中所建议的那样,OWLReasoner
在其任何方法中都不返回匿名表达式,这是因为这些方法中的匿名表达式是无限的:例如,给定任何类,该类都有无限的匿名子类。证据太长,无法在这里复制,但在描述逻辑的文章和书籍中很容易找到
因此,当设计
OWLReasoner
时,选择是使推理不完整(通过只返回或多或少任意的匿名表达式集)、不可判定(通过返回无限集)还是将其仅限于命名类。后者被认为是最好的解决方案。你的意思是首先我得到本体中属性的所有属性域公理:OWLOntology::getDataPropertyDomainAxioms
,然后对于每个公理,我得到公理签名中的所有类:OWLDataPropertyDomainAxiom::getClassesInSignature
,然后,对于每个类,我都会得到该类的所有子类:OWLReasoner::getsubclass
?不,只有域类-这是一个匿名类,不会出现在签名中。OWLDataPropertyDomainAxiom有一个专门的方法,我不知道为什么,但是当我使用getClassesInSignature
时,它列出了匿名类的所有子类。你说的是哪种方法?@Ignazio你应该添加这个设计决策的原因,即作为域的推断OWL类表达式的数量将是无限的。你的意思是首先我得到本体中属性的所有属性域公理:OWLOntology::getDataPropertyDomainAxioms
,之后,对于每个axiom,我得到axiom签名中的所有类:OWLDataPropertyDomainAxiom::getClassesInSignature
,然后对于每个类,我得到该类的所有子类:OWLReasoner::GetSubclass
?不,只有域类-这是一个匿名类,不会出现在签名中。OWLDataPropertyDomainAxiom有一个专门的方法,我不知道为什么,但当我使用getClassesInSignature
时,它列出了t的所有子类