本文介绍了来自Dbpedia的Sparql查询和另一个图返回的结果少于预期的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是SPARQL的初学者,我正在此端点上工作。我想加入DBpedia图中的数据。我正在使用属性 owl:sameAs 来引用DBpedia资源。

I'm a beginner in SPARQL and I'm working on this endpoint http://spcdata.digitpa.gov.it:8899/sparql. I'd like to join data from the DBpedia graph. I'm using the property owl:sameAs for referencing to DBpedia resources.

我想获取 pa:Comune 类别中定义了 dbp:populationTotal 值的所有城市的名称和人口值。这是我的查询:

I'd like to fetch the name and population values of all cities falling in the class pa:Comune for which a dbp:populationTotal value is defined. Here is my query:

PREFIX pa:  <http://spcdata.digitpa.gov.it/>
PREFIX rdf: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbp: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?label ?populationTotal WHERE {
  ?s a pa:Comune .
  ?s rdf:label ?label .
  ?s owl:sameAs ?sameAs .
  ?sameAs dbp:populationTotal ?populationTotal .
}
ORDER BY ?label

不幸的是,尽管结果正确,但我只得到其中很小的一部分。我已经检查过,还有更多的市镇在DBpedia上有参考,其属性值为 dbp:populationTotal 。我尝试了所有不同的海绵值,但结果仍然相同。我想问题可能出在我从另一个图表中获取数据,但是我不知道该怎么做。

Unfortunately, though results are correct, I get only a very small subset of them. I've checked and there are many more municipalities that have a reference on DBpedia with a value for property dbp:populationTotal. I've tried with all different sponge values but the results are still the same. I guess the problem might be I'm fetching data from another graph, but I don't know what to do.

编辑:
我在Ian Dickinson的建议下尝试了此查询,并且有效! / p>

i've tried this query after the suggestion of Ian Dickinson, and it works!

PREFIX pa:  <http://spcdata.digitpa.gov.it/>
PREFIX rdf: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbp: <http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT DISTINCT ?label ?sameAs ?populationTotal WHERE {
  ?s a pa:Comune .
  ?s rdf:label ?label .
  ?s owl:sameAs ?sameAs .
FILTER (REGEX(STR(?sameAs), "dbpedia", "i")).
  SERVICE <http://dbpedia.org/sparql>
  {
  ?sameAs dbp:populationTotal ?populationTotal .
   }
} LIMIT 1700

不幸的是,意大利有8000多个市镇,所以我不得不限制结果的上限(因此,LIMIT 1700,这是我可以在没有超时的情况下获得的较高点击数。)。

Unfortunately, there are 8000+ muncipalities in Italy, so I had to cap the results (hence the LIMIT 1700, which is the higher number of hits I can get without having a timeout.).

推荐答案

我不清楚您的Virtuoso端点连接到哪个数据源,但是在您的数据集中总人口不多的地方并不多。以下查询仅返回28个结果:

It's not clear to me what data source your Virtuoso endpoint is connected to, but there are not many places with a population total in your dataset. The following query returns only 28 results:

PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT distinct *  WHERE {
  ?sa dbo:populationTotal ?total
}

如您所见,针对DbPedia SPARQL端点运行的同一查询将返回更多结果。我只能推测您仅将数据的一部分加载到了放在 http://spcdata.digitpa.gov.it:8899/sparql

As you observe, the same query run against the DbPedia SPARQL endpoint returns many more results. I can only surmise that you have loaded only a subset of the data into the Virtuoso graph that you have put up at http://spcdata.digitpa.gov.it:8899/sparql.

这篇关于来自Dbpedia的Sparql查询和另一个图返回的结果少于预期的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 18:34