use of org.apache.jena.sparql.syntax.ElementSubQuery in project jena by apache.
the class WhereHandlerTest method testMakeSubQueryFromWhere.
@Test
public void testMakeSubQueryFromWhere() {
AbstractQueryBuilder<?> sb = new WhereBuilder().addWhere("?x", RDF.type, RDF.Alt);
ElementSubQuery esq = handler.makeSubQuery(sb);
Triple t1 = new Triple(NodeFactory.createVariable("x"), RDF.type.asNode(), RDF.Alt.asNode());
TriplePath tp = new TriplePath(t1);
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
Query q = new Query();
q.setQuerySelectType();
q.setQueryResultStar(true);
q.setQueryPattern(epb);
ElementSubQuery esq2 = new ElementSubQuery(q);
WhereValidator wv = new WhereValidator(esq2);
esq.visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.sparql.syntax.ElementSubQuery in project jena by apache.
the class WhereClauseTest method testSetVarsInSubQuery_Node_Variable.
@ContractTest
public void testSetVarsInSubQuery_Node_Variable() {
Node v = NodeFactory.createVariable("v");
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", v);
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addSubQuery(sb);
Query subQuery = new Query();
subQuery.setQuerySelectType();
subQuery.setQueryResultStar(true);
ElementSubQuery esq = new ElementSubQuery(subQuery);
ElementPathBlock epb = new ElementPathBlock();
subQuery.setQueryPattern(epb);
TriplePath tp = new TriplePath(NodeFactory.createURI("one"), new P_Link(NodeFactory.createURI("two")), NodeFactory.createVariable("v"));
epb.addTriple(tp);
WhereValidator visitor = new WhereValidator(esq);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, NodeFactory.createURI("three"));
subQuery = new Query();
subQuery.setQuerySelectType();
subQuery.setQueryResultStar(true);
esq = new ElementSubQuery(subQuery);
epb = new ElementPathBlock();
subQuery.setQueryPattern(epb);
tp = new TriplePath(NodeFactory.createURI("one"), new P_Link(NodeFactory.createURI("two")), NodeFactory.createURI("three"));
epb.addTriple(tp);
visitor = new WhereValidator(esq);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementSubQuery in project jena by apache.
the class WhereClauseTest method testAddSubQuery.
@ContractTest
public void testAddSubQuery() {
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "urn:uri:").addVar("?x").addWhere("pfx:one", "pfx:two", "pfx:three");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addSubQuery(sb);
Query query = builder.build();
Query q2 = new Query();
q2.setQuerySelectType();
q2.addProjectVars(Arrays.asList(Var.alloc("x")));
ElementPathBlock epb = new ElementPathBlock();
q2.setQueryPattern(epb);
epb.addTriplePath(new TriplePath(new Triple(NodeFactory.createURI("urn:uri:one"), NodeFactory.createURI("urn:uri:two"), NodeFactory.createURI("urn:uri:three"))));
ElementSubQuery esq = new ElementSubQuery(q2);
WhereValidator visitor = new WhereValidator(esq);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementSubQuery in project jena by apache.
the class WhereHandlerTest method testMakeSubQueryFromAsk.
@Test
public void testMakeSubQueryFromAsk() {
AbstractQueryBuilder<?> sb = new AskBuilder().addWhere("?x", RDF.type, RDF.Alt);
ElementSubQuery esq = handler.makeSubQuery(sb);
Triple t1 = new Triple(NodeFactory.createVariable("x"), RDF.type.asNode(), RDF.Alt.asNode());
TriplePath tp = new TriplePath(t1);
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
Query q = new Query();
q.setQuerySelectType();
q.setQueryResultStar(true);
q.setQueryPattern(epb);
ElementSubQuery esq2 = new ElementSubQuery(q);
WhereValidator wv = new WhereValidator(esq2);
esq.visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.sparql.syntax.ElementSubQuery 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);
}
Aggregations