2

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

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

LivingPlace(?lp), hasHospital(?lp, false) → RuralArea(?lp)

然而,我真正想做的是与这个推理相反。

农村地区(?lp) → hasHospital(?lp, false)

每当我创建一个 RuralArea 类型的个体时,我希望 Pellet 推断出一个错误的 hasHospital。我怎样才能做到这一点?

4

1 回答 1

3

这是您所描述的带有类的最小本体,即类 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 中显示有关数据类型属性的推论(如Protégé OWL 邮件列表中的此消息中所述)时,推论

ruralArea1 hasHospital false

显示,如以下屏幕截图所示。

Protege UI 中显示的推理

看到 Pellet 可以得出这种推论的另一种方法是使用 SPARQL 进行询问。例如,使用保存在query.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 值为 false)

并得到相同的结果。在 Protégé 中,这将类似于以下屏幕截图。这样做的好处是,如果您使用不支持 SWRL 的 OWL 推理器,它将为您提供相同的结果。

OWL 限制实现与 SWRL 规则相同的效果

于 2013-08-29T17:11:07.880 回答