use of org.apache.jena.sparql.syntax.ElementOptional in project jena by apache.
the class WhereHandlerTest method testAddOptionalStrings.
@Test
public void testAddOptionalStrings() {
handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"))));
handler.build();
TriplePath tp = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
ElementOptional opt = new ElementOptional(epb);
WhereValidator wv = new WhereValidator(opt);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.sparql.syntax.ElementOptional in project jena by apache.
the class WhereHandlerTest method testAddOptionalObjectsWithPath.
@Test
public void testAddOptionalObjectsWithPath() {
PrefixMapping pmap = new PrefixMappingImpl();
pmap.setNsPrefix("ts", "urn:test:");
Path path = PathParser.parse("ts:two/ts:dos", pmap);
handler.addOptional(new TriplePath(NodeFactory.createURI("one"), path, ResourceFactory.createLangLiteral("three", "en-US").asNode()));
handler.build();
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(NodeFactory.createURI("one"), path, ResourceFactory.createLangLiteral("three", "en-US").asNode());
epb.addTriplePath(tp);
WhereValidator visitor = new WhereValidator(optional);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementOptional 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.sparql.syntax.ElementOptional in project jena by apache.
the class ElementRewriter method visit.
@Override
public void visit(ElementOptional el) {
el.getOptionalElement().visit(this);
push(new ElementOptional(getResult()));
}
Aggregations