【发布时间】:2021-05-30 04:38:03
【问题描述】:
我想使用 SPARQL 查询为一种类型的记录获取分页数据,该记录类型具有一些重复属性,如类型、图像。
以下查询返回重复,因此分页出错。
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX schema:<http://schema.org/>
SELECT distinct ?uri ?label ?r ?type ?image ?ownership ?rating ?comments ?allOwners
FROM <http://sample.net/>
WHERE {
?r rdf:type <http://schema.org/Relation> .
?r schema:property ?uri.
?r schema:owner ?owner .
?r schema:ownership ?ownership .
?uri rdfs:label ?label .
?uri rdf:type ?type .
?uri schema:image ?image .
OPTIONAL {?r schema:comments ?comments .}
OPTIONAL {?r schema:rating ?rating .}
filter (?owner =<http://sample.net/resource/37654824-334f-4e57-a40c-4078cac9c579>)
} limit 20 offset 0
样本数据
subject,predicate,object
Product-uri,type,Vehicle
Product-uri,type,Car
Product-uri,type,Toyota
Product-uri,image,Image-key1.png
Product-uri,image,Image-key2.png
Product-uri,image,Image-key3.png
Product-uri2,type,Vehicle
Product-uri2,type,Car
Product-uri2,type,Toyota
Product-uri2,image,Image-key21.png
Product-uri2,image,Image-key22.png
Product-uri2,image,Image-key23.png
如果我查询此数据以获取唯一产品列表(其中每个产品有多种类型和图像),总计数将是 12 而不是 2。
【问题讨论】:
-
重复是什么意思?在不同的页面上?如果是这样,这是因为您必须对整个结果进行排序,因为除了实现特定的东西之外没有隐式排序,但从来没有保证。长话短说,将
ORDER BY与一个或多个变量一起使用。 -
在您询问或疑惑之前,排序会使整个查询变慢。
标签: sparql rdf virtuoso linked-data