SPARQL查询根据语句的顺序返回不同的结果 [英] SPARQL query returns different results depending on the order of statements

查看:258
本文介绍了SPARQL查询根据语句的顺序返回不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SPARQL查询,该查询返回两种资源的最特定的通用类。

I have a SPARQL query which returns the most specific common classes of two resources.

当我尝试在 https://dbpedia.org/sparql ,有时它什么都不返回,而其他时候它返回我想要的类。

When I try to run it on https://dbpedia.org/sparql, sometimes it returns nothing, and other times it returns the classes I want.

我注意到它与查询中语句的顺序有关。

I have noticed it is related to the order of the statements in the query.

这不是理想的行为,因为当我执行查询,无论输入资源URI的顺序如何,我都希望它具有相同的结果。

This is not a desirable behavior because, when I execute the query, I expect it to have the same results regardless of the order in which I input the URIs of the resources.

有人遇到过此问题并找到了解决方案?

Has anyone experienced this problem and found a solution for it?

查询

以下查询正常运行,返回 http://dbpedia.org/ontology/Film http://dbpedia.org/ontology/Wikid ata:Q11424 作为结果:

The following query works properly, returning http://dbpedia.org/ontology/Film and http://dbpedia.org/ontology/Wikidata:Q11424 as results:

SELECT ?lcs
WHERE
{
  <http://dbpedia.org/resource/Ice_Age_(2002_film)> a ?class1 .
  ?class1 rdfs:subClassOf* ?lcs .
  <http://dbpedia.org/resource/Finding_Nemo> a ?class2 .
  ?class2 rdfs:subClassOf* ?lcs .

  FILTER NOT EXISTS {
    <http://dbpedia.org/resource/Finding_Nemo> a ?class3 .
    ?class3 rdfs:subClassOf* ?sublcs .
    <http://dbpedia.org/resource/Ice_Age_(2002_film)> a ?class4 .
    ?class4 rdfs:subClassOf* ?sublcs .
    ?sublcs  rdfs:subClassOf ?lcs
  }

  FILTER strstarts(str(?lcs), "http://dbpedia.org/ontology")
}

但是,以下查询不返回任何内容:

However, the following query returns nothing:

SELECT ?lcs
WHERE
{
  <http://dbpedia.org/resource/Finding_Nemo> a ?class1 .
  ?class1 rdfs:subClassOf* ?lcs .
  <http://dbpedia.org/resource/Ice_Age_(2002_film)> a ?class2 .
  ?class2 rdfs:subClassOf* ?lcs .

  FILTER NOT EXISTS {
    <http://dbpedia.org/resource/Finding_Nemo> a ?class3 .
    ?class3 rdfs:subClassOf* ?sublcs .
    <http://dbpedia.org/resource/Ice_Age_(2002_film)> a ?class4 .
    ?class4 rdfs:subClassOf* ?sublcs .
    ?sublcs  rdfs:subClassOf ?lcs
  }

  FILTER strstarts(str(?lcs), "http://dbpedia.org/ontology")
}


推荐答案


  1. 您在公共终结点上运行查询,该终结点具有各种自我保护设置。这意味着昂贵的查询可能会产生部分结果或没有结果,而廉价的查询可能会产生完整的结果。您可以设置自己的镜像终端节点(在Amazon EC2上快速便捷地使用)在没有这种保护的情况下,您应该会从相同的查询中看到相同的结果。

  1. You're running your queries on a public endpoint, which has a variety of self-protection settings in place. This means that expensive queries may produce partial or no results, while inexpensive queries may produce full results. You can set up your own mirror endpoint (quick-and-easy on Amazon EC2) with no such protections, and you should see equivalent results from equivalent queries.

@AKSW为您的查询提供了一种调整,可以快速产生完整的结果- p>

@AKSW provided a tweak to your query that quickly produces full results --


添加 FILTER strstarts(str(?sublcs), http://dbpedia.org/ontology\")不存在部分

(请参见< a href = http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&qtxt=SELECT%20%3Flcs%0D%0AWHERE%0D%0A%7B%0D% 0A%20%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FFinding_Nemo%3E%20a%20%3Fclass1%20.%0D%0A%20%20%3Fclass1%20rdfs%3AsubClassOf *%20%3Flcs% 20.%0D%0A%20%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FIce_Age_%282002_film%29%3E%20a%20%3Fclass2%20.%0D%0A%20%20%20%3Fclass2% 20rdfs%3AsubClassOf *%20%3Flcs%20.%0D%0A%0D%0A%20%20FILTER%20NOT%20EXI STS%20%7B%0D%0A%20%20%20%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FFinding_Nemo%3E%20a%20%3Fclass3%20.%0D%0A%20%20 %20%20%3Fclass3%20rdfs%3AsubClassOf *%20%3Fsublcs%20.%0D%0A%20%20%20%20%20%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FIce_Age_%282002_film%29%3E %20a%20%3Fclass4%20.%0D%0A%20%20%20%20%3Fclass4%20rdfs%3AsubClassOf *%20%3Fsublcs%20.%0D%0A%20%20%20%20%20%3Fsublcs% 20%20rdfs%3AsubClassOf%20%3Flcs%20%0D%0A%20%20%20%20FILTER%20strstarts%28str%28%3Fsublcs%29%2C%20%22http%3A%2F%2F%2Fdbpedia.org%2Fontology% 22%29%0D%0A%20%20%7D%0D%0A%0D%0A%20%20FILTER%20strstarts%28str%28%3Flcs%29%2C%20%22http%3A%2F%2Fdbpedia.org% 2Fontology%22%29%0D%0A%7D& format = text%2Fhtml& CXML_redir_for_subjs = 121& CXML_redir_for_hrefs =& timeout = 30000& debug = on& run =%20Run%20Query%20 rel = nofollow noreferrer查询表单和实时结果

SELECT ?lcs
WHERE
{
  <http://dbpedia.org/resource/Finding_Nemo>  a  ?class1  .
  ?class1  rdfs:subClassOf*  ?lcs  .
  <http://dbpedia.org/resource/Ice_Age_(2002_film)>  a  ?class2  .
  ?class2  rdfs:subClassOf*  ?lcs  .

  FILTER NOT EXISTS {
    <http://dbpedia.org/resource/Finding_Nemo>  a  ?class3  .
    ?class3  rdfs:subClassOf*  ?sublcs  .
    <http://dbpedia.org/resource/Ice_Age_(2002_film)>  a  ?class4  .
    ?class4  rdfs:subClassOf*  ?sublcs .
    ?sublcs  rdfs:subClassOf  ?lcs 
    FILTER strstarts( str(?sublcs), "http://dbpedia.org/ontology" )
  }

  FILTER strstarts( str(?lcs), "http://dbpedia.org/ontology" )
}


(ObDisclaimer: OpenLink软件产生< a href = https://virtuoso.openlinksw.com/ rel = nofollow noreferrer> Virtuoso ,它为DBpedia端点提供了动力,而上面引用的AMI 。他们也雇用了我。)

(ObDisclaimer: OpenLink Software produces Virtuoso, which powers the DBpedia endpoint, and the AMI referenced above. They also employ me.)

这篇关于SPARQL查询根据语句的顺序返回不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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