use of org.apache.jena.sparql.syntax.ElementPathBlock 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);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereHandlerTest method testAddUnionWithVar.
@Test
public void testAddUnionWithVar() {
Triple t1 = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
Triple t2 = new Triple(NodeFactory.createURI("uno"), NodeFactory.createURI("dos"), NodeFactory.createURI("tres"));
SelectBuilder sb = new SelectBuilder().addVar("x").addWhere(t1);
handler.addUnion(sb);
SelectBuilder sb2 = new SelectBuilder().addWhere(t2);
handler.addUnion(sb2);
handler.build();
ElementUnion union = new ElementUnion();
Query q = new Query();
q.setQuerySelectType();
ElementPathBlock epb1 = new ElementPathBlock();
epb1.addTriple(t1);
q.setQueryPattern(epb1);
q.addProjectVars(Arrays.asList(Var.alloc("x")));
ElementSubQuery sq = new ElementSubQuery(q);
union.addElement(sq);
ElementPathBlock epb2 = new ElementPathBlock();
epb2.addTriple(t2);
union.addElement(epb2);
WhereValidator visitor = new WhereValidator(union);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereHandlerTest method testList.
@Test
public void testList() {
Node n = handler.list("<one>", "?var", "'three'");
Node one = NodeFactory.createURI("one");
Node two = Var.alloc("var").asNode();
Node three = NodeFactory.createLiteral("three");
ElementPathBlock epb = new ElementPathBlock();
Node firstObject = NodeFactory.createBlankNode();
Node secondObject = NodeFactory.createBlankNode();
Node thirdObject = NodeFactory.createBlankNode();
epb.addTriplePath(new TriplePath(new Triple(firstObject, RDF.first.asNode(), one)));
epb.addTriplePath(new TriplePath(new Triple(firstObject, RDF.rest.asNode(), secondObject)));
epb.addTriplePath(new TriplePath(new Triple(secondObject, RDF.first.asNode(), two)));
epb.addTriplePath(new TriplePath(new Triple(secondObject, RDF.rest.asNode(), thirdObject)));
epb.addTriplePath(new TriplePath(new Triple(thirdObject, RDF.first.asNode(), three)));
epb.addTriplePath(new TriplePath(new Triple(thirdObject, RDF.rest.asNode(), RDF.nil.asNode())));
WhereValidator visitor = new WhereValidator(epb);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
assertTrue(n.isBlank());
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereHandlerTest method testAddSubQueryWithVars.
@Test
public void testAddSubQueryWithVars() {
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addVar("?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.setQuerySelectType();
q.setQueryPattern(epb);
ElementSubQuery esq = new ElementSubQuery(q);
WhereValidator wv = new WhereValidator(esq);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock 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);
}
Aggregations