SWRL rules in protege 3.4.8

后端 未结 1 1192
轻奢々
轻奢々 2020-12-03 13:35

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 rul

相关标签:
1条回答
  • 2020-12-03 13:39

    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]) ⊑ 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 .
    
    0 讨论(0)
提交回复
热议问题