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 { … }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…