Search in sources :

Example 1 with ElementFilter

use of org.apache.jena.sparql.syntax.ElementFilter in project jena by apache.

the class ElementRewriter method visit.

@Override
public void visit(ElementFilter el) {
    ExprRewriter exprRewriter = new ExprRewriter(values);
    el.getExpr().visit(exprRewriter);
    push(new ElementFilter(exprRewriter.getResult()));
}
Also used : ElementFilter(org.apache.jena.sparql.syntax.ElementFilter)

Example 2 with ElementFilter

use of org.apache.jena.sparql.syntax.ElementFilter in project jena by apache.

the class WhereHandlerTest method testAddFilterVarOnly.

@Test
public void testAddFilterVarOnly() throws ParseException {
    handler.addFilter("?one");
    handler.build();
    ExprFactory fact = new ExprFactory();
    WhereValidator visitor = new WhereValidator(new ElementFilter(fact.asExpr("?one")));
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementFilter(org.apache.jena.sparql.syntax.ElementFilter) ExprFactory(org.apache.jena.arq.querybuilder.ExprFactory) Test(org.junit.Test)

Example 3 with ElementFilter

use of org.apache.jena.sparql.syntax.ElementFilter in project jena by apache.

the class WhereHandlerTest method testSetVarsInFilter.

@Test
public void testSetVarsInFilter() throws ParseException {
    handler.addFilter("?one < ?v");
    handler.build();
    E_LessThan expr = new ExprFactory().lt(NodeFactory.createVariable("one"), NodeFactory.createVariable("v"));
    WhereValidator visitor = new WhereValidator(new ElementFilter(expr));
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    Map<Var, Node> values = new HashMap<>();
    values.put(Var.alloc("v"), NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10)));
    handler.setVars(values);
    handler.build();
    expr = new ExprFactory().lt(NodeFactory.createVariable("one"), NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10)));
    visitor = new WhereValidator(new ElementFilter(expr));
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Var(org.apache.jena.sparql.core.Var) ElementFilter(org.apache.jena.sparql.syntax.ElementFilter) Node(org.apache.jena.graph.Node) E_LessThan(org.apache.jena.sparql.expr.E_LessThan) ExprFactory(org.apache.jena.arq.querybuilder.ExprFactory) Test(org.junit.Test)

Example 4 with ElementFilter

use of org.apache.jena.sparql.syntax.ElementFilter in project jena by apache.

the class WhereClauseTest method testSetVarsInFilter.

@ContractTest
public void testSetVarsInFilter() throws ParseException {
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addFilter("?one < ?v");
    ExprVar one = new ExprVar(NodeFactory.createVariable("one"));
    ExprVar v = new ExprVar(NodeFactory.createVariable("v"));
    Expr expr = new E_LessThan(one, v);
    ElementFilter filter = new ElementFilter(expr);
    WhereValidator visitor = new WhereValidator(filter);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    Node literal = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10));
    builder.setVar(Var.alloc("v"), literal);
    NodeValueInteger lit = new NodeValueInteger(10);
    expr = new E_LessThan(one, lit);
    filter = new ElementFilter(expr);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementFilter(org.apache.jena.sparql.syntax.ElementFilter) Node(org.apache.jena.graph.Node) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) E_LessThan(org.apache.jena.sparql.expr.E_LessThan) ContractTest(org.xenei.junit.contract.ContractTest)

Example 5 with ElementFilter

use of org.apache.jena.sparql.syntax.ElementFilter 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)

Aggregations

ElementFilter (org.apache.jena.sparql.syntax.ElementFilter)9 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)6 ExprFactory (org.apache.jena.arq.querybuilder.ExprFactory)4 E_LessThan (org.apache.jena.sparql.expr.E_LessThan)4 ExprVar (org.apache.jena.sparql.expr.ExprVar)4 Test (org.junit.Test)4 Var (org.apache.jena.sparql.core.Var)3 Expr (org.apache.jena.sparql.expr.Expr)3 Node (org.apache.jena.graph.Node)2 Triple (org.apache.jena.graph.Triple)2 E_Regex (org.apache.jena.sparql.expr.E_Regex)2 NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)2 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)2 ContractTest (org.xenei.junit.contract.ContractTest)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)1 Op (org.apache.jena.sparql.algebra.Op)1 E_Equals (org.apache.jena.sparql.expr.E_Equals)1