Search in sources :

Example 46 with WhereValidator

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

the class WhereClauseTest method testSetVarsInTriple.

@ContractTest
public void testSetVarsInTriple() {
    Var v = Var.alloc("v");
    Node one = NodeFactory.createURI("one");
    Node two = NodeFactory.createURI("two");
    Node three = NodeFactory.createURI("three");
    Node four = NodeFactory.createURI("four");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhere(new Triple(one, two, v));
    TriplePath tp = new TriplePath(new Triple(one, two, v));
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    WhereValidator visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, three);
    tp = new TriplePath(new Triple(one, two, three));
    epb = new ElementPathBlock();
    epb.addTriple(tp);
    visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, four);
    tp = new TriplePath(new Triple(one, two, four));
    epb = new ElementPathBlock();
    epb.addTriple(tp);
    visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, null);
    tp = new TriplePath(new Triple(one, two, v));
    epb = new ElementPathBlock();
    epb.addTriple(tp);
    visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 47 with WhereValidator

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

the class WhereClauseTest method testBindExprVar.

@ContractTest
public void testBindExprVar() {
    Var v = Var.alloc("foo");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addBind(new E_Random(), v);
    Query query = builder.build();
    WhereValidator visitor = new WhereValidator(new ElementBind(Var.alloc("foo"), new E_Random()));
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    builder.setVar(v, NodeFactory.createURI("three"));
    query = builder.build();
    visitor = new WhereValidator(new ElementTriplesBlock());
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) E_Random(org.apache.jena.sparql.expr.E_Random) ElementBind(org.apache.jena.sparql.syntax.ElementBind) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 48 with WhereValidator

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

the class WhereClauseTest method testAddGraph_triplePath.

@ContractTest
public void testAddGraph_triplePath() {
    final Node s = NodeFactory.createURI("s");
    final Node p = NodeFactory.createURI("p");
    final Node o = NodeFactory.createURI("o");
    TriplePath tp = new TriplePath(new Triple(s, p, o));
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addGraph("<g>", tp);
    Query query = builder.build();
    ElementPathBlock epb = new ElementPathBlock();
    ElementNamedGraph eng = new ElementNamedGraph(NodeFactory.createURI("g"), epb);
    epb.addTriplePath(new TriplePath(new Triple(s, p, o)));
    WhereValidator visitor = new WhereValidator(eng);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ElementNamedGraph(org.apache.jena.sparql.syntax.ElementNamedGraph) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 49 with WhereValidator

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

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

the class WhereHandlerTest method testAddMinus.

@Test
public void testAddMinus() {
    SelectBuilder sb = new SelectBuilder();
    sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", "three");
    handler.addMinus(sb);
    handler.build();
    ElementPathBlock epb = new ElementPathBlock();
    ElementMinus minus = new ElementMinus(epb);
    epb.addTriplePath(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"))));
    WhereValidator visitor = new WhereValidator(minus);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementMinus(org.apache.jena.sparql.syntax.ElementMinus) TriplePath(org.apache.jena.sparql.core.TriplePath) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) 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