这里有一个最小的本体类,就像你所描述的那样,即LivingPlace类有两个直接的子类City和RuralArea。有一个人,ruralArea1,它的类型是RuralArea,而本体包含SWRL规则
RuralArea(?X)→ hasHospital(?X,FALSE)
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://example.org/places#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:swrl="http://www.w3.org/2003/11/swrl#"
xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://example.org/places"/>
<owl:Class rdf:about="http://example.org/places#LivingPlace"/>
<owl:Class rdf:about="http://example.org/places#City">
<rdfs:subClassOf rdf:resource="http://example.org/places#LivingPlace"/>
</owl:Class>
<owl:Class rdf:about="http://example.org/places#RuralArea">
<rdfs:subClassOf rdf:resource="http://example.org/places#LivingPlace"/>
</owl:Class>
<owl:DatatypeProperty rdf:about="http://example.org/places#hasHospital">
<rdfs:domain rdf:resource="http://example.org/places#LivingPlace"/>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
</owl:DatatypeProperty>
<swrl:Imp>
<swrl:body>
<swrl:AtomList>
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
<rdf:first>
<swrl:ClassAtom>
<swrl:classPredicate rdf:resource="http://example.org/places#RuralArea"/>
<swrl:argument1>
<swrl:Variable rdf:about="urn:swrl#x"/>
</swrl:argument1>
</swrl:ClassAtom>
</rdf:first>
</swrl:AtomList>
</swrl:body>
<swrl:head>
<swrl:AtomList>
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
<rdf:first>
<swrl:DatavaluedPropertyAtom>
<swrl:argument2 rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean"
>false</swrl:argument2>
<swrl:propertyPredicate rdf:resource="http://example.org/places#hasHospital"/>
<swrl:argument1 rdf:resource="urn:swrl#x"/>
</swrl:DatavaluedPropertyAtom>
</rdf:first>
</swrl:AtomList>
</swrl:head>
</swrl:Imp>
<owl:NamedIndividual rdf:about="http://example.org/places#ruralArea1">
<rdf:type rdf:resource="http://example.org/places#RuralArea"/>
</owl:NamedIndividual>
</rdf:RDF>
当我在Protégé4.x中加载此本体并使用Pellet作为推理,并确保推断数据类型属性在UI中显示(如this message on the Protégé OWL mailing list中所述),推断
ruralArea1 hasHospital false
将显示
,如以下屏幕截图所示。
另一种方式看佩莱可以得出这样的推论是要求使用SPARQL。例如,使用保存在query.sparql
prefix : <http://example.org/places#>
select ?s ?o where {
?s :hasHospital ?o
}
SPARQL查询和pellet
命令行工具,我们得到以下结果:
$ pellet query -q query.sparql ./places.owl
Query Results (1 answers):
s | o
============================================================
ruralArea1 | false^^http://www.w3.org/2001/XMLSchema#boolean
这是值得指出的是,你实际上并不需要对SWRL做这个特别的推论。你可以简单地说,
RuralArea subClassOf(hasHospital值false)
,并得到相同的结果。在Protégé中,这看起来像下面的截图。这样做的好处是,如果您使用的OWL推理器没有SWRL支持,它将会给出相同的结果。
在偏好中启用数据类型断言是我的关键概念。谢谢 – alex 2016-07-28 08:53:02