2

I have created this ontology which contains two classes: Blood-Sugar and Services. Blood-Sugar has two data properties: hasValu with range xsd:int, and hasStatut with range xsd:string. The object property triggerService has Blood-Sugar as domain and Service as range.

I want to infer a data property assertion with this rule:

Blood_Sugar(?x) ∧ hasValue(?x, ?y) ∧ swrlb:greaterThan(?y, 126) ∧ swrlb:lessThan(?y, 500) → hasStatut(?x, "High")

Then I want to infer a new object property with this rule:

Blood_Sugar(?x) ∧ hasStatut(?x, "High") ∧ Service(?s) → triggerService(?x, ?s)

However, the reasoner does not give me the result that I want when I create individuals to which the rules should apply. Here is an ontology that demonstrates this behavior:

<?xml version="1.0"?>


<!DOCTYPE rdf:RDF [
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY swrl "http://www.w3.org/2003/11/swrl#" >
    <!ENTITY swrlb "http://www.w3.org/2003/11/swrlb#" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY protege "http://protege.stanford.edu/plugins/owl/protege#" >
    <!ENTITY xsp "http://www.owl-ontologies.com/2005/08/07/xsp.owl#" >
    <!ENTITY swrla "http://swrl.stanford.edu/ontologies/3.3/swrla.owl#" >
    <!ENTITY sqwrl "http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl#" >
]>


