use of org.apache.jena.sparql.core.TriplePath in project jena by apache.
the class WhereHandlerTest method testAddWhereAnonymous.
@Test
public void testAddWhereAnonymous() {
handler.addWhere(new TriplePath(new Triple(Node.ANY, RDF.first.asNode(), Node.ANY)));
assertContainsRegex(WHERE + OPEN_CURLY + "ANY" + SPACE + uri("http://www\\.w3\\.org/1999/02/22-rdf-syntax-ns#first") + SPACE + "ANY" + OPT_SPACE + CLOSE_CURLY, query.toString());
}
use of org.apache.jena.sparql.core.TriplePath in project jena by apache.
the class WhereHandlerTest method testAddOptionalWhereHandler.
@Test
public void testAddOptionalWhereHandler() throws ParseException {
WhereHandler pattern = new WhereHandler(new Query());
Var s = Var.alloc("s");
Node q = NodeFactory.createURI("urn:q");
Node v = NodeFactory.createURI("urn:v");
Var x = Var.alloc("x");
Node n123 = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(123));
pattern.addWhere(new TriplePath(new Triple(s, q, n123)));
pattern.addWhere(new TriplePath(new Triple(s, v, x)));
pattern.addFilter("?x>56");
handler.addOptional(pattern);
Query expected = QueryFactory.create("SELECT * WHERE { OPTIONAL { ?s <urn:q> '123'^^<http://www.w3.org/2001/XMLSchema#int> . ?s <urn:v> ?x . FILTER(?x>56) }}");
Assert.assertEquals(expected.getQueryPattern(), query.getQueryPattern());
}
use of org.apache.jena.sparql.core.TriplePath in project jena by apache.
the class WhereHandlerTest method testAddUnionToExistingWithVar.
@Test
public void testAddUnionToExistingWithVar() {
handler.addWhere(new TriplePath(new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o"))));
SelectBuilder sb = new SelectBuilder().addVar("x").addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
handler.addUnion(sb);
assertContainsRegex(WHERE + OPEN_CURLY + OPEN_CURLY + uri("s") + SPACE + uri("p") + SPACE + uri("o") + CLOSE_CURLY + OPT_SPACE + UNION + OPEN_CURLY + SELECT + var("x") + SPACE + WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY, query.toString());
}
use of org.apache.jena.sparql.core.TriplePath 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);
assertContainsRegex(WHERE + OPEN_CURLY + OPEN_CURLY + uri("s") + SPACE + uri("p") + SPACE + uri("o") + CLOSE_CURLY + OPT_SPACE + UNION + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
}
use of org.apache.jena.sparql.core.TriplePath in project jena by apache.
the class FormatterElement method visit.
@Override
public void visit(ElementPathBlock el) {
// Write path block - don't put in a final trailing "."
if (el.isEmpty()) {
out.println("# Empty BGP");
return;
}
// Split into BGP-path-BGP-...
// where the BGPs may be empty.
PathBlock pBlk = el.getPattern();
BasicPattern bgp = new BasicPattern();
// Has anything been output?
boolean first = true;
for (TriplePath tp : pBlk) {
if (tp.isTriple()) {
bgp.add(tp.asTriple());
continue;
}
if (!bgp.isEmpty()) {
if (!first)
out.println(" .");
flush(bgp);
first = false;
}
if (!first)
out.println(" .");
// Path
printSubject(tp.getSubject());
out.print(" ");
PathWriter.write(out, tp.getPath(), context.getPrologue());
out.print(" ");
printObject(tp.getObject());
first = false;
}
// Flush any stored triple patterns.
if (!bgp.isEmpty()) {
if (!first)
out.println(" .");
flush(bgp);
first = false;
}
}
Aggregations