SPARQL和本体规则

时间:2013-12-30 12:56:09

标签: rdf sparql semantic-web owl

是否可以使用SPARQL创建 if / then 规则并推断我的数据上的新关系? 例如,我可以编码如下的规则吗?

  • if (blood_sugar> 126 blood_sugar< 500)然后 blood_sugar_level =高
  • if (blood_sugar_level = High)然后(service = adjust_insulin_dose)

1 个答案:

答案 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 { … }