use of org.apache.jena.sparql.expr.E_LessThan in project jena by apache.
the class AlgebraExec method main.
public static void main(String[] argv) {
String BASE = "http://example/";
BasicPattern bp = new BasicPattern();
Var var_x = Var.alloc("x");
Var var_z = Var.alloc("z");
// ---- Build expression
bp.add(new Triple(var_x, NodeFactory.createURI(BASE + "p"), var_z));
Op op = new OpBGP(bp);
// Expr expr = ExprUtils.parse("?z < 2 ") ;
Expr expr = new E_LessThan(new ExprVar(var_z), NodeValue.makeNodeInteger(2));
op = OpFilter.filter(expr, op);
// ---- Example setup
Model m = makeModel();
m.write(System.out, "TTL");
System.out.println("--------------");
System.out.print(op);
System.out.println("--------------");
// ---- Execute expression
QueryIterator qIter = Algebra.exec(op, m.getGraph());
// -------- Either read the query iterator directly ...
if (false) {
for (; qIter.hasNext(); ) {
Binding b = qIter.nextBinding();
Node n = b.get(var_x);
System.out.println(NodeFmtLib.displayStr(n));
System.out.println(b);
}
qIter.close();
} else {
// -------- Or make ResultSet from it (but not both - reading an
// iterator consumes the current solution)
List<String> varNames = new ArrayList<>();
varNames.add("x");
varNames.add("z");
ResultSet rs = ResultSetStream.create(varNames, m, qIter);
ResultSetFormatter.out(rs);
qIter.close();
}
System.exit(0);
}
use of org.apache.jena.sparql.expr.E_LessThan in project jena by apache.
the class WhereHandlerTest method testAddFilter.
@Test
public void testAddFilter() throws ParseException {
handler.addFilter("?one < 10");
handler.build();
BigInteger bi = new BigInteger(Integer.toString(10));
E_LessThan expr = new ExprFactory().lt(NodeFactory.createVariable("one"), bi);
WhereValidator visitor = new WhereValidator(new ElementFilter(expr));
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.expr.E_LessThan in project jena by apache.
the class WhereClauseTest method testAddFilter.
@ContractTest
public void testAddFilter() throws ParseException {
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addFilter("?one<10");
E_LessThan lt = new E_LessThan(new ExprVar(Var.alloc("one")), new NodeValueInteger(10));
ElementFilter ef = new ElementFilter(lt);
WhereValidator visitor = new WhereValidator(ef);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations