Search in sources :

Example 56 with WhereValidator

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

the class WhereHandlerTest method testAddUnionToExistingWithVar.

@Test
public void testAddUnionToExistingWithVar() {
    handler.addWhere(new TriplePath(new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o"))));
    SelectBuilder sb = new SelectBuilder().addVar("x").addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
    handler.addUnion(sb);
    handler.build();
    Query q = new Query();
    q.setQuerySelectType();
    ElementPathBlock epb1 = new ElementPathBlock();
    epb1.addTriple(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
    q.setQueryPattern(epb1);
    q.addProjectVars(Arrays.asList(Var.alloc("x")));
    ElementSubQuery sq = new ElementSubQuery(q);
    ElementPathBlock epb2 = new ElementPathBlock();
    epb2.addTriple(new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o")));
    ElementUnion union = new ElementUnion();
    union.addElement(epb2);
    union.addElement(sq);
    WhereValidator visitor = new WhereValidator(union);
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) ElementUnion(org.apache.jena.sparql.syntax.ElementUnion) 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) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 57 with WhereValidator

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

the class WhereHandlerTest method testAddOptionalWhereHandler.

@Test
public void testAddOptionalWhereHandler() {
    WhereHandler pattern = new WhereHandler(new Query());
    Var s = Var.alloc("s");
    Node q = NodeFactory.createURI("urn:q");
    Node v = NodeFactory.createURI("urn:v");
    Var x = Var.alloc("x");
    Node n123 = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(123));
    pattern.addWhere(new TriplePath(new Triple(s, q, n123)));
    pattern.addWhere(new TriplePath(new Triple(s, v, x)));
    handler.addOptional(pattern);
    handler.build();
    ElementPathBlock epb = new ElementPathBlock();
    ElementOptional optional = new ElementOptional(epb);
    TriplePath tp = new TriplePath(new Triple(s, q, n123));
    epb.addTriplePath(tp);
    tp = new TriplePath(new Triple(s, v, x));
    epb.addTriplePath(tp);
    WhereValidator visitor = new WhereValidator(optional);
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) ElementOptional(org.apache.jena.sparql.syntax.ElementOptional) 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)

Example 58 with WhereValidator

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

the class WhereHandlerTest method testAddOptionalObjects.

@Test
public void testAddOptionalObjects() {
    handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), ResourceFactory.createResource("two").asNode(), ResourceFactory.createLangLiteral("three", "en-US").asNode())));
    handler.build();
    ElementPathBlock epb = new ElementPathBlock();
    ElementOptional optional = new ElementOptional(epb);
    TriplePath tp = new TriplePath(new Triple(NodeFactory.createURI("one"), ResourceFactory.createResource("two").asNode(), ResourceFactory.createLangLiteral("three", "en-US").asNode()));
    epb.addTriplePath(tp);
    WhereValidator visitor = new WhereValidator(optional);
    handler.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementOptional(org.apache.jena.sparql.syntax.ElementOptional) 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 59 with WhereValidator

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

the class WhereClauseTest method addGraph_GSPO.

public void addGraph_GSPO() {
    final Node s = NodeFactory.createURI("s");
    final Node p = NodeFactory.createURI("p");
    final Node o = NodeFactory.createURI("o");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addGraph("<g>", s, p, o);
    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)

Example 60 with WhereValidator

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

the class WhereClauseTest method testAddFilter.

@ContractTest
public void testAddFilter() throws ParseException {
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addFilter("?one<10");
    E_LessThan lt = new E_LessThan(new ExprVar(Var.alloc("one")), new NodeValueInteger(10));
    ElementFilter ef = new ElementFilter(lt);
    WhereValidator visitor = new WhereValidator(ef);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementFilter(org.apache.jena.sparql.syntax.ElementFilter) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) E_LessThan(org.apache.jena.sparql.expr.E_LessThan) ContractTest(org.xenei.junit.contract.ContractTest)

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