Search in sources :

Example 11 with WhereValidator

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

the class WhereHandlerTest method testAddUnionOfOne.

@Test
public void testAddUnionOfOne() {
    Triple t1 = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
    SelectBuilder sb = new SelectBuilder().addWhere(t1);
    handler.addUnion(sb);
    handler.build();
    ElementPathBlock epb1 = new ElementPathBlock();
    epb1.addTriple(t1);
    WhereValidator visitor = new WhereValidator(epb1);
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 12 with WhereValidator

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

the class WhereHandlerTest method testSetVarsInWhereValues.

@Test
public void testSetVarsInWhereValues() {
    Var v = Var.alloc("v");
    Node value = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10));
    Map<Var, Node> values = new HashMap<>();
    values.put(v, value);
    handler.addValueVar(query.getPrefixMapping(), "?x", "<one>", "?v");
    handler.setVars(values);
    handler.build();
    ElementData edat = new ElementData();
    Var x = Var.alloc("x");
    edat.add(x);
    Binding binding1 = BindingFactory.binding(x, NodeFactory.createURI("one"));
    edat.add(binding1);
    Binding binding2 = BindingFactory.binding(x, value);
    edat.add(binding2);
    WhereValidator visitor = new WhereValidator(edat);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) ElementData(org.apache.jena.sparql.syntax.ElementData) Test(org.junit.Test)

Example 13 with WhereValidator

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

the class WhereHandlerTest method testBindExprVar.

@Test
public void testBindExprVar() {
    Var v = Var.alloc("foo");
    handler.addBind(new E_Random(), v);
    handler.build();
    ElementBind bind = new ElementBind(Var.alloc("foo"), new E_Random());
    WhereValidator visitor = new WhereValidator(bind);
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : E_Random(org.apache.jena.sparql.expr.E_Random) ElementBind(org.apache.jena.sparql.syntax.ElementBind) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Test(org.junit.Test)

Example 14 with WhereValidator

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

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

the class WhereHandlerTest method testAddValueVar_pfx_obj.

@Test
public void testAddValueVar_pfx_obj() {
    handler.addValueVar(query.getPrefixMapping(), "?v");
    handler.build();
    Var v = Var.alloc("v");
    ElementData edat = new ElementData();
    edat.add(v);
    WhereValidator visitor = new WhereValidator(edat);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementData(org.apache.jena.sparql.syntax.ElementData) Test(org.junit.Test)

Aggregations

WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)90 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)60 Triple (org.apache.jena.graph.Triple)54 TriplePath (org.apache.jena.sparql.core.TriplePath)49 Test (org.junit.Test)47 Query (org.apache.jena.query.Query)42 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)42 ContractTest (org.xenei.junit.contract.ContractTest)42 Var (org.apache.jena.sparql.core.Var)34 Node (org.apache.jena.graph.Node)30 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)22 FrontsTriple (org.apache.jena.graph.FrontsTriple)22 ExprVar (org.apache.jena.sparql.expr.ExprVar)21 ElementData (org.apache.jena.sparql.syntax.ElementData)18 ElementOptional (org.apache.jena.sparql.syntax.ElementOptional)16 HashMap (java.util.HashMap)10 ElementUnion (org.apache.jena.sparql.syntax.ElementUnion)8 LinkedHashMap (java.util.LinkedHashMap)7 Binding (org.apache.jena.sparql.engine.binding.Binding)6 E_Random (org.apache.jena.sparql.expr.E_Random)6