如何编写分页SPARQL查询以获取具有多个相同节点的产品列表

如何编写分页SPARQL查询以获取具有多个相同节点的产品列表,sparql,rdf,virtuoso,linked-data,Sparql,Rdf,Virtuoso,Linked Data,我想使用SPARQL查询获取一种类型的记录的分页数据,该记录具有一些重复的属性,如type、image 下面的查询返回重复项,因此分页错误 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

我想使用SPARQL查询获取一种类型的记录的分页数据,该记录具有一些重复的属性,如type、image

下面的查询返回重复项,因此分页错误

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

如果我查询此数据以获取独特产品列表(每个产品有多种类型和图像),则总计数将是12,而不是2。

如注释中所述,当使用
限制
偏移
逐步通过大型解决方案集时,第一件重要的事情是在查询中包含一个
ORDER BY

ORDER BY
在找到整个解决方案集之前无法应用,因此它可能会减慢查询速度(如注释所示)。实际上,查询以相同的速度运行,但是当没有
ORDER BY
时,可能会在找到解决方案时返回解决方案,因此一些解决方案可能会很快返回,但完整的解决方案集将在有或没有
ORDER BY
的情况下非常接近相同的时间)

DISTINCT
应用于整个解决方案行——因此,如果任何列发生变化,您将得到看起来重复的行


你的问题没有明确说明你所看到的是什么“重复”。也许您可以添加一些示例结果和/或一些示例数据,以便我们更好地了解哪些内容没有达到您希望的效果。

重复是什么意思?在不同的页面上?如果是这样的话,这是因为您必须提供整个结果的排序,因为除了实现特定的内容外,没有隐式排序,但这永远无法保证。长话短说,对一个或多个变量使用
orderby
。在您询问或疑惑之前,排序会使整个查询变慢。
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