【问题标题】:Duplicate rows when making SPARQL queries进行 SPARQL 查询时重复行
【发布时间】:2015-11-03 16:04:42
【问题描述】:

我想从欧洲议会中提取有关特定议程项目的演讲,可通过此处的 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"))
}

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

【问题讨论】:

标签: rdf sparql


【解决方案1】:

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

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

然后你运行了查询:

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

你会在结果中得到两行:

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

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

为避免这种情况,您可以使用 select distinct,它会删除“重复”的结果行。做吧:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    相关资源
    最近更新 更多