进行 SPARQL 查询时出现重复行

Duplicate rows when making SPARQL queries

我想从欧洲议会中提取关于特定议程项目的演讲,可通过此处的 SPARQL 界面访问:http://linkedpolitics.ops.few.vu.nl/user/query

数据库的模式在这里找到:http://linkedpolitics.ops.few.vu.nl/home

通过以下查询

SELECT ?speaker ?given ?surname ?acronym ?text ?partyLabel ?type
WHERE {
   <http://purl.org/linkedpolitics/eu/plenary/2010-12-16_AgendaItem_4> dcterms:hasPart ?speech.
   ?speech lpv:speaker ?speaker.
   ?speaker foaf:givenName ?given.
   ?speaker foaf:familyName ?surname.
   ?speaker lpv:countryOfRepresentation ?country.
   ?country lpv:acronym ?acronym.
   ?speech lpv:translatedText ?text.
   ?speaker lpv:politicalFunction ?func.
   ?func lpv:institution ?institution.
   ?institution rdfs:label ?partyLabel.
   ?institution rdf:type ?type.
   FILTER(langMatches(lang(?text), "en"))
}

我得到了我想要的信息,但是所有的行都重复了好几次。当我试图通过它看起来的政治功能来访问政党标签时,就会发生这种情况。如何仅获取唯一行以及首先出现重复项的原因是什么?

您正在使用大量变量,但您并未select使用所有变量。这意味着您返回的行的差异可能在于您实际上没有 selecting 的变量。例如,如果您有数据:

:a :hasChild :b .
:a :hasChild :c .

你运行查询:

select ?parent where {
  ?parent :hasChild ?child .
}

你会在结果中得到两行:

?parent
-------
:a
:a

因为有两种绑定提供解决方案:一种是 ?child 是 :a,另一种是 ?b。

为避免这种情况,您可以使用 select distinct,它会删除 "duplicate" 结果行。只要做:

SELECT DISTINCT ?speaker ?given ?surname ?acronym ?text ?partyLabel ?type