查找属性路径中的所有步骤 [英] Finding all steps in property path

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

问题描述

我是 SPARQL 的新手,我正在尝试创建一个属性路径查询,它将沿路径吐出每个中间步骤.到目前为止,我有这个:

I'm new to SPARQL and I'm trying to create a property path query that will spit out each intermediate step along the path. So far I have this:

select ?object
where {
  <subjectURI> <isRelatedTo>+ ?object .
}

这给了我一个在整个路径中与我的主题 URI 的所有关系的列表,无论关系有多远(如果我错了,请纠正我).

This gives me a list of all the relations to my subject URI throughout the path, no matter how distantly the relation (correct me if I'm wrong so far).

但是,我想看看这些关系是如何组织的.类似的东西:

But, I'd like to see how the relations are organized. Something like:

<subjectURI> <isRelatedTo> <object1>
<object1> <isRelatedTo> <object2>
<object2> <isRelatedTo> <object3>

等等......这可能吗?

and so on...Is this possible?

推荐答案

不,这是属性路径设计的限制.

No, this is a limitation of the design of property paths.

路径既可用于压缩更复杂的查询模式,也可用于测试任意长度的路径,如您的示例所示.

Paths may either be used to compact more complex query patterns or they may be used to test for arbitrary length paths as in your example.

前者可以转换成一种形式,为您提供中间步骤,例如

The former may be converted into a form that gives you the intermediate steps e.g.

SELECT * WHERE
{
  ?s <http://predicate>/<http://predicate> ?o
}

可以转换成如下:

SELECT * WHERE
{
  ?s <http://predicate> ?intermediate .
  ?intermediate <http://predicate> ?o .
}

不幸的是,对于任意长度的路径不能做同样的事情.但是,如果您知道路径的上限是多少,则可以像这样重写查询:

Unfortunately the same cannot be done for arbitrary length paths. However if you know what the upper bound on paths are you can rewrite your query like so:

SELECT *
WHERE
{
  {
    ?s <http://predicate> ?step1 .
    ?step1 <http://predicate> ?o .
  }
  UNION
  {
    ?s <http://predicate> ?step1 .
    ?step1 <http://predicate> ?step2 .
    ?step2 <http://predicate> ?o .
  }
  # Add additional UNION for each length of path you want up to your upper bound
}

尽管您可以立即看到这会使事情变得非常冗长.

Though as you can immediately see this makes things very verbose.

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

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