是否可以使用SPARQL创建 if / then 规则并推断我的数据上的新关系? 例如,我可以编码如下的规则吗?
答案 0 :(得分:0)
这个问题确实无法提供足够的数据来确切地确定您要做的事情,但您当然可以根据特定条件绑定值。例如,以下查询包括一些内联数据(用于将患者与血糖水平相关联),并相应地绑定变量?bloodSugarLevel
和?service
的值。
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 |
----------------------------------
或者,您可以查看3.1.3 DELETE/INSERT,您可以使用该{{3}}编写更新查询,如下所示,将三元组添加到图表中(其中......与上述相同)。
insert { ?patient :hasService ?service }
where { … }