Yes, though the Virtuoso specific syntax shown there is not legal SPARQL See Aggregates (http://www.w3.org/TR/sparql11-query/#aggregates) in the SPARQL 1.1 specification which Jena fully supports
Rob On 12/05/2014 05:49, "Md Mizanur Rahoman" <mi...@nii.ac.jp> wrote: >Dear Experts, > >My question is: > >Is there any Jena implementation that can execute Aggregate function like >count, sum etc? Iterative counting of all elements could an option, >however, I want to know about direct implement of below method. > >such as, the below method > >------------------------------ >------------------------------------------------------------------------ >public void queryExecutor(VirtGraph dataset) { > > String query = > "select distinct ?T1 ?T2 count(*) "+ > "from <http://dbpedia.org> "+ > "where "+ > "{ "+ > "?s1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?T1. "+ > "?s2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?T2. "+ > "?s1 <http://dbpedia.org/property/spouse> ?s2. "+ > "?s2 <http://dbpedia.org/property/birthPlace> ?obj. "+ > "FILTER(REGEX(?T1, \"http://dbpedia.org/ontology/\")). "+ > "FILTER(REGEX(?T2, \"http://dbpedia.org/ontology/\")). "+ > "}"+ > "group by ?T1 ?T2 "; > > > System.out.println(query); > > Query sparql1 = QueryFactory.create(query, >Syntax.syntaxSPARQL_11); > try { > VirtuosoQueryExecution vqe1 = >VirtuosoQueryExecutionFactory.create(sparql1, dataset); > ResultSet results1 = vqe1.execSelect(); > > } > catch (Exception e) { > System.out.println("Error in query execution: " + >e.toString()); > e.printStackTrace(); > } > > } >-------------------------------------------------------------------------- >--------------------------------- > > >- >Regards >Mizan >NII, Japan > > > >---------- Forwarded message ---------- >From: Md Mizanur Rahoman <mi...@nii.ac.jp> >Date: Wed, May 7, 2014 at 7:35 PM >Subject: Group By Query in Jena Java >To: users@jena.apache.org > > >Dear Expert, > >I want to execute a group by query in Jena. I am using Jena V2.6.4. But it >is giving exception >-------------------------------------------------------------------------- >--------------------------- > >Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: >Encountered " "count" "count "" at line 1, column 26. > >-------------------------------------------------------------------------- >---------------------------- >And here is my method, > >-------------------------------------------------------------------------- >---------------------------- >public void queryExecutor(VirtGraph dataset) { > > String query = > "select distinct ?T1 ?T2 count(*) "+ > "from <http://dbpedia.org> "+ > "where "+ > "{ "+ > "?s1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?T1. "+ > "?s2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?T2. "+ > "?s1 <http://dbpedia.org/property/spouse> ?s2. "+ > "?s2 <http://dbpedia.org/property/birthPlace> ?obj. "+ > "FILTER(REGEX(?T1, \"http://dbpedia.org/ontology/\")). "+ > "FILTER(REGEX(?T2, \"http://dbpedia.org/ontology/\")). "+ > "}"+ > "group by ?T1 ?T2 "; > > > System.out.println(query); > > Query sparql1 = QueryFactory.create(query, >Syntax.syntaxSPARQL_11); > try { > VirtuosoQueryExecution vqe1 = >VirtuosoQueryExecutionFactory.create(sparql1, dataset); > ResultSet results1 = vqe1.execSelect(); > > } > catch (Exception e) { > System.out.println("Error in query execution: " + >e.toString()); > e.printStackTrace(); > } > > } >-------------------------------------------------------------------------- >--------------------------------- > >My question is: > >* Is there any Jena version that can execute Aggregate function like >count, >sum etc? > >- >Regards >Mizanur >NII, Japan