为什么我的SPARQL查询重复结果? [英] Why does my SPARQL query duplicate results?

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

问题描述

我正在做一些搜索,并学习有关SPARQL的更多信息,但这并不像SQL那样容易.我只想知道为什么我的查询重复结果以及如何解决它.这是我的SPARQL查询:

I am doing some searching, and learning more about SPARQL, but it is not easy like SQL. I just want to know why my query duplicates result and how to fix it. This is my SPARQL Query:

PREFIX OQ:<http://www.owl-ontologies.com/Ontology1364995044.owl#>

SELECT ?x ?ys ?z ?Souhaite
WHERE {
  ?y OQ:hasnameactivite ?x.
  ?y OQ:AttenduActivite ?Souhaite.
  ?y OQ:SavoirDeActivite ?z.
  ?y OQ:hasnamephase ?ys.
  ?y OQ:Activitepour ?v.
  ?ro OQ:hasnamerole ?nr.
  ?y OQ:avoirrole ?ro.
  FILTER regex (?nr ,"Concepteur").
  FILTER regex (?v,"Voiture").
}

这给了我这些结果:

预期结果是:

推荐答案

在第一次阅读您的问题时,我打算回答,您可以将查询中的SELECT更改为SELECT DISTINCT(使用

While first reading your question, I was going to respond that you can change SELECT in your query to SELECT DISTINCT (using the DISTINCT modifier) to remove duplicate results. However, looking at your result set, I don't actually see any duplicated answers. Each row appears to be unique. The values for ?xs and ?ys all happen to be the same, but the combinations of ?z and ?Souhaite make the rows distinct. Your results are essentially the product { xs1 } × { ys1 } × { z1, z2, z3 } × { S1, S2, S3 }, and don't contain any duplicates.

我只是更仔细地查看了查询和显示的结果,并且存在一些差异.例如,您的结果有一个名为?xs的变量,但您的查询未使用该变量.我将假定?x应该是?xs.另外,变量名称?xs?ys?z?Souhaite根本不是很描述.当我们不知道它们在结果中扮演什么角色时,很难谈论这些.

I just looked a bit more closely at the query and the results you are showing, and there are some discrepancies. For instance, your results have a variable named ?xs but your query does not use such a variable. I will assume that ?x is supposed to be ?xs. Also, the variable names ?xs, ?ys, ?z, and ?Souhaite are not very descriptive at all. It's hard to talk about these when we don't know what role they play in the result.

关于期望的结果,?xs?ys实际上应该绑定到每一行.例如,所需结果的第二行包含?z?Souhaite,但没有?xs?ys,但是如果没有相应的?xs?ys,它们可能没有任何意义. , 正确的?因此,我不会尝试解决第二行和第三行中这些列为空白的问题;它们不应为空.

Regarding the results that you are expecting, ?xs and ?ys really should be bound for each row. The second row of your desired results, for instance, have a ?z and a ?Souhaite, but no ?xs and ?ys, but they probably do not make any sense without a corresponding ?xs and ?ys, correct? As such, I will not try to address the issue of those columns being blank in your second and third rows; they should not be blank.

在预期的结果中,您删除了包含许多?z/?Souhaite组合的行,例如"Besoins …" "Schemas …""Volume …" "Fourchette …".这些出现在结果中是因为它们在您的数据中.如果您需要帮助清除数据以使这些数据不存在,我们将需要查看您的数据,并从数据的来源中了解一些信息.

In your expected results, you have removed the rows that included many ?z/?Souhaite combinations, such as "Besoins …" "Schemas …" and "Volume …" "Fourchette …". These appeared in the results because they are in your data. If you want help cleaning your data so that these are not present, we will need to see your data, and know something about from where it came.

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

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