1

I want to get total count of sparql query results. I am using jena API for this in java. count query is working in virtuoso but its not working in java using jena api.

Sparql Query:

select ( count ( ?name ) AS ?total ) from < mygraph > 
where { ?name rdf:type foaf:Name}

Its not working in jena API. I have read http://www.w3.org/2001/sw/DataAccess/issues#countAggregate So I think its not working in rdf but its working in Virtuoso sparql editor. So if u have a solution then plz let me know.And also tell me if there is alternative solution.

Thank you

Here is my java code,

String countQueryString="select ( count ( ?name ) AS ?total ) from < mygraph > 
where { ?name rdf:type foaf:Name}";
Query selectQuery = QueryFactory.create(countQueryString);
        QueryExecution qe = QueryExecutionFactory.sparqlService(Constant.SPARQL_ENDPOINT, selectQuery);
Resultset results=qe.execSelect();
if(results.hasNext())
{
    totalCount=countResult.next().get("total").toString();
}

Below is the exception: HttpException: HttpException: 400 Bad Request: HttpException: 400 Bad Request.....

4

1 回答 1

2

Take a look at the ARQ documentation for aggregate support (I encountered similar issues)

http://jena.apache.org/documentation/query/group-by.html

It seems that it doesn't support

(count(?variable) as ?binding)

In the past I have also tried removing the parenthesis around the aggregate projection i.e:

select count ( ?name ) AS ?total from < mygraph > where { ?name rdf:type foaf:Name}

But this was because Virtuoso actually had an issue with them.

于 2012-05-30T11:11:03.877 回答