2013-03-06 151 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