进行 SPARQL 查询时重复行 [英] Duplicate rows when making SPARQL queries

查看:41
本文介绍了进行 SPARQL 查询时重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to extract speeches regarding a specific agenda item from the European Parliament, which are accessible through a SPARQL interface here: http://linkedpolitics.ops.few.vu.nl/user/query

数据库的架构可以在这里找到:http://linkedpolitics.ops.few.vu.nl/home

The schema of the database is found here: 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"))
}

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

I get the information that I want, but all the rows are duplicated several times. This happens when I try to access the party label through the political function it seems. How do I get unique rows only and what is the reason for duplicates appearing in the first place?

推荐答案

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

You're using a large number of variables, and you're not selecting all of them. That means that the difference in the rows that you're getting back are probably in the variables that you're not actually selecting. E.g., if you had data:

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

然后你运行了查询:

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

你会在结果中得到两行:

you'd get two rows in the result:

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

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

because there are two bindings that provide solutions: one where ?child is :a, and one where child is ?b.

为避免这种情况,您可以使用 select distinct,这会删除重复"结果行.就这样做:

To avoid this, you can use select distinct, which removes the "duplicate" result rows. Just do:

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

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

这篇关于进行 SPARQL 查询时重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