use of org.apache.jena.arq.querybuilder.WhereBuilder 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.arq.querybuilder.WhereBuilder in project jena by apache.
the class QBQuadHolderTest method namedTest_Var.
@Test
public void namedTest_Var() {
WhereBuilder builder = new WhereBuilder();
Node g = NodeFactory.createURI("g");
List<Triple> tLst = new ArrayList<Triple>();
Node s = NodeFactory.createURI("s");
Node p = NodeFactory.createVariable("p");
Node o = NodeFactory.createURI("o");
builder.addGraph(g, s, p, o);
Node s2 = NodeFactory.createURI("s2");
Node p2 = NodeFactory.createURI("p2");
Node o2 = NodeFactory.createURI("o2");
tLst.add(new Triple(s, p2, o));
tLst.add(new Triple(s2, p2, o2));
builder.addGraph(g, s2, p, o2);
holder = new QBQuadHolder(builder);
Map<Var, Node> map = new HashMap<>();
map.put(Var.alloc(p), p2);
holder.setValues(map);
List<Quad> lst = holder.getQuads().toList();
assertEquals(2, lst.size());
assertEquals(new Quad(g, tLst.get(0)), lst.get(0));
assertEquals(new Quad(g, tLst.get(1)), lst.get(1));
}
use of org.apache.jena.arq.querybuilder.WhereBuilder in project jena by apache.
the class QBQuadHolderTest method mixedTest.
@Test
public void mixedTest() {
WhereBuilder builder = new WhereBuilder();
List<Triple> tLst = new ArrayList<Triple>();
Node s = NodeFactory.createURI("s");
Node p = NodeFactory.createURI("p");
Node o = NodeFactory.createURI("o");
tLst.add(new Triple(s, p, o));
builder.addWhere(s, p, o);
Node g = NodeFactory.createURI("g");
Node s2 = NodeFactory.createURI("s2");
Node p2 = NodeFactory.createURI("p2");
Node o2 = NodeFactory.createURI("o2");
tLst.add(new Triple(s2, p2, o2));
builder.addGraph(g, s2, p2, o2);
holder = new QBQuadHolder(builder);
List<Quad> lst = holder.getQuads().toList();
assertEquals(2, lst.size());
assertEquals(new Quad(Quad.defaultGraphNodeGenerated, tLst.get(0)), lst.get(0));
assertEquals(new Quad(g, tLst.get(1)), lst.get(1));
}
use of org.apache.jena.arq.querybuilder.WhereBuilder in project jena by apache.
the class QBQuadHolderTest method namedTest.
@Test
public void namedTest() {
WhereBuilder builder = new WhereBuilder();
Node g = NodeFactory.createURI("g");
List<Triple> tLst = new ArrayList<Triple>();
Node s = NodeFactory.createURI("s");
Node p = NodeFactory.createURI("p");
Node o = NodeFactory.createURI("o");
tLst.add(new Triple(s, p, o));
builder.addGraph(g, s, p, o);
Node s2 = NodeFactory.createURI("s2");
Node p2 = NodeFactory.createURI("p2");
Node o2 = NodeFactory.createURI("o2");
tLst.add(new Triple(s2, p2, o2));
builder.addGraph(g, s2, p2, o2);
holder = new QBQuadHolder(builder);
List<Quad> lst = holder.getQuads().toList();
assertEquals(2, lst.size());
assertEquals(new Quad(g, tLst.get(0)), lst.get(0));
assertEquals(new Quad(g, tLst.get(1)), lst.get(1));
}
use of org.apache.jena.arq.querybuilder.WhereBuilder in project jena by apache.
the class WhereClauseTest method testAddWhereWhereClause.
@ContractTest
public void testAddWhereWhereClause() {
WhereBuilder whereBuilder = new WhereBuilder().addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"))));
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addWhere(whereBuilder);
ElementPathBlock epb = new ElementPathBlock();
Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
epb.addTriple(t);
WhereValidator visitor = new WhereValidator(epb);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations