简体   繁体   English

ُEXISTS 和 join 两个 SPARQL 查询中的不同值返回不同的结果,而他们应该做同样的事情?

[英]ُEXISTS and join with distinct values in two SPARQL queries return different results while they should do the same thing?

When running the following two queries on DBpedia the result is different.在 DBpedia 上运行以下两个查询时,结果是不同的。 First query gives 68 while the second gives 42. The only difference is the line第一个查询给出 68 而第二个给出 42。唯一的区别是行

filter(exists {[] <http://dbpedia.org/ontology/nationality> ?o.}) 

replaced by join to ensure that the object of dbpo:country is in dbpo:nationality替换为 join 以确保dbpo:country的 object 在dbpo:nationality

{select distinct ?o { [] <http://dbpedia.org/ontology/nationality> ?o.}} 

First Query:第一个查询:

select count(*){
 {select distinct ?s ?o
 { ?o1 <http://dbpedia.org/ontology/successor> ?s . 
 ?o1 <http://dbpedia.org/ontology/governor> ?o2 . 
 ?o2 <http://dbpedia.org/ontology/country> ?o  
filter(exists {[] <http://dbpedia.org/ontology/nationality> ?o.})
filter(exists {?s <http://dbpedia.org/ontology/nationality> []})
}}.
}

Second Query:第二个查询:

select count(*){
 {select distinct ?s ?o
 { ?o1 <http://dbpedia.org/ontology/successor> ?s . 
 ?o1 <http://dbpedia.org/ontology/governor> ?o2 . 
 ?o2 <http://dbpedia.org/ontology/country> ?o  
{select distinct ?o { [] <http://dbpedia.org/ontology/nationality> ?o.}} 
filter(exists {?s <http://dbpedia.org/ontology/nationality> []})
}}.
}

The result of the first query seems to be the correct one.第一个查询的结果似乎是正确的。

You've got a DISTINCT in the subquery within the second full query, which is causing some results not to be carried through to the final result set.您在第二个完整查询中的子查询中有一个DISTINCT ,这导致某些结果无法传递到最终结果集中。

Note the result of this query, which drops that keyword from the subquery, matches your first, ie, 68 --请注意,从子查询中删除该关键字的此查询的结果与您的第一个匹配,即68 --

select count(*)
  { { select distinct ?s ?o
        { ?o1 <http://dbpedia.org/ontology/successor> ?s . 
          ?o1 <http://dbpedia.org/ontology/governor> ?o2 . 
          ?o2 <http://dbpedia.org/ontology/country> ?o  
          { select ?o { [] <http://dbpedia.org/ontology/nationality> ?o. } } 
          filter ( exists { ?s <http://dbpedia.org/ontology/nationality> [] } )
  } } }

I can't spare the time to investigate which result rows from the first and third queries are not found in the second, but I imagine that if you dig further into the descriptions of all these ?s and ?o , you will be able to find the answer.我不能抽出时间来调查第二个查询中没有找到第一个和第三个查询的哪些结果行,但是我想如果您进一步深入研究所有这些?s?o的描述,您将能够找到答案。

A key hint — SPARQL queries are evaluated from inside-out (also described as from bottom-up, but this is confusing because it's not the literal bottom, but the lowest sub-query).一个关键提示 — SPARQL 查询是从内向外评估的(也被描述为自下而上,但这很令人困惑,因为它不是文字底部,而是最低的子查询)。 That means that select?o { [] <http://dbpedia.org/ontology/nationality>?o. }这意味着select?o { [] <http://dbpedia.org/ontology/nationality>?o. } select?o { [] <http://dbpedia.org/ontology/nationality>?o. } (or select distinct?o { [] <http://dbpedia.org/ontology/nationality>?o. } ) is evaluated before the rest of the query -- while the filter clauses are evaluated after the main select . select?o { [] <http://dbpedia.org/ontology/nationality>?o. } (or select distinct?o { [] <http://dbpedia.org/ontology/nationality>?o. } ) is evaluated before the rest of the query -- while the filter clauses are evaluated after the main select .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM