Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to create if/then rules using SPARQL and infer new relationships on my data? For example, could I encode rules like the following?

  • if (blood_sugar > 126 and blood_sugar < 500) then blood_sugar_level = High
  • if (blood_sugar_level = High) then (service = adjust_insulin_dose)
See Question&Answers more detail:os

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

1 Answer

The question really doesn't provide enough data to figure out exactly what you're trying to do, but you can certainly bind values based on particular conditions. For instance, the following query includes some inline data (to associate patients with blood sugar levels), and binds the values of the variables ?bloodSugarLevel and ?service accordingly.

prefix : <http://stackoverflow.com/q/20840035/1281433/>

select ?patient ?service where {
  # some sample data of patients and
  # their blood sugar levels
  values (?patient ?bloodSugar) {
    (:alice 120)
    (:bill  150)
  }

  # bind ?bloodSugarLevel to :high or :low as appropriate.
  bind( if( 126 < ?bloodSugar && ?bloodSugar < 500,
            :high,
            :low )
        as ?bloodSugarLevel )

  # bind ?service to :adjust-insulin-dose if the
  # ?bloodSugarLevel is :high, else to :do-nothing.
  bind( if( ?bloodSugarLevel = :high,
            :adjust-insulin-dose,
            :do-nothing )
        as ?service )
}
----------------------------------
| patient | service              |
==================================
| :alice  | :do-nothing          |
| :bill   | :adjust-insulin-dose |
----------------------------------

Alternatively, you might look into 3.1.3 DELETE/INSERT with which you can write an update query like the following to add triples to the graph (where the … is the same as above).

insert { ?patient :hasService ?service }
where { … }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...