gpt4 book ai didi

sparql - GraphDB - 具有两个连接的非常慢的 sparql 查询

转载 作者:行者123 更新时间:2023-12-05 02:15:56 29 4
gpt4 key购买 nike

我的数据库有关于文档的信息,其中每个文档都有一个类别,例如

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX: <http://example.com>

:doc1 :hasCategory :category1 .
:category1 rdfs:label "Law" .

大约有 10 万条这样的语句。

运行一个简单的查询来获取每个类别的文档数:

SELECT ?category (count(distinct ?doc) as ?count) WHERE {
?doc :hasCategory ?category .
} GROUP BY ?category

运行大约需要 0.1 秒。

但要同时返回类别标签:

SELECT ?category ?label (count(distinct ?doc) as ?count) WHERE {
?doc :hasCategory ?category .
?category rdfs:label ?label .
} GROUP BY ?category ?label

此查询运行时间超过 7 秒。

为什么差异会这么大,是否有更优化的查询可以用来获取标签?

最佳答案

我发现我可以通过以下查询在 0.2 秒内获得所需的结果:

SELECT ?category (sample(?lbl) as ?label) ?count WHERE {
?category rdfs:label ?lbl .
{
SELECT ?category (count(distinct ?doc) as ?count) WHERE {
?doc :hasCategory ?category .
} GROUP BY ?category
}
} GROUP BY ?category ?count

但我真的不明白为什么它更有效率。

关于sparql - GraphDB - 具有两个连接的非常慢的 sparql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50856301/

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