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?!!!!!
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:
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 usingxsd: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:
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):
In Protégé that looks a little bit different, but it's pretty close:
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.
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.)
Ontology with Rules