You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SPARQL联邦查询去重时SAMPLE函数行为异常导致结果缺失问题

问题背景

  • 正在查询IdRef Sparql端点以获取研究人员的合著者数据,为了得到更完整的结果,对HAL端点执行了联邦查询。
  • 查询整体运行正常,但会生成重复结果,打算使用权威标识符(ORCID、ISNI等)进行去重。
  • 当前编写的查询存在结果缺失问题。

现有查询代码

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

SELECT distinct ?aut ?auturi
WHERE {
  SELECT distinct (SAMPLE(?auturi) AS ?auturi) (SAMPLE(?aut) AS ?aut) ?ids
  WHERE {
    {
      ?uri ?rel <http://www.idref.fr/139753753/id>. #entities our author has a link with
      ?uri ?relcontrib ?auturi. #other with a link to these entities
      ?auturi a foaf:Person. #filter for persons
      ?auturi skos:prefLabel ?aut. #get authors' name
      FILTER (?auturi != <http://www.idref.fr/139753753/id>) #exclude the same author we're querying
      OPTIONAL {
        ?auturi owl:sameAs ?ids. #get authors' identifiers
      }
    } UNION {
      <http://www.idref.fr/139753753/id> owl:sameAs ?id.
      FILTER (CONTAINS(STR(?id), "archives-ouvertes.fr"))
      BIND(URI(REPLACE(STR(?id), "#.*", "")) as ?idHal) #get an ID to query HAL
      SERVICE <http://sparql.archives-ouvertes.fr/sparql> {
        ?idHal foaf:publications ?uri. #same as above
        ?auturi foaf:publications ?uri.
        ?auturi foaf:name ?aut.
        FILTER (?idHal != ?auturi)
        OPTIONAL {
          ?auturi owl:sameAs ?ids.
        }
      }
    }
  }
}

问题描述

使用带SAMPLE的子查询实现去重的运行效果不符合预期:有一条结果被排除了,缺失的结果对应URI为https://data.archives-ouvertes.fr/author/marie-masclet-de-barbarin.rdf。

一开始猜测是该结果没有匹配的owl:sameAs对象,但结果集中另一条同样没有对应owl:sameAs值的结果却正常出现在了最终结果集中。

目前不明确sample的运行逻辑,希望获得更准确的去重实现方法。

补充:包含重复项的原始查询结果

# auturi  aut
1   http://www.idref.fr/057577889/id Lantenois, Annick (1956-....)
2   http://www.idref.fr/033888760/id Cubaud, Pierre
3   http://www.idref.fr/028984838/id Suber, Peter
4   http://www.idref.fr/165836652/id Cramer, Florian (1969-....)
5   http://www.idref.fr/050447823/id Mounier, Pierre (1970-....)
6   http://www.idref.fr/174428006/id Ena, Alexandra (19..-....)
7   http://www.idref.fr/052212807/id Lebert, Marie
8   https://data.archives-ouvertes.fr/author/pierre-mounier Pierre Mounier
9   https://data.archives-ouvertes.fr/author/patrice-bellot Patrice Bellot
10 https://data.archives-ouvertes.fr/author/marlene-delhaye Marlène Delhaye
11 https://data.archives-ouvertes.fr/author/denis-bertin Denis Bertin
12 https://data.archives-ouvertes.fr/author/emma-bester Emma Bester
13 https://data.archives-ouvertes.fr/author/marie-masclet-de-barbarin Marie Masclet de Barbarin

本质上唯一的重复项是第5条和第8条,二者可以通过共享的?ids对象识别。


内容的提问来源于stack exchange,提问作者corbin-c

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 07:24:03