gpt4 book ai didi

sparql - 如何使用 Sesame 获得资源的简洁有界描述?

转载 作者:行者123 更新时间:2023-12-02 07:18:26 26 4
gpt4 key购买 nike

我一直在测试 Sesame 2.7.2,当面对 DESCRIBE 查询不包含空白节点闭包这一事实时,我感到非常惊讶[编辑:正确的术语是 CBD for concise bounded description ]

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

所以问题是:如何获得资源的封闭描述 <uri1>不做:

  1. 查询DESCRIBE <uri1>
  2. 迭代结果以确定哪些对象是空白节点
  3. 然后DESCRIBE ?b WHERE { <uri1> pred_relating_to_bnode_ ?b }
  4. 只要找到 bnode,就递归执行并链接

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

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

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

最后,让 DESCRIBE 不是更好更简单吗?返回资源的封闭描述,您仍然可以获得当前返回的结果,如下所示?

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

编辑:这是我想从 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} 相同的结果,所以我只得到这个

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

最佳答案

使用 SPARQL 的部分解决方案

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

@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”的空白节点,这是一个开始。

Sesame 中更大的问题

看起来您将不得不执行如上所述的操作,并且可能需要进行多次搜索,或者您将不得不修改 Sesame。编写一些创造性 SPARQL 的替代方法是更改​​ Sesame 实现描述查询的方式。有些端点使这相对容易,但 Sesame 似乎不是其中之一。有一个 2011 年的邮件列表线程,Custom SPARQL DESCRIBE Implementation ,这似乎解决了同样的问题。

罗伯托·加西亚问道:

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).

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.

吉恩·布鲁克斯特拉回复:

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.

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

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.

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.

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.

关于sparql - 如何使用 Sesame 获得资源的简洁有界描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17363199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com