如何使用芝麻获得对资源的简明有界说明? [英] How to get a concise bounded description of a resource with Sesame?

查看:92
本文介绍了如何使用芝麻获得对资源的简明有界说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在测试Sesame 2.7.2,当面对DESCRIBE查询不包含空白节点闭包的事实时,我感到非常惊讶[对于简洁的有界描述 ]

I've been testing Sesame 2.7.2 and I got a big surprise when faced to the fact that DESCRIBE queries do not include blank nodes closure [ the right term for this is CBD for concise bounded description]

如果我正确理解的话,SPARQL规范对此相当宽松,并说返回的内容实际上取决于提供者,但是我仍然对该选择感到惊讶,因为bnodes(在describe查询的结果中)不能在后续的SPARQL查询中使用.

If I correctly understand, the SPARQL spec is quite loose on that and says that what is returned is actually up to the provider, but I'm still surprised at the choice, since bnodes (in the results of the describe query) cannot be used in subsequent SPARQL queries.

所以问题是:如何不做以下事情就可以得到资源<uri1>的封闭描述:

So the question is: how can I get a closed description of a resource <uri1> without doing:

  1. 查询DESCRIBE <uri1>
  2. 对结果进行迭代,以确定哪些对象是空白节点
  3. 然后DESCRIBE ?b WHERE { <uri1> pred_relating_to_bnode_ ?b }
  4. 以递归方式进行,只要找到bnode,就可以进行链接
  1. query DESCRIBE <uri1>
  2. iterate over the result to determine which objects are blank nodes
  3. then DESCRIBE ?b WHERE { <uri1> pred_relating_to_bnode_ ?b }
  4. do it recursively and chaining over as long as bnodes are found

如果我没记错的话,深度2节点必须用

If I'm not mistaken, depth-2 bnodes would have to be described with

DESCRIBE ?b2 WHERE {<uri1> <p1&> ?b . ?b <p2> ?b2 }

除非有更简单的方法可以做到这一点?

unless there is a simpler way to do this?

最后,让DESCRIBE返回资源的封闭描述会更好,更简单吗,您仍然可以通过类似以下内容获得当前返回的结果?

Finally, would it not be better and simpler to let DESCRIBE return a closed description of a resource where you can still obtain the currently returned result with something like the following?

CONSTRUCT {<uri1> ?p ?o} WHERE {<uri1> ?p ?o}

编辑:这是我要从芝麻回来的封闭结果的示例

here is an example of a closed result I want to get back from Sesame

<urn:sites#1> a my:WebSite .
<urn:sites#1> my:domainName _:autos1 .
<urn:sites#1> my:online "true"^^xsd:boolean .
_:autos1 a rdf:Alt .
_:autos1 rdf:_1 _:autos2
_:autos2 my:url "192.168.2.111:15001"@fr
_:autos2 my:url "192.168.2.111:15002"@en

当前:DESCRIBE <urn:sites#1>返回的结果与查询CONSTRUCT WHERE {<urn:sites#1> ?p ?o}相同,所以我只能得到

Currently: DESCRIBE <urn:sites#1> returns me the same result as the query CONSTRUCT WHERE {<urn:sites#1> ?p ?o}, so I get only that

<urn:sites#1> a my:WebSite .
<urn:sites#1> my:domainName _:autos1 .
<urn:sites#1> my:online "true"^^xsd:boolean .

推荐答案

使用SPARQL的部分解决方案

根据您的评论,这还不是确切的解决方案,但是请注意,您可以在给定的describe查询中描述多个内容.例如,给定数据:

Partial solutions using SPARQL

Based on your comments, this isn't an exact solution yet, but note that you can describe multiple things in a given describe query. For instance, given the data:

@prefix : <http://example.org/> .

:Alice :named "Alice" ;
       :likes :Bill, [ :named "Carl" ;
                       :likes [ :named "Daphne" ]].
:Bill :likes :Elaine ;
      :named "Bill" .

您可以运行查询:

PREFIX : <http://example.org/>

describe :Alice ?object where {
  :Alice :likes* ?object .
  FILTER( isBlank( ?object ) )
}

并获得结果:

@prefix :        <http://example.org/> .

:Alice
      :likes        :Bill ;
      :likes        [ :likes        [ :named        "Daphne"
                                    ] ;
                      :named        "Carl"
                    ] ;
      :named        "Alice" .

这当然不是一个完整的描述,因为它只是从:Alice中跟随:likes,而不是任意谓词.但这确实得到了名为"Carl""Daphne"的空白节点,这是一个开始.

That's not a complete description of course, because it's only following :likes out from :Alice, not arbitrary predicates. But it does get the blank nodes named "Carl" and "Daphne", which is a start.

看起来您将不得不执行上述操作,并且可能需要多次搜索,或者您必须修改芝麻.编写一些有创意的SPARQL的替代方法是更改​​Sesame实现描述查询的方式.一些端点使此操作相对容易,但Sesame似乎不是其中之一.从2011年开始有一个邮件列表主题,自定义SPARQL DESCRIBE实施,似乎可以解决同样的问题.

It looks like you're going to have to do something like what's described above, and possibly with multiple searches, or you're going to have to modify Sesame. The alternative to writing some creative SPARQL is to change the way that Sesame implements describe queries. Some endpoints make this relatively easy, but Sesame doesn't seem to be one of them. There's a mailing list thread from 2011, Custom SPARQL DESCRIBE Implementation, that seems addressed at this same problem.

RobertoGarcía问:

Roberto García asks:

我正在尝试自定义SPARQL DESCRIBE查询的行为. 我愿意获得类似于CBD的东西(即所有属性和 所描述资源的值以及所有属性和值 与之连接的空白节点).

I'm trying to customise the behaviour of SPARQL DESCRIBE queries. I'm willing to get something similar to CBD (i.e. all properties and values for the described resource plus all properties and values for the blank nodes connected to it).

我尝试使用CONSTRUCT查询重现类似的行为 但是性能不好,如果我查询变得非常复杂 尝试考虑指向空白节点的长属性链 从描述的资源开始.

I have tried to reproduce a similar behaviour using a CONSTRUCT query but the performance is not good and the query gets quite complex if I try to consider long chains of properties pointing to blank nodes starting from the described resource.

Jeen Broekstra答复:

Jeen Broekstra replies:

芝麻中DESCRIBE的实现在查询中进行了硬编码 解析器.只能通过调整解析器本身甚至更改它 这将是棘手的,因为查询模型没有简单的方法来表达它 两者之一:它需要代数的扩展.

The implementation of DESCRIBE in Sesame is hardcoded in the query parser. It can only be changed by adapting the parser itself, and even then it will be tricky, as the query model has no easy way to express it either: it needs an extension of the algebra.

>如果这不可能,那么有关如何使用CONSTRUCT实施的任何建议 查询?

> If this is not possible, any advice about how to implement it using CONSTRUCT queries?

我不确定在单个查询中这样做是否可行. CBD本质上是递归的,尽管SPARQL确实有一些支持 对于递归(属性链),问题在于您必须执行 在属性链的每个步骤中进行中间检查,以查看是否 绑定值是否为空白节点.这不是SPARQL 开箱即用:属性链被定义为仅具有长度 路径的终止条件.

I'm not sure it's technically possible to do this in a single query. CBDs are recursive in nature, and while SPARQL does have some support for recursivity (property chains), the problem is that you have to do an intermediate check in every step of the property chain to see if the bound value is a blank node or not. This is not something that SPARQL supports out of the box: property chains are defined to have only length of the path as the stop condition.

使用 子查询,并集和可选项,但我对此表示怀疑.

Perhaps something is possible using a convoluted combination of subqueries, unions and optionals, but I doubt it.

我认为最好的解决方法是改用标准DESCRIBE 芝麻支持的格式,并为其中的每个空白节点值 结果执行一个单独的连续查询.换句话说:您可以通过以下方式解决它 手.

I think the best workaround is instead to use the standard DESCRIBE format that Sesame supports, and for each blank node value in that result do a separate consecutive query. In other words: you solve it by hand.

唯一的其他选择是在以下位置记录功能请求以支持CBD: 芝麻.我不能保证是否/何时遵循 依旧.

The only other option is to log a feature request for support of CBDs in Sesame. I can't give any guarantees about if/when that will be followed up on though.

这篇关于如何使用芝麻获得对资源的简明有界说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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