0

如何在家里没有用户时提取所有关闭的执行器。我试图编写 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]
.
.  
4

1 回答 1

1

规则

[rule1: noValue(:users :hasLocation :home) -> 
        (:actuators :hasLocation :home) 
        (:actuators :state "OFF"^^xsd:boolean)] 

不符合您的预期,而且很可能也有一些错别字。在您的本体中(将来,请提供我们可以实际复制和粘贴的代码,例如 TTL 序列化或 OWL/FSS),您有一个名为user的类,而不是users,但在您的规则中,您谈论的是users . 但即使纠正了这一点,你也不会得到你想要的结果,因为你在需要使用变量的地方使用 IRI。你的规则说

  • 如果三元组:users :hasLocation :home没有出现在图表中,
  • 然后应该将三元组:actuators :hasLocation :home:actuators :state "OFF"^^xsd:boolean添加到图中。

我认为您需要一条规则:

  • 如果?x 是一个执行器并且有一个家的位置,并且没有用户与一个位置有相同的家,
  • 执行器的状态应设置为off

那看起来更像:

[(?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”

于 2015-01-21T15:42:00.930 回答