use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testListInTriple.
@Test
public void testListInTriple() {
handler.addWhere(new TriplePath(new Triple(handler.list("<one>", "?var", "'three'"), ResourceFactory.createResource("foo").asNode(), ResourceFactory.createResource("bar").asNode())));
handler.build();
P_Link first = new P_Link(RDF.first.asNode());
P_Link rest = new P_Link(RDF.rest.asNode());
Node n = NodeFactory.createURI("foo");
P_Link foo = new P_Link(n);
// ElementPathBlock epb = (ElementPathBlock) query.getQueryPattern();
ElementPathBlock epb = new ElementPathBlock();
Node list = NodeFactory.createBlankNode();
Node s = list;
epb.addTriple(new TriplePath(s, first, NodeFactory.createURI("one")));
Node o = NodeFactory.createBlankNode();
epb.addTriple(new TriplePath(s, rest, o));
s = o;
epb.addTriple(new TriplePath(s, first, Var.alloc("var")));
o = NodeFactory.createBlankNode();
epb.addTriple(new TriplePath(s, rest, o));
s = o;
epb.addTriple(new TriplePath(s, first, NodeFactory.createLiteral("three")));
epb.addTriple(new TriplePath(s, rest, RDF.nil.asNode()));
epb.addTriple(new TriplePath(list, foo, NodeFactory.createURI("bar")));
WhereValidator visitor = new WhereValidator(epb);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddWhereObjectsWithPath.
@Test
public void testAddWhereObjectsWithPath() {
PrefixMapping pmap = new PrefixMappingImpl();
pmap.setNsPrefix("ts", "urn:test:");
Path path = PathParser.parse("ts:two/ts:dos", pmap);
handler.addWhere(new TriplePath(NodeFactory.createURI("one"), path, ResourceFactory.createLangLiteral("three", "en-US").asNode()));
handler.build();
TriplePath tp = new TriplePath(NodeFactory.createURI("one"), path, ResourceFactory.createLangLiteral("three", "en-US").asNode());
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
WhereValidator wv = new WhereValidator(epb);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddUnionToExisting.
@Test
public void testAddUnionToExisting() {
handler.addWhere(new TriplePath(new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o"))));
SelectBuilder sb = new SelectBuilder();
sb.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
handler.addUnion(sb);
handler.build();
TriplePath tp1 = new TriplePath(new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o")));
ElementPathBlock epb1 = new ElementPathBlock();
epb1.addTriple(tp1);
TriplePath tp2 = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
ElementPathBlock epb2 = new ElementPathBlock();
epb2.addTriple(tp2);
ElementUnion union = new ElementUnion();
union.addElement(epb1);
union.addElement(epb2);
WhereValidator visitor = new WhereValidator(union);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testSetVarsInOptional.
@Test
public void testSetVarsInOptional() {
Var v = Var.alloc("v");
handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v)));
handler.build();
TriplePath tp = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v));
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
ElementOptional opt = new ElementOptional(epb);
WhereValidator wv = new WhereValidator(opt);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
Map<Var, Node> values = new HashMap<>();
values.put(v, NodeFactory.createURI("three"));
handler.setVars(values);
handler.build();
tp = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
epb = new ElementPathBlock();
epb.addTriple(tp);
opt = new ElementOptional(epb);
wv = new WhereValidator(opt);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddValueVar_pfx_obj_array.
@Test
public void testAddValueVar_pfx_obj_array() {
Node two = NodeFactory.createURI("two");
handler.addValueVar(query.getPrefixMapping(), "?v", "<one>", two);
handler.build();
Var v = Var.alloc("v");
ElementData edat = new ElementData();
edat.add(v);
Binding binding1 = BindingFactory.binding(v, NodeFactory.createURI("one"));
edat.add(binding1);
Binding binding2 = BindingFactory.binding(v, two);
edat.add(binding2);
WhereValidator visitor = new WhereValidator(edat);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations