use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereClauseTest method testAddOptionalStringWithPath.
@ContractTest
public void testAddOptionalStringWithPath() {
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addOptional("<one>", "<two>/<dos>", "three");
Path path = new P_Seq(new P_Link(NodeFactory.createURI("two")), new P_Link(NodeFactory.createURI("dos")));
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(NodeFactory.createURI("one"), path, NodeFactory.createLiteral("three"));
epb.addTriplePath(tp);
WhereValidator visitor = new WhereValidator(optional);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock 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.ElementPathBlock in project jena by apache.
the class WhereHandlerTest method testAddWhereStrings.
@Test
public void testAddWhereStrings() {
handler.addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"))));
handler.build();
ElementPathBlock epb = new ElementPathBlock();
TriplePath tp = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
epb.addTriplePath(tp);
WhereValidator visitor = new WhereValidator(epb);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereQuadHolder method addOptional.
/**
* Add an optional triple to the where clause
*
* @param t The triple path to add.
* @throws IllegalArgumentException If the triple is not a valid triple for a
* where clause.
*/
public void addOptional(TriplePath t) throws IllegalArgumentException {
testTriple(t);
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(t);
ElementOptional opt = new ElementOptional(epb);
getClause().addElement(opt);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereQuadHolder 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);
}
}
}
Aggregations