Query query = QueryFactory.make() ;
query.setQuerySelectType() ;
// See also ExProg1
ElementGroup elg = new ElementGroup() ;
Var varTitle = Var.alloc("title") ;
Var varX = Var.alloc("x") ;
Triple t1 = new Triple(varX, DC.title.asNode(), varTitle) ;
elg.addTriplePattern(t1) ;
// Adds a filter. Need to wrap variable in a NodeVar.
Expr expr = new E_Regex(new ExprVar(varTitle), "sparql", "i") ;
ElementFilter filter = new ElementFilter(expr) ;
elg.addElementFilter(filter) ;
// Attach the group to query.
query.setQueryPattern(elg) ;
// Choose what we want - SELECT ?title