swrl rules to infer dataProperty values

你。 提交于 2019-12-04 17:24:42

Here's a minimal ontology with classes as you've described, i.e., the class LivingPlace has two direct subclasses, City and RuralArea. There is one individual, ruralArea1, which is of type RuralArea, and the ontology contains the SWRL rule

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>

When I load this ontology in Protégé 4.x and use Pellet as the reasoner, and also ensure that inferences about datatype properties are displyed in the UI (as discussed in this message on the Protégé OWL mailing list), the inference that

ruralArea1 hasHospital false

is displayed, as shown in the following screenshot.

Another way to see that Pellet can draw this inference is to ask using SPARQL. For instance, using the SPARQL query saved in query.sparql

prefix : <http://example.org/places#>

select ?s ?o where { 
  ?s :hasHospital ?o 
}

and the pellet command line tool, we obtain these results:

$ pellet query -q query.sparql ./places.owl 
Query Results (1 answers): 
s          | o                                              
============================================================
ruralArea1 | false^^http://www.w3.org/2001/XMLSchema#boolean

It is worth pointing out that you don't actually need SWRL to do this particular inference. You can simply say that

RuralArea subClassOf (hasHospital value false)

and get the same results. In Protégé, that would look like the following screenshot. This has the advantage that it will give you the same results if you're using an OWL reasoner that doesn't have SWRL support.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!