use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class StageGeneratorGeneric method execute.
protected QueryIterator execute(BasicPattern pattern, ReorderTransformation reorder, StageGenerator execution, QueryIterator input, ExecutionContext execCxt) {
Explain.explain(pattern, execCxt.getContext());
if (!input.hasNext())
return input;
if (reorder != null && pattern.size() >= 2) {
// If pattern size is 0 or 1, nothing to do.
BasicPattern bgp2 = pattern;
// Try to ground the pattern
if (!input.isJoinIdentity()) {
QueryIterPeek peek = QueryIterPeek.create(input, execCxt);
// And now use this one
input = peek;
Binding b = peek.peek();
bgp2 = Substitute.substitute(pattern, b);
ReorderProc reorderProc = reorder.reorderIndexes(bgp2);
pattern = reorderProc.reorder(pattern);
}
}
Explain.explain("Reorder/generic", pattern, execCxt.getContext());
return QueryIterBlockTriples.create(input, pattern, execCxt);
}
use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class PathLib method pathToTriples.
/** Convert any paths of exactly one predicate to a triple pattern */
public static Op pathToTriples(PathBlock pattern) {
BasicPattern bp = null;
Op op = null;
for (TriplePath tp : pattern) {
if (tp.isTriple()) {
if (bp == null)
bp = new BasicPattern();
bp.add(tp.asTriple());
continue;
}
// Path form.
op = flush(bp, op);
bp = null;
OpPath opPath2 = new OpPath(tp);
op = OpSequence.create(op, opPath2);
continue;
}
// End. Finish off any outstanding BGP.
op = flush(bp, op);
return op;
}
use of org.apache.jena.sparql.core.BasicPattern 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.core.BasicPattern in project jena by apache.
the class TestReorder method stats_01.
@Test
public void stats_01() {
StatsMatcher m = matcher("((:x :p ANY) 5)");
ReorderTransformation transform = new ReorderWeighted(m);
BasicPattern bgp = bgp("(bgp)");
BasicPattern bgp2 = transform.reorder(bgp);
assertEquals(bgp2, bgp);
}
use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.
the class TestReorder method reorderIndexes2.
@Test
public void reorderIndexes2() {
ReorderProc proc = new ReorderProcIndexes(new int[] { 1, 0 });
BasicPattern bgp1 = bgp("(bgp (:x :p ?v) (:x :q ?w))");
BasicPattern bgp2 = bgp("(bgp (:x :q ?w) (:x :p ?v))");
BasicPattern bgp3 = proc.reorder(bgp1);
assertEquals(bgp2, bgp3);
}
Aggregations