SPARQL 1.1 中任意属性路径的边界 [英] boundary for arbitrary property path in SPARQL 1.1

查看:38
本文介绍了SPARQL 1.1 中任意属性路径的边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以限制属性路径的长度?例如,获取所有长度在 (m,n) 之间或所有不在此范围内的三元组?例如,如何使用以下查询完成此操作?

Is it possible to bound the length of property path? For example getting all the triples with lengths that are between (m,n) or all that are not between this range? For instance, how could this be done with the following query?

select ?x ?y
where {?x p* ?y}

推荐答案

一些端点直接支持这个

某些 SPARQL 引擎支持直接执行此操作的方法,使用类似于正则表达式的语法.例如,

Some endpoints support this directly

Some SPARQL engines support a method for doing this directly, with a regular-expression-like syntax. E.g.,

?s :p{n,m} ?o

将是长度在 n 和 m 之间的路径.该语法在 SPARQL 1.1 属性路径:W3C 2010 年 1 月 26 日工作草案.还支持精确长度、最小长度和最大长度.不管是好是坏,该语法并未纳入最终的 SPARQL 1.1 标准.不过,一些 SPARQL 端点仍会接受它,因此值得一试.

would be a path with a length between n and m. That syntax is described in SPARQL 1.1 Property Paths: W3C Working Draft 26 January 2010. There is also support for exact lengths, minimum lengths, and maximum lengths. For better of for worse, that syntax didn't make it into the final SPARQL 1.1 standard. Some SPARQL endpoints will still accept it though, so it's worth trying.

但是有一个解决方法.这个想法是将候选路径分成两部分.通过检查可以将其分成两部分的方式有多少,您可以找到路径的长度.也就是说,你做这样的事情,例如,找到 ?s 和 ?p ,它们通过长度为 10 的路径连接:

But there is a workaround. The idea is to split the candidate path into two parts. By checking how many ways it can be split into two parts, you can find the length of the path. That is, you do something like this to, for instance, find ?s and ?p where they are joined by a path of length ten:

select ?s ?o {
  ?s :p* ?mid .
  ?mid :p* ?o .
}
group by ?s ?o
having (count(?mid) = 10)

如果您使用这种方法,请务必检查实际计数.根据您想要如何计算长度,很容易出现一对一(或二)错误.有几个选项(是计算属性还是节点,是否计算端点等),因此值得进行一些实验.

Be sure to check the actual counts if you use this approach. It's easy to get an off-by-one (or -two) error depending on how you want to calculate length. There are a few options (whether to count the properties or the nodes, whether to count the endpoints or not, etc.), so a little bit of experimentation is worth while.

有关如何使用此模式的更多示例,请查看:

For some more examples of how you can use this pattern, have a look at:

这篇关于SPARQL 1.1 中任意属性路径的边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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