Search in sources :

Example 1 with WhereValidator

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

the class WhereHandlerTest method testAddSubQueryWithVarExpressions.

@Test
public void testAddSubQueryWithVarExpressions() throws ParseException {
    SelectBuilder sb = new SelectBuilder();
    sb.addPrefix("pfx", "uri").addVar("count(*)", "?x").addWhere("<one>", "<two>", "three");
    handler.addSubQuery(sb);
    handler.build();
    Triple t1 = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"));
    TriplePath tp = new TriplePath(t1);
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    Query q = new Query();
    q.addResultVar("x", q.allocAggregate(new AggCount()));
    q.setQuerySelectType();
    q.setQueryPattern(epb);
    ElementSubQuery esq = new ElementSubQuery(q);
    WhereValidator wv = new WhereValidator(esq);
    query.getQueryPattern().visit(wv);
    assertTrue(wv.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) TriplePath(org.apache.jena.sparql.core.TriplePath) AggCount(org.apache.jena.sparql.expr.aggregate.AggCount) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 2 with WhereValidator

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

the class WhereHandlerTest method testAddAllOnEmpty.

@Test
public void testAddAllOnEmpty() {
    Query query2 = new Query();
    WhereHandler handler2 = new WhereHandler(query2);
    handler2.addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"))));
    handler.addAll(handler2);
    handler.build();
    Triple t1 = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"));
    TriplePath tp = new TriplePath(t1);
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    WhereValidator wv = new WhereValidator(epb);
    query.getQueryPattern().visit(wv);
    assertTrue(wv.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 3 with WhereValidator

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

the class WhereHandlerTest method testAddWhereObjects.

@Test
public void testAddWhereObjects() {
    handler.addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), ResourceFactory.createResource("two").asNode(), ResourceFactory.createLangLiteral("three", "en-US").asNode())));
    handler.build();
    Triple t1 = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), ResourceFactory.createLangLiteral("three", "en-US").asNode());
    TriplePath tp = new TriplePath(t1);
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    WhereValidator wv = new WhereValidator(epb);
    query.getQueryPattern().visit(wv);
    assertTrue(wv.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) TriplePath(org.apache.jena.sparql.core.TriplePath) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 4 with WhereValidator

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

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

the class WhereHandlerTest method testSetVarsInTriple.

@Test
public void testSetVarsInTriple() {
    Var v = Var.alloc("v");
    handler.addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v)));
    handler.build();
    Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v);
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(t);
    WhereValidator visitor = new WhereValidator(epb);
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
    Map<Var, Node> values = new HashMap<>();
    values.put(v, NodeFactory.createURI("three"));
    handler.setVars(values);
    handler.build();
    t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
    epb = new ElementPathBlock();
    epb.addTriple(t);
    visitor = new WhereValidator(epb);
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) 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) TriplePath(org.apache.jena.sparql.core.TriplePath) 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