来自主题的 sparql 完整树 [英] sparql complete tree from subject

查看:42
本文介绍了来自主题的 sparql 完整树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有一个人物图时,例如约翰和约翰有工作地址家庭地址电话号码关系等

When I have for example a person graph e.g. John and john has a work adress home adress phone numbers relations etc.

是否可以在不知道是什么的情况下检索与 john 和 john 的子类相关的所有内容?

Is it possible to retrieve everything that is connected to john and to the subclasses of john without knowing what it is?

这样我就可以检索例如以下内容

So that I can retrieve for example the following

John < address < house_number
     < mobile_number
     < company < address
               < function < office number < etc...

And retrieve this via:
     "John" rdfs:everything ?everything ... as deep as the tree goes.

或者我需要知道图表吗?

Or do I need to know the graph?

推荐答案

你的术语有点不对劲,因为地址、手机号码等不是 John 的子类.RDF 是关于三元组(标记为有向边),而约翰的地址是具有John hasAddress AddressOfJohn 形式的三元组的对象.用基于图的术语来说,听起来您是在问是否可以检索从 John 开始的某个有向路径可到达的所有事物.使用具体数据更容易,所以假设您有这些数据:

Your terminology is a bit off, as things like addresses, mobile numbers, etc., aren't subclasses of John. RDF is about triples (labeled directed edges), and John's address is the object of a triple that has the form John hasAddress AddressOfJohn. Speaking in graph based terms, it sounds like you're asking whether it's possible to retrieve all the things that are reachable by some directed path beginning at John. It's easier to work with concrete data, so let's suppose that you've got this data:

@prefix : <http://stackoverflow.com/q/20878795/1281433/> .

:john :hasAddress :addressOfJohn ;
      :hasMobileNumber :mobileNumber ;
      :hasCompany :company .

:addressOfJohn :hasHouseNumber :houseNumber .

:company :hasAddress :addressOfCompany ;
         :hasFunction :function .

SPARQL 1.1 添加了对 属性路径的支持,有点像一种用于属性序列的正则表达式语言,包括典型的运算符,如 *(任意数量的重复)和 +(一个或多个).不幸的是,你不能在属性路径中使用变量,所以你不能只做

SPARQL 1.1 added support for Property Paths, which a sort of like a regular expression language for sequences of properties, including typical operators like * (any number of repetition) and + (one or more). Unfortunately, you can't use variables in property paths, so you can't just do

:john ?p+ ?object

但是,如 answers.semanticweb.com 上的一个类似问题所述 SPARQL:没有指定谓词的属性路径,您可以构造一个将匹配每个属性的析取.例如,由于 : 是一个定义的前缀,因此是一个 IRI,模式 :|!: 将匹配 any 属性(因为一切都是要么 : 要么不是).这说明 (:|!:)+ 是一个真正的通配符路径.因此,我们可以编写如下查询并得到相应的结果:

However, as noted in a similar question on answers.semanticweb.com SPARQL: property paths without specified predicates, you can construct a disjunction that will match every property. For instance, since : is a defined prefix and is thus an IRI, the pattern :|!: will match any property (since everything is either : or it isn't). That mans that (:|!:)+ is a genuine wildcard path. Thus, we can write a query like the following and get the corresponding results:

prefix : <http://stackoverflow.com/q/20878795/1281433/>

select ?object where { 
  :john (:|!:)+ ?object 
}

---------------------
| object            |
=====================
| :company          |
| :function         |
| :addressOfCompany |
| :mobileNumber     |
| :addressOfJohn    |
| :houseNumber      |
---------------------

这篇关于来自主题的 sparql 完整树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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