SPARQL查询和不同计数 [英] SPARQL query and distinct count
本文介绍了SPARQL查询和不同计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下查询:
SELECT ?tag WHERE {
?r ns9:taggedWithTag ?tagresource.
?tagresource ns9:name ?tag
}
LIMIT 5000
,结果是:
abc
abc
abc
abc
abc
abc
abc
abd
ads
anb
我想要的东西是:
tag | count
-----------------
abc 7
abd 1
ads 1
anb 1
我尝试过 count(*)
c $ c> count(?tag),但我得到的错误信息变量或*预期。
,如何使它正确?
I have tried it with count(*)
and count(?tag)
, but than I get the error message "Variable or "*" expected."
Can someone tell me, how to make it right?
推荐答案
如果你使用Java和Jena的ARQ,你可以使用< http://jena.sourceforge.net/ARQ/group-by.htmlrel =nofollow noreferrer> ARQ的聚合扩展。您的查询将如下所示:
If you're using Java and Jena's ARQ, you can use ARQ's extensions for aggregates. Your query would look something like:
SELECT ?tag (count(distinct ?tag) as ?count)
WHERE {
?r ns9:taggedWithTag ?tagresource.
?tagresource ns9:name ?tag
}
LIMIT 5000
2008年起的SPARQL规范不包含汇总,但< a href =http://www.w3.org/TR/sparql11-query/ =nofollow noreferrer>当前版本,1.1,从2013年。
这篇关于SPARQL查询和不同计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文