Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

owl - SWRL rules in protege 3.4.8

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?!!!!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 .

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...