Search in sources :

Example 6 with E_LessThan

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);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) BasicPattern(org.apache.jena.sparql.core.BasicPattern) E_LessThan(org.apache.jena.sparql.expr.E_LessThan) Triple(org.apache.jena.graph.Triple) Expr(org.apache.jena.sparql.expr.Expr) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ResultSet(org.apache.jena.query.ResultSet)

Example 7 with E_LessThan

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);
}
Also used : WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementFilter(org.apache.jena.sparql.syntax.ElementFilter) BigInteger(java.math.BigInteger) E_LessThan(org.apache.jena.sparql.expr.E_LessThan) ExprFactory(org.apache.jena.arq.querybuilder.ExprFactory) Test(org.junit.Test)

Example 8 with E_LessThan

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);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementFilter(org.apache.jena.sparql.syntax.ElementFilter) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) E_LessThan(org.apache.jena.sparql.expr.E_LessThan) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

E_LessThan (org.apache.jena.sparql.expr.E_LessThan)8 Expr (org.apache.jena.sparql.expr.Expr)5 ExprVar (org.apache.jena.sparql.expr.ExprVar)5 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)4 Node (org.apache.jena.graph.Node)4 ElementFilter (org.apache.jena.sparql.syntax.ElementFilter)4 Var (org.apache.jena.sparql.core.Var)3 NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)3 Test (org.junit.Test)3 ContractTest (org.xenei.junit.contract.ContractTest)3 ArrayList (java.util.ArrayList)2 ExprFactory (org.apache.jena.arq.querybuilder.ExprFactory)2 Triple (org.apache.jena.graph.Triple)2 ResultSet (org.apache.jena.query.ResultSet)2 Op (org.apache.jena.sparql.algebra.Op)2 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)2 BasicPattern (org.apache.jena.sparql.core.BasicPattern)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2 BigInteger (java.math.BigInteger)1