I'm trying to test a simple SWRL rule. There are three Classes in my ontology: LivingPlace which has two sub-classes RuralArea and City. LivingPlace is the domain of the dataProperty hasHospital which has the range boolean.
When I test the following rule with Pellet reasoner, the individual I created as a member of LivingPlace is also inferred as a member of RuralArea.
LivingPlace(?lp), hasHospital(?lp, false) → RuralArea(?lp)
However, what I really want to do is the reverse of this reasoning.
RuralArea(?lp) → hasHospital(?lp, false)
Whenever I create an individual of type RuralArea, I want Pellet to infer a hasHospital of false. How can I do this?
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.
来源:https://stackoverflow.com/questions/15246550/swrl-rules-to-infer-dataproperty-values