use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class ARQParserBase method createQueryPattern.
protected ElementGroup createQueryPattern(Template t) {
ElementGroup elg = new ElementGroup();
Map<Node, BasicPattern> graphs = t.getGraphPattern();
for (Node n : graphs.keySet()) {
Element el = new ElementPathBlock(graphs.get(n));
if (!Quad.defaultGraphNodeGenerated.equals(n)) {
ElementGroup e = new ElementGroup();
e.addElement(el);
el = new ElementNamedGraph(n, e);
}
elg.addElement(el);
}
return elg;
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereHandler method addWhere.
/**
* Add the triple path to the where clause
*
* @param t The triple path to add.
* @throws IllegalArgumentException If the triple path is not a valid triple
* path for a where clause.
*/
public void addWhere(TriplePath t) throws IllegalArgumentException {
testTriple(t);
ElementGroup eg = getClause();
List<Element> lst = eg.getElements();
if (lst.isEmpty()) {
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(t);
eg.addElement(epb);
} else {
Element e = lst.get(lst.size() - 1);
if (e instanceof ElementTriplesBlock && t.isTriple()) {
ElementTriplesBlock etb = (ElementTriplesBlock) e;
etb.addTriple(t.asTriple());
} else if (e instanceof ElementPathBlock) {
ElementPathBlock epb = (ElementPathBlock) e;
epb.addTriple(t);
} else {
ElementPathBlock etb = new ElementPathBlock();
etb.addTriple(t);
eg.addElement(etb);
}
}
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class AskBuilderTest method testList.
@Test
public void testList() {
builder.addWhere(builder.list("<one>", "?two", "'three'"), "<foo>", "<bar>");
Query query = builder.build();
Node one = NodeFactory.createURI("one");
Node two = Var.alloc("two").asNode();
Node three = NodeFactory.createLiteral("three");
Node foo = NodeFactory.createURI("foo");
Node bar = NodeFactory.createURI("bar");
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())));
epb.addTriplePath(new TriplePath(new Triple(firstObject, foo, bar)));
WhereValidator visitor = new WhereValidator(epb);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations