如何在家中没有用户时提取所有关闭的执行器。我试着写Jena规则,但无法得到正确的输出。我添加了我想要的结果。需要帮助写规则。
[rule1: noValue(:users :hasLocation :home) ->
(:actuators :hasLocation :home)
(:actuators :state "OFF"^^xsd:boolean)]
[rule2: noValue(:users :hasLocation :home) ->
(?x rdf:type :actuators)
(?x :hasLocation :home)
(?x :state "OFF"^^xsd:boolean)]
{ rulex: [noValue(:subject1 :hasPropertyP2 :Object1) ->
(:subject2 :hasProperty1 :Object2)
(:subject2 :hasPropertyP3 Object3)] }
Ontology:
class:user
Individual user_1 -> user
Individual user_2 -> user
.
.
class: actuators
subclass: ac -> actuators
subclass: light -> actuators
subclass: other -> actuators
Individual central_ac -> ac
Individual room_lighting -> light
Individual tv -> other
Individual refridgration -> other
Individual heater -> other
result for rule1 [:actuators :state "OFF"^^xsd:boolean]
result for rule2 [:4e62503a:14b01762f42:-7eea :state "OFF"^^xsd:boolean]
desired result:
[central_ac :state "OFF"^^xsd:boolean]
[room_lighting :state "OFF"^^xsd:boolean]
[tv :state "OFF"^^xsd:boolean]
.
.
答案 0 :(得分:1)
规则
[rule1: noValue(:users :hasLocation :home) ->
(:actuators :hasLocation :home)
(:actuators :state "OFF"^^xsd:boolean)]
没有做到你期望的事情,也可能有一些错别字。在您的本体中(将来,请提供我们可以实际复制和粘贴的代码,例如TTL序列化或OWL / FSS),您有一个名为用户的类,而不是用户,但在您的规则中,您会谈论用户。但即使这已得到纠正,您也无法获得所需的结果,因为您需要在需要使用变量的地方使用IRI。你的规则说明了
我认为您需要一条规则:
这看起来更像是:
[(?actuator rdf:type :actuator)
(?actuator :hasLocation ?home)
noValue(?user,:hasLocation,?home)
->
(?actuator :state "OFF")]
这将开始在您的图表中获得结果,如
[:central_ac :state "OFF"]
[:room_lighting :state "OFF"]
[:tv :state "OFF"]
请注意,我从" OFF" 中删除了 ^^ xsd:boolean 数据类型,因为" OFF" 不是布尔数据类型的有效词法形式。您可以使用" true" 或" false" 。