这是一个包含您所描述的类的最小本体,即 LivingPlace 类有两个直接子类,City 和 RuralArea。有一个个体,ruralArea1,类型为RuralArea,本体包含SWRL规则
农村地区(?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
显示,如下图所示。
查看 Pellet 可以得出此推论的另一种方法是使用 SPARQL 进行询问。例如,使用保存在 query.sparql 中的 SPARQL 查询
prefix : <http://example.org/places#>
select ?s ?o where {
?s :hasHospital ?o
}
和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 value false)
并获得相同的结果。在 Protégé 中,这将类似于以下屏幕截图。这样做的好处是,如果您使用的是不支持 SWRL 的 OWL 推理器,它将为您提供相同的结果。