<rdf:RDF xmlns="http://www.owl-ontologies.com/Ontology1391620136.owl#"
     xml:base="http://www.owl-ontologies.com/Ontology1391620136.owl"
     xmlns:swrla="http://swrl.stanford.edu/ontologies/3.3/swrla.owl#"
     xmlns:sqwrl="http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
     xmlns:swrl="http://www.w3.org/2003/11/swrl#"
     xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
     xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:owl="http://www.w3.org/2002/07/owl#">
    <owl:Ontology rdf:about="">
        <owl:imports rdf:resource="http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl"/>
        <owl:imports rdf:resource="http://swrl.stanford.edu/ontologies/3.3/swrla.owl"/>
    </owl:Ontology>
    <swrl:Variable rdf:ID="s"/>
    <swrl:Variable rdf:ID="x"/>
    <swrl:Variable rdf:ID="y"/>
    <owl:Class rdf:ID="Blood_Sugar"/>
    <swrl:Imp rdf:ID="Rule-2">
        <swrl:body>
            <swrl:AtomList>
                <rdf:first>
                    <rdf:Description>
                        <rdf:type rdf:resource="&swrl;ClassAtom"/>
                        <swrl:argument1>
                            <rdf:Description rdf:about="#x"/>
                        </swrl:argument1>
                        <swrl:classPredicate rdf:resource="#Blood_Sugar"/>
                    </rdf:Description>
                </rdf:first>
                <rdf:rest>
                    <swrl:AtomList>
                        <rdf:first>
                            <rdf:Description>
                                <rdf:type rdf:resource="&swrl;DatavaluedPropertyAtom"/>
                                <swrl:argument2 rdf:datatype="&xsd;string">High</swrl:argument2>
                                <swrl:argument1>
                                    <rdf:Description rdf:about="#x"/>
                                </swrl:argument1>
                                <swrl:propertyPredicate rdf:resource="#hasStatut"/>
                            </rdf:Description>
                        </rdf:first>
                        <rdf:rest>
                            <swrl:AtomList>
                                <rdf:first>
                                    <rdf:Description>
                                        <rdf:type rdf:resource="&swrl;ClassAtom"/>
                                        <swrl:argument1>
                                            <rdf:Description rdf:about="#s"/>
                                        </swrl:argument1>
                                        <swrl:classPredicate rdf:resource="#Service"/>
                                    </rdf:Description>
                                </rdf:first>
                                <rdf:rest rdf:resource="&rdf;nil"/>
                            </swrl:AtomList>
                        </rdf:rest>
                    </swrl:AtomList>
                </rdf:rest>
            </swrl:AtomList>
        </swrl:body>
        <swrl:head>
            <swrl:AtomList>
                <rdf:first>
                    <rdf:Description>
                        <rdf:type rdf:resource="&swrl;IndividualPropertyAtom"/>
                        <swrl:argument2>
                            <rdf:Description rdf:about="#s"/>
                        </swrl:argument2>
                        <swrl:argument1>
                            <rdf:Description rdf:about="#x"/>
                        </swrl:argument1>
                        <swrl:propertyPredicate rdf:resource="#triggerService"/>
                    </rdf:Description>
                </rdf:first>
                <rdf:rest rdf:resource="&rdf;nil"/>
            </swrl:AtomList>
        </swrl:head>
    </swrl:Imp>
    <swrl:Imp rdf:ID="Rule-1">
        <swrl:body>
            <swrl:AtomList>
                <rdf:first>
                    <rdf:Description>
                        <rdf:type rdf:resource="&swrl;ClassAtom"/>
                        <swrl:argument1>
                            <rdf:Description rdf:about="#x"/>
                        </swrl:argument1>
                        <swrl:classPredicate rdf:resource="#Blood_Sugar"/>
                    </rdf:Description>
                </rdf:first>
                <rdf:rest>
                    <swrl:AtomList>
                        <rdf:first>
                            <rdf:Description>
                                <rdf:type rdf:resource="&swrl;DatavaluedPropertyAtom"/>
                                <swrl:argument2>
                                    <rdf:Description rdf:about="#y"/>
                                </swrl:argument2>
                                <swrl:argument1>
                                    <rdf:Description rdf:about="#x"/>
                                </swrl:argument1>
                                <swrl:propertyPredicate rdf:resource="#hasValue"/>
                            </rdf:Description>
                        </rdf:first>
                        <rdf:rest>
                            <swrl:AtomList>
                                <rdf:first>
                                    <rdf:Description>
                                        <rdf:type rdf:resource="&swrl;BuiltinAtom"/>
                                        <swrl:arguments>
                                            <rdf:List>
                                                <rdf:first>
                                                    <rdf:Description rdf:about="#y"/>
                                                </rdf:first>
                                                <rdf:rest>
                                                    <rdf:List>
                                                        <rdf:first rdf:datatype="&xsd;long">126</rdf:first>
                                                        <rdf:rest rdf:resource="&rdf;nil"/>
                                                    </rdf:List>
                                                </rdf:rest>
                                            </rdf:List>
                                        </swrl:arguments>
                                        <swrl:builtin>
                                            <rdf:Description rdf:about="&swrlb;greaterThan"/>
                                        </swrl:builtin>
                                    </rdf:Description>
                                </rdf:first>
                                <rdf:rest>
                                    <swrl:AtomList>
                                        <rdf:first>
                                            <rdf:Description>
                                                <rdf:type rdf:resource="&swrl;BuiltinAtom"/>
                                                <swrl:arguments>
                                                    <rdf:List>
                                                        <rdf:first>
                                                            <rdf:Description rdf:about="#y"/>
                                                        </rdf:first>
                                                        <rdf:rest>
                                                            <rdf:List>
                                                                <rdf:first rdf:datatype="&xsd;long">500</rdf:first>
                                                                <rdf:rest rdf:resource="&rdf;nil"/>
                                                            </rdf:List>
                                                        </rdf:rest>
                                                    </rdf:List>
                                                </swrl:arguments>
                                                <swrl:builtin>
                                                    <rdf:Description rdf:about="&swrlb;lessThan"/>
                                                </swrl:builtin>
                                            </rdf:Description>
                                        </rdf:first>
                                        <rdf:rest rdf:resource="&rdf;nil"/>
                                    </swrl:AtomList>
                                </rdf:rest>
                            </swrl:AtomList>
                        </rdf:rest>
                    </swrl:AtomList>
                </rdf:rest>
            </swrl:AtomList>
        </swrl:body>
        <swrl:head>
            <swrl:AtomList>
                <rdf:first>
                    <rdf:Description>
                        <rdf:type rdf:resource="&swrl;DatavaluedPropertyAtom"/>
                        <swrl:argument2 rdf:datatype="&xsd;string">High</swrl:argument2>
                        <swrl:argument1>
                            <rdf:Description rdf:about="#x"/>
                        </swrl:argument1>
                        <swrl:propertyPredicate rdf:resource="#hasStatut"/>
                    </rdf:Description>
                </rdf:first>
                <rdf:rest rdf:resource="&rdf;nil"/>
            </swrl:AtomList>
        </swrl:head>
    </swrl:Imp>
    <Blood_Sugar rdf:ID="Blood_Sugar_1">
        <hasValue rdf:datatype="&xsd;int">150</hasValue>
    </Blood_Sugar>
    <owl:DatatypeProperty rdf:ID="hasStatut">
        <rdfs:domain rdf:resource="#Blood_Sugar"/>
        <rdfs:range rdf:resource="&xsd;string"/>
    </owl:DatatypeProperty>
    <owl:DatatypeProperty rdf:ID="hasValue">
        <rdfs:domain rdf:resource="#Blood_Sugar"/>
        <rdfs:range rdf:resource="&xsd;int"/>
    </owl:DatatypeProperty>
    <owl:Class rdf:ID="Service"/>
    <Service rdf:ID="Service_1"/>
    <owl:ObjectProperty rdf:ID="triggerService">
        <rdfs:domain rdf:resource="#Blood_Sugar"/>
        <rdfs:range rdf:resource="#Service"/>
    </owl:ObjectProperty>
