在SPARQL中计数 [英] Counting in SPARQL

查看:282
本文介绍了在SPARQL中计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我有这个查询

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 

SELECT DISTINCT (COUNT(?instance) AS ?count) WHERE {
?instance a <http://dbpedia.org/ontology/Ambassador> . 
}

,结果是286。很酷。现在,我想获取具有 http://dbpedia.org/property/name 属性的大使的数量。但是

and the result is 286. Cool. Now I want to get the number of ambassadors that have http://dbpedia.org/property/name property. But

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 

SELECT DISTINCT (COUNT(?instance) AS ?count) WHERE {
?instance a <http://dbpedia.org/ontology/Ambassador> . 
?instance <http://dbpedia.org/property/name> ?name
}

结果为533 :(。因此,由于存在拥有此属性一次或多次的人,但是无论拥有多少次,我如何获得拥有此属性的大使的数量。您能否在单个查询中做到这一点?

results in 533 :(. So it is counting more because there are people which have this property one or more times. But how do I get the number of ambassadors that have this property regardless of how many times they have it. Can you do this in a single query?

谢谢。

推荐答案

您可能想尝试一下:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 

SELECT (COUNT(DISTINCT ?instance) AS ?count) WHERE {
?instance a <http://dbpedia.org/ontology/Ambassador>; 
          <http://dbpedia.org/property/name> ?name
}

它给我的结果是283,可能会或可能不会是正确的:)。

It's giving me a result of 283, which might or might not be right :).

这篇关于在SPARQL中计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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