Hi again, 

I solved the problem myself with help of andy's previous reply. 
I just needed some patients. Sorry for inconvenience.


In case if it helps for some one around this group here is the code

----------------------------------------------------------------------------------------------------------
 Var v1 = Var.alloc("instance");
  Expr ev1 = new ExprVar(v1);
  
  Var v2 = Var.alloc("fpredicate");
  Expr pre = new ExprVar(v2);
  
  Var v3 = Var.alloc("object");
  Expr ev3 = new ExprVar(v3);
  
  Var v4 = Var.alloc("otype");
  
  Var v5 = Var.alloc("coverage");
  
  Var v6 = Var.alloc("ficount");
  
  Var v7 = Var.alloc("focount");
  
  Triple t1 = new 
Triple(v1.asNode(),RDF.type.asNode(),NodeValue.makeNodeString("<http://data.linkedmdb.org/resource/movie/film>").asNode());
  Triple t2 = new Triple(v1.asNode(), v2.asNode(), v3.asNode());
  
  BasicPattern bp1 = new BasicPattern();
  bp1.add(t1);
  bp1.add(t2);
  
  Op op = new OpBGP(bp1);
  
  
  
  Expr str = new E_Str(pre);
  
  E_Regex reex = new E_Regex(str, "http://data.linkedmdb.org/resource/";, "i");
  
  op = OpFilter.filter(reex, op);
  
  VarExprList exl = new VarExprList();
  exl.add(v2);
  
  ExprList el1 = new ExprList();
  el1.add(ev3);
  
  Expr exf1 = new E_Function("java:facet.ifuri", el1);
  
    
  exl.add(v4, exf1);
  
  Aggregator agg1 = new AggCountVarDistinct(ev1);
  Aggregator agg2 = new AggCountVarDistinct(ev3);
  
  
  ExprAggregator eagg1 = new ExprAggregator(v6, agg1);
  ExprAggregator eagg2 = new ExprAggregator(v7, agg2);
  
  List<ExprAggregator> aggrelist = new ArrayList<ExprAggregator>();
  
  aggrelist.add(eagg1);
  aggrelist.add(eagg2);
  
  op =new OpGroup(op,exl, aggrelist);
  
  ExprList el2 = new ExprList();
  el2.add(eagg1);
  el2.add(eagg2);
  Expr v = NodeValue.makeNodeString("85620");
  el2.add(v);
  
  Expr exf2 = new E_Function("java:facet.weights3", el2);
  
  VarExprList var = new VarExprList();
  var.add(v2);
  var.add(v5, exf2);
  var.add(v6,agg1.getExpr());
  var.add(v7, agg2.getExpr());
  var.add(v4);
  
  op = new OpProject(op, var.getVars());
  op.output(new IndentedWriter(System.out));
  
  System.out.println("\n\n\n");
  
  Query query = OpAsQuery.asQuery(op);
  
   
  query.serialize(new IndentedWriter(System.out,true)) ; 
--------------------------------------------------------------------------------------------------------------------------------


Regards, 
ajaz 











________________________________
 From: ajaz shaik <[email protected]>
To: Jena incubator <[email protected]> 
Sent: Friday, 18 November 2011 1:50 PM
Subject: ARQ Building query incrementally help 
 
Dear all, 

I need some help in changing my static SPARQL query to build Incrementally 
using ARQ. 
below is my query 

 1 PREFIX  dc:   <http://purl.org/dc/terms/>
  2 PREFIX  db:   <http://data.linkedmdb.org/resource/>
  3 PREFIX  foaf: <http://xmlns.com/foaf/0.1/>
  4 PREFIX  movie: <http://data.linkedmdb.org/resource/movie/>
  5 PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
  6 PREFIX  oddlinker: <http://data.linkedmdb.org/resource/oddlinker/>
  7 PREFIX  d2r:  
<http://sites.wiwiss.fu-berlin.de/suhl/bizer/d2r-server/config.rdf#>
  8 PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
  9 PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
 10 PREFIX  map:  <file:///C:/d2r-server-0.4/mapping.n3#>
 11 PREFIX  dbpedia: <http://dbpedia.org/property/>
 12 PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 13 PREFIX  skos: <http://www.w3.org/2004/02/skos/core#>
 14 PREFIX  fn:   <java:facet.>
 15 
 16 SELECT  ?fpredicate (count(distinct ?instance) AS ?ficount) (count(distinct 
?object) AS ?focount) (fn:weights3(count(distinct ?instance), count(distinct 
?object), 85620) AS ?coverage) ?otype
 17 WHERE
 18   { ?instance rdf:type movie:film .
 19     ?instance ?fpredicate ?object
 20     FILTER regex(str(?fpredicate), "http://data.linkedmdb.org/resource/";, 
"i")
 21   }
 22 GROUP BY ?fpredicate (fn:ifuri(?object) AS ?otype)
  1 (project (?fpredicate ?ficount ?focount ?coverage ?otype)
  2   (extend ((?ficount ?.0) (?focount ?.1) (?coverage (<java:facet.weights3> 
?.0 ?.1 85620)))
  3     (group (?fpredicate (?otype (<java:facet.ifuri> ?object))) ((?.0 (count 
distinct ?instance)) (?.1 (count distinct ?object)))
  4       (filter (regex (str ?fpredicate) 
"http://data.linkedmdb.org/resource/"; "i")
  5         (bgp
  6           (triple ?instance 
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
<http://data.linkedmdb.org/resource/movie/film>)
  7           (triple ?instance ?fpredicate ?object)
  8         ))))) 

                                        </code></pre>

I want to build the above query incrementally because, I dynamically add 
Triples (as constraints) inside bgp. 
I really appreciate if any of experts here can at least give me rough code. I 
have seen all the documentation 
went through the ARQ code of AlgebraGenerator but it did not help me. I am 
still confused in adding 
functions to projections grouping by functions. Kindly pardon me it was 
trivial.  

I appreciate your help. 

Regards 
aj 

Reply via email to