</rdf:RDF>
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Anima
  • 75
  • 2
  • 7
  • 1
    You haven't shown us any data to which your rules could be applied. If there's no instance data, there's nothing for the rules to run against, and there won't be any instances. Please show a minimal example where this problem arises. That is, please create and post an ontology that has the minimal number of rules and the minimum amount of data needed to reproduce this problem. – Joshua Taylor Feb 04 '14 at 12:36
  • Thank you for showing more of the problem that you're encountering, but you still haven't provided data that we can work with, and the size of your class hierarchy suggests that what you've shown us is _not_ a minimal reproduction of the problem. It will help everyone involved if you start an ontology from scratch, add a class, a property, some instance data, and a rule, and see if you get the expected results. Starting from that minimal point, see where things break, and then show us that. That's usually the best way to diganose these sorts of problems. E.g,. see http://sscce.org/ . – Joshua Taylor Feb 04 '14 at 15:36
  • Thanx, but can you give me un example of inferring new object proprety using SWRL rule? – Anima Feb 04 '14 at 15:48
  • I see that you've updated the question. I've downloaded your ontology and I'm able to get (what I expect) are the desired inferences. To see some of them, you may need to change an option or two in Protégé. See [my new answer](http://stackoverflow.com/a/21592981/1281433). (See how much easier this is when we have working code to test?) – Joshua Taylor Feb 06 '14 at 02:42

2 Answers2

5

But the reasonner does not give me the result that i want when I creat instances !!!

A bit more detail would be helpful here. How do you know that the reasoner (and which reasoner are you using, by the way?) isn't inferring the desired properties? Did you enable the reasoner? Did you run a query to check whether the inferences were present? Did you set the configuration in Protégé to show all the appropriate inferences?

At any rate, thank you for providing an ontology to reproduce your results. I was able to load it into Protégé, run the Pellet reasoner, and I can get the following inferences:

Blood_Sugar_1 triggerService Service_1
Blood_Sugar_1 hasStatut "High"^^string
Blood_Sugar_1 hasStatut "150"^^int

blood sugar results

While Pellet is able to compute all of these inferences, Protégé only shows inferences for object properties by default; you have to go into the Reasoner > Configure… menu and makes sure that under the "Displayed Individual Inferences" section the "Data Property Assertions" option is checked. Turning on the Pellet reasoner and setting this option is described in more detail in my answer to Ontology property definition in Protégé-OWL / SWRL.

reasoner configuration option

Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Thnk you soooooooooo much, It's runing now ^_^ But why it infeer this a gain Blood_Sugar_1 hasStatut "150"^^int ?????????? – Anima Feb 07 '14 at 14:27
  • Wouldn't you be worried if it couldn't infer the things that you specifically gave it? :) I don't know why it appears again in Protégé, but that's really just a UI issue; everything that you've asserted should be inferrable; this is just a matter of Protégé displaying it again. – Joshua Taylor Feb 07 '14 at 15:16
  • @JoshuaTaylor : I have the same problem but I know Pellet returns the correct inferred axioms but not Hermit. I noticed that Hermit is not able to get the results when there is a DataProperty in the rule, Why? I want to use hermit because it is faster! – msc87 Oct 30 '16 at 13:41
0

Based on your comment, perhaps an example of SWRL rules being used to infer a new object property assertion will get you on track. Some OWL 2 reasoners support SWRL rules, so I'm using Protégé 4.x and Pellet. SWRL rules can be used to infer new object property assertions. For instance, in the following ontology, there is a class Person with individuals Alice, Bill, Carl, and Raymond, an object property likes, and a rule:

Person(?x) &rightarrow; likes(?x,Raymond)

After enabling the Pellet reasoner (Reasoner > Pellet, then Reasoner > Start Reasoner), we get the expected results. E.g., Bill likes Raymond:

bill likes raymond

Here's the ontology:

@prefix :      <http://example.org/swrl-example#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix swrl:  <http://www.w3.org/2003/11/swrl#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix swrlb: <http://www.w3.org/2003/11/swrlb#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://example.org/swrl-example>
        a       owl:Ontology .

:Person  a      owl:Class .

:Raymond  a     owl:NamedIndividual , :Person .

:Alice  a       owl:NamedIndividual , :Person .

[ a          swrl:Imp ;
  swrl:body  [ a          swrl:AtomList ;
               rdf:first  [ a                    swrl:ClassAtom ;
                            swrl:argument1       <urn:swrl#x> ;
                            swrl:classPredicate  :Person
                          ] ;
               rdf:rest   ()

             ] ;
  swrl:head  [ a          swrl:AtomList ;
               rdf:first  [ a                       swrl:IndividualPropertyAtom ;
                            swrl:argument1          <urn:swrl#x> ;
                            swrl:argument2          :Raymond ;
                            swrl:propertyPredicate  :likes
                          ] ;
               rdf:rest   ()

             ]
] .

:Bill   a       owl:NamedIndividual , :Person .

:likes  a       owl:ObjectProperty .

:Carl   a       owl:NamedIndividual , :Person .

<urn:swrl#x>  a  swrl:Variable .
Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • did you defined the domain and the range of the proprety "likes"? – Anima Feb 04 '14 at 16:06
  • @Anima I did not, as you can see in the ontology that I provided. (I copied and pasted the _entire_ ontology. You can download it and open it in Protégé.) Declaring domains and ranges on properties is optional, and I am trying to demonstrate a _minimal_ example of using SWRL rules to infer object property assertions. Adding domains and ranges would be an unnecessary complication. – Joshua Taylor Feb 04 '14 at 16:14
  • I think that I hav a broblem on my Protegé, I tried your example but it dose not run again !! – Anima Feb 04 '14 at 16:23
  • @Anima Are you running Protege 3.x or 4.x? Your images are from Protege 3.x, but I used Protege 4.x. I'd suggest that you do, too, unless you have some compelling reason to stay with Protege 3.x. Protege 4.x supports OWL2, but Protege 3.x only supports OWL 1. SWRL rules are a later addition, so you really want the later Protege. "does not run" is not descriptive enough, as it can have lots of causes: not turning on or synchronizing the reasoner, not saving the ontology before starting the reasoner, etc. You're not providing enough information to diagnose the problem. – Joshua Taylor Feb 04 '14 at 16:24
  • I use the 2 version 3.x and 4.x, "does not run" means that it does not give result – Anima Feb 04 '14 at 16:31
  • Well, when you provide an ontology that we can download and load ourselves, we can see whether the problem is reproducible. If it is, then we might be able to diagnose and fix it. Until you provide such an ontology that has these issues, we can't really do anything about it. – Joshua Taylor Feb 04 '14 at 16:34
  • ok thank you very much, I,ll provide you a simple examlpe of ontology, but how can I upload in this page? – Anima Feb 05 '14 at 17:50
  • @Anima Just copy the ontology and add it to you question, formatted as code. – Joshua Taylor Feb 05 '14 at 18:11