2013-03-06 153 views
2

我想测试一个简单的SWRL规则。我的本体论中有三个类:LivingPlace,它有两个子类RuralArea和City。 LivingPlace是dataProperty hasHospital的域,它具有范围布尔值。swrl规则推断dataProperty值

当我使用Pellet推理器测试以下规则时,我作为LivingPlace成员创建的个人也被推断为RuralArea的成员。

LivingPlace(?LP),hasHospital(?LP,FALSE)→ RuralArea(?LP)

不过,我真正想要做的就是这个道理相反。

RuralArea(?LP)→ hasHospital(?LP,FALSE)

每当我创造型RuralArea的个体,我想颗粒推断假一hasHospital。我怎样才能做到这一点?

回答

2

这里有一个最小的本体类,就像你所描述的那样,即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 
将显示

,如以下屏幕截图所示。

inference displayed in the Protege UI

另一种方式看佩莱可以得出这样的推论是要求使用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支持,它将会给出相同的结果。

OWL restriction accomplishing the same effect as the SWRL rule

+0

在偏好中启用数据类型断言是我的关键概念。谢谢 – alex 2016-07-28 08:53:02