views:

1443

answers:

1

hi all,

i have the following query:

SELECT ?tag WHERE {
?r ns9:taggedWithTag ?tagresource.
?tagresource ns9:name ?tag
}
LIMIT 5000

and the results are:

abc
abc
abc
abc
abc
abc
abc
abd
ads
anb

I want to get somthing like

tag | count
-----------------
abc     7
abd     1
ads     1
anb     1

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?

Thanks in advance

+5  A: 

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)
WHERE {
    ?r ns9:taggedWithTag ?tagresource.
    ?tagresource ns9:name ?tag
}
LIMIT 5000

The (current) SPARQL specification doesn't support these types of aggregates.

Phil M
it doesn't but aggregates are getting added to SPARQL 1.1 and they are widely implemented (via different extensions, as noted)
dajobe