3

I created an ontology that contains the class Blood_Sugar this class contains 4 subclasses: Normal_BS, High_BS, Low_BS and Dangerous_BS. I would like to execute a SWRL rule on Protege 3.4.8 which permit to classify individuals of the supere class Blood_Sugar in subclasses according to their values. Blood_Pressure(?x) ∧ hasLevelvalue(?x, ?y) ∧ swrlb:greaterThan(?y, 126) ∧ swrlb:lessThan(?y, 500) → High_BS(?x) knowing that hasLevelValue is a DataType proprety, its domain is Blood_Sugar class and its range is INT On the Blood_Sugar class and thier subclasses class, I created the restriction (hasLevelvalue only int)

I created som individuals that have diffrent values but they are not classified in the sub classes (High_BS, Low_BS...) the swrl rule does not give an erreur but it does not give a result :( I dont know what end wher is the problem?!!!!!

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Anima
  • 75
  • 2
  • 7
  • What reasoner are you using to evaluate the SWRL rules? – Joshua Taylor Jan 20 '14 at 21:43
  • Also, Protégé 3.4.8 is rather old; is there a reason not to use a later version? – Joshua Taylor Jan 20 '14 at 21:47
  • I use protege 3.4.8 in order to use SWRL Tab and Jess, but I tried the same rule on Protegé 4 and the reasoner is Pellet but no result :( – Anima Jan 20 '14 at 21:57
  • OK, I've added an answer. You actually don't need SWRL rules for this case; you can do it using just OWL class subclass or equivalent class axioms. There are some hard to read parts of your answer, but I've reproduced enough of it, and included examples of the SWRL way of doing it, and the two OWL axiom ways of doing it. – Joshua Taylor Jan 20 '14 at 22:40

1 Answers1

8

Possible problems

Your question is a bit unclear, and I'm not sure whether there are just typographical errors, or if there are genuine modeling errors. You said that you were looking at the class Blood_Sugar, and four subclasses, but then the rule that you showed starts with a Blood_Pressure atom (pressure, not sugar), and that could be the problem right there:

Blood_Pressure(?x) ∧ hasLevelvalue(?x, ?y) ∧ swrlb:greaterThan(?y, 126) ∧ swrlb:lessThan(?y, 500) → High_BS(?x)

If that's just a typo in the question, though, you could be having problems with the datatypes. Rather than using xsd:int, you should probably be using xsd:integer (so that you don't have to worry about issues with overflow, etc.) Not to mention, if you use one in your data, but declare the range differently, you could run into inconsistencies there.

Using Rules

To get you going, I've reconstructed a very minimal part of your ontology in Protégé 4.x, and using the Pellet reasoner, I've demonstrated the results that you're looking for:

enter image description here enter image description here enter image description here

I've included the ontology in N3 format toward the end of this answer.

Using Restrictions

Now, even though you can do this using SWRL rules, you can also do this using simple OWL restriction classes, and that might be a better option, because it might work with more reasoners. If nothing else, it's one less dependency, so it might be a more attractive solution. The trick is to either define Blood_HS as equivalent to the intersection of Blood_Sugar and things with a level in the desired range, or you could use an general class axiom. In both of these cases, you can get the desired result using the Pellet reasoner, and you don't need any SWRL rule.

Using an Equivalent Class Axiom

You can simply say that (using the class names that I've been using in mine ontology):

HighBloodSugar ≡ BloodSugar and (hasLevelValue some integer[>120,<600])

In Protégé that looks a little bit different, but it's pretty close:

enter image description here

Using a Subclass Axiom

Now, if you you don't want to make that an equivalent class axiom, you can use a general axiom like the following.

BloodSugar and (hasLevelValue some integer[>120,<600]) &sqsubseteq; HighBloodSugar

This only looks a little bit different in Protégé. This is the closest to the SWRL version, since anything that is a blood sugar and has a level in the specified range will be classified as a high blood sugar, but it's still possible that there are other high blood sugars, too. (You don't get this with the equivalent class axiom.)

enter image description here

Ontology with Rules

@prefix :      <http://stackoverflow.com/q/21243879/1281433/blood-pressure.owl#> .
@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#> .
@prefix blood-pressure: <http://stackoverflow.com/q/21243879/1281433/blood-pressure.owl#> .

<http://stackoverflow.com/q/21243879/1281433/blood-pressure.owl>
        a       owl:Ontology .

blood-pressure:HighBloodSugar
        a       owl:Class .

blood-pressure:bs1  a                 owl:NamedIndividual , blood-pressure:BloodSugar ;
        blood-pressure:hasLevelValue  200 .

<urn:swrl#bp>  a  swrl:Variable .

<urn:swrl#bs>  a  swrl:Variable .

blood-pressure:BloodSugar
        a       owl:Class .

blood-pressure:hasLevelValue
        a            owl:DatatypeProperty ;
        rdfs:domain  blood-pressure:BloodSugar ;
        rdfs:range   xsd:integer .

[ a          swrl:Imp ;
  swrl:body  [ a          swrl:AtomList ;
               rdf:first  [ a                    swrl:ClassAtom ;
                            swrl:argument1       <urn:swrl#bs> ;
                            swrl:classPredicate  blood-pressure:BloodSugar
                          ] ;
               rdf:rest   [ a          swrl:AtomList ;
                            rdf:first  [ a                       swrl:DatavaluedPropertyAtom ;
                                         swrl:argument1          <urn:swrl#bp> ;
                                         swrl:argument2          <urn:swrl#level> ;
                                         swrl:propertyPredicate  blood-pressure:hasLevelValue
                                       ] ;
                            rdf:rest   [ a          swrl:AtomList ;
                                         rdf:first  [ a               swrl:BuiltinAtom ;
                                                      swrl:arguments  [ a          rdf:List ;
                                                                        rdf:first  <urn:swrl#level> ;
                                                                        rdf:rest   [ a          rdf:List ;
                                                                                     rdf:first  126 ;
                                                                                     rdf:rest   ()

                                                                                   ]
                                                                      ] ;
                                                      swrl:builtin    swrlb:greaterThan
                                                    ] ;
                                         rdf:rest   [ a          swrl:AtomList ;
                                                      rdf:first  [ a               swrl:BuiltinAtom ;
                                                                   swrl:arguments  [ a          rdf:List ;
                                                                                     rdf:first  <urn:swrl#level> ;
                                                                                     rdf:rest   [ a          rdf:List ;
                                                                                                  rdf:first  500 ;
                                                                                                  rdf:rest   ()

                                                                                                ]
                                                                                   ] ;
                                                                   swrl:builtin    swrlb:lessThan
                                                                 ] ;
                                                      rdf:rest   ()

                                                    ]
                                       ]
                          ]
             ] ;
  swrl:head  [ a          swrl:AtomList ;
               rdf:first  [ a                    swrl:ClassAtom ;
                            swrl:argument1       <urn:swrl#bs> ;
                            swrl:classPredicate  blood-pressure:HighBloodSugar
                          ] ;
               rdf:rest   ()

             ]
] .

<urn:swrl#level>  a  swrl:Variable .
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • 1
    Thank you soooooooooooooooooooooooooo much, I would like to learn SWRL so it's my first example, I corrected the mistakes so my rule is runing now :) Whith restriction, I know do it, but I want to apply SWRL. Thnx once again. – Anima Jan 21 '14 at 13:32
  • @Anima Glad to hear it! Yes, SWRL can be very useful, and there _are_ things that you can do with SWRL rules that you can't do with class restrictions. Some things you can even do in a hybrid way: for instance, XSD datatypes with facets are legal SWRL predicates, so instead of `greaterThan(?level,120), lessThan(?level,600)`, you should even be able to do `xsd:integer[>120,<600](?level)` (not sure about the syntax, and some editors will make it hard to enter anyhow). There are lots of options. – Joshua Taylor Jan 21 '14 at 13:42