【问题标题】:How to write Jena rule to query class and get individuals for a property如何编写耶拿规则来查询类并获取属性的个人
【发布时间】:2015-01-21 15:24:41
【问题描述】:

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

【问题讨论】:

  • 基于 your comment 在您之前的问题中,您说 “哪些个人将 o 作为属性 p 的值?” .. 正是我想要找回的。,你可以打电话给listResourcesWithProperty(property,object)。您不需要为此制定规则。
  • 在你的许多规则中使用类名作为主题对我来说没有意义。例如,您的规则 1 应该类似于 [rule1: (?actuator :hasLocation ?home) noValue(?user :hasLocation ?home) -> (?actuator :state "false"^^xsd:boolean)] 。
  • 规则 1 和规则 2 是相同的,我的意思是解释我的情况,当我将规则 1 用于所需的输出时,我看到的是规则 1 的结果,同样适用于规则 2。我只有一条规则。 rulex 是一个用来解释我的想法的模板。

标签: sparql rdf jena semantic-web jena-rules


【解决方案1】:

规则

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

并没有按照您的预期进行,而且很可能还有一些拼写错误。在您的本体中(以后请提供我们可以实际复制和粘贴的代码,例如 TTL 序列化或 OWL/FSS),您有一个名为 user 的类,而不是 用户,但在您的规则中,您谈论的是用户。但即使纠正了这一点,你也不会得到你想要的结果,因为你在需要使用变量的地方使用 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"。

【讨论】:

  • 不接受有什么特别的原因吗?这个建议有什么问题吗?
  • 我出于其他原因想删除该问题,因此又接受了它。解决方案很完美。
  • @user3747396 虽然该示例并不完全完整或最小化,但它具有代表性,并且有一个合理的答案。我认为这可能对使用耶拿规则的其他人有用。我看不出应该删除它的理由。
猜你喜欢
  • 2014-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-20
  • 2023-03-26
相关资源
最近更新 更多