如何编写耶拿规则来查询类并获取个人的财产 [英] How to write Jena rule to query class and get individuals for a property

查看:106
本文介绍了如何编写耶拿规则来查询类并获取个人的财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当没有用户在家时,如何提取所有关闭的执行器.我试图编写耶拿规则,但无法获得正确的输出.我已经添加了想要的期望结果.在编写规则方面需要帮助.

How to extract all actuators that are switched off when there are no users at home. I tried to write Jena rule but am unable to get proper output. I have added desired result that I want. Need help with writing rule.

[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]
.
.  

推荐答案

规则

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

没有按照您的预期做,而且很可能还会出现一些错别字.在您的本体中(将来,请提供我们可以实际复制和粘贴的代码,例如TTL序列化或OWL/FSS),您有一个名为 user 而不是的类用户,但在您的规则中,您谈论的是用户.但是,即使已纠正该问题,也不会获得所需的结果,因为在需要使用变量的位置使用了IRI.您的规则说

doesn't do what you expect it to, and there may very well be some typos, too. In your ontology (in the future, please provide code that we can actually copy and paste, e.g.,the TTL serialization, or the OWL/FSS), you have a class called user, not users, but in your rule you talk about users. But even if that were corrected, you're not going to get the results you want, because you're using IRIs where you need to be using variables. Your rule says that

  • 如果三元组:users:hasLocation:home not 是否出现在图形中,
  • 然后将三元组:actuators:hasLocation:home :actuators:state"OFF" ^^ xsd:boolean 添加到该图.
  • if the triple :users :hasLocation :home does not appear in the graph,
  • then the triples :actuators :hasLocation :home and :actuators :state "OFF"^^xsd:boolean should be added to the graph.

我认为您想要一条规则,说:

I think that you want a rule that says:

  • 如果?x是执行器并且具有家的位置,并且没有用户拥有与该位置相同的家,
  • 然后应将执行器的状态设置为关闭.
  • if ?x is an actuator and has a location of home, and there are not users that have the same home as a location,
  • then the state of the actuator should be set to off.

那看起来更像是:

[(?actuator rdf:type :actuator)
 (?actuator :hasLocation ?home)
 noValue(?user,:hasLocation,?home)
 ->
 (?actuator :state "OFF")]

这将开始为您提供图形中的结果

This will start getting you results in your graph like

[:central_ac :state "OFF"]
[:room_lighting :state "OFF"]
[:tv :state "OFF"]

请注意,我从"OFF" 中删除了 ^^ xsd:boolean 数据类型,因为"OFF" 不是有效的词法布尔数据类型的形式.您可以改用"true" "false" .

Note that I removed the ^^xsd:boolean datatype from "OFF", because "OFF" isn't a valid lexical form for the boolean datatype. You could use "true" or "false" instead.

这篇关于如何编写耶拿规则来查询类并获取个人的财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