Search in sources :

Example 21 with BasicPattern

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);
}
Also used : QueryIterPeek(org.apache.jena.sparql.engine.iterator.QueryIterPeek) Binding(org.apache.jena.sparql.engine.binding.Binding) ReorderProc(org.apache.jena.sparql.engine.optimizer.reorder.ReorderProc) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 22 with BasicPattern

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;
}
Also used : Op(org.apache.jena.sparql.algebra.Op) OpPath(org.apache.jena.sparql.algebra.op.OpPath) BasicPattern(org.apache.jena.sparql.core.BasicPattern) TriplePath(org.apache.jena.sparql.core.TriplePath)

Example 23 with BasicPattern

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;
}
Also used : ElementNamedGraph(org.apache.jena.sparql.syntax.ElementNamedGraph) Node(org.apache.jena.graph.Node) Element(org.apache.jena.sparql.syntax.Element) BasicPattern(org.apache.jena.sparql.core.BasicPattern) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock)

Example 24 with BasicPattern

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);
}
Also used : BasicPattern(org.apache.jena.sparql.core.BasicPattern) StatsMatcher(org.apache.jena.sparql.engine.optimizer.StatsMatcher) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 25 with BasicPattern

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);
}
Also used : BasicPattern(org.apache.jena.sparql.core.BasicPattern) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Aggregations

BasicPattern (org.apache.jena.sparql.core.BasicPattern)44 Node (org.apache.jena.graph.Node)15 Triple (org.apache.jena.graph.Triple)13 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)13 Op (org.apache.jena.sparql.algebra.Op)11 Test (org.junit.Test)11 Var (org.apache.jena.sparql.core.Var)5 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)5 Binding (org.apache.jena.sparql.engine.binding.Binding)5 ArrayList (java.util.ArrayList)4 BaseTest (org.apache.jena.atlas.junit.BaseTest)4 OpQuadPattern (org.apache.jena.sparql.algebra.op.OpQuadPattern)4 Quad (org.apache.jena.sparql.core.Quad)4 SocketException (java.net.SocketException)3 HashMap (java.util.HashMap)3 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)3 OpService (org.apache.jena.sparql.algebra.op.OpService)3 QueryExceptionHTTP (org.apache.jena.sparql.engine.http.QueryExceptionHTTP)3 Context (org.apache.jena.sparql.util.Context)3 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)2