Search in sources :

Example 1 with ExprFactory

use of org.apache.jena.arq.querybuilder.ExprFactory 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 2 with ExprFactory

use of org.apache.jena.arq.querybuilder.ExprFactory 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 3 with ExprFactory

use of org.apache.jena.arq.querybuilder.ExprFactory 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 4 with ExprFactory

use of org.apache.jena.arq.querybuilder.ExprFactory in project jena by apache.

the class WhereHandlerTest method testAddFilterWithNamespace.

@Test
public void testAddFilterWithNamespace() throws ParseException {
    query.setPrefix("afn", "http://jena.apache.org/ARQ/function#");
    handler.addFilter("afn:namespace(?one) = 'foo'");
    handler.build();
    ExprFactory fact = new ExprFactory();
    E_Function func = new E_Function("http://jena.apache.org/ARQ/function#namespace", fact.asList("?one"));
    E_Equals expr = fact.eq(func, "foo");
    WhereValidator visitor = new WhereValidator(new ElementFilter(expr));
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) E_Equals(org.apache.jena.sparql.expr.E_Equals) ElementFilter(org.apache.jena.sparql.syntax.ElementFilter) E_Function(org.apache.jena.sparql.expr.E_Function) ExprFactory(org.apache.jena.arq.querybuilder.ExprFactory) Test(org.junit.Test)

Aggregations

ExprFactory (org.apache.jena.arq.querybuilder.ExprFactory)4 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)4 ElementFilter (org.apache.jena.sparql.syntax.ElementFilter)4 Test (org.junit.Test)4 E_LessThan (org.apache.jena.sparql.expr.E_LessThan)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Node (org.apache.jena.graph.Node)1 Var (org.apache.jena.sparql.core.Var)1 E_Equals (org.apache.jena.sparql.expr.E_Equals)1 E_Function (org.apache.jena.sparql.expr.E_Function)1