Search in sources :

Example 41 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class TransformMergeBGPs method merge.

private static BasicPattern merge(BasicPattern p1, BasicPattern p2) {
    if (p1 == null || p2 == null)
        return null;
    BasicPattern p = new BasicPattern();
    p.addAll(p1);
    p.addAll(p2);
    return p;
}
Also used : BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 42 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class TransformReorder method transform.

/**
	 * Transforms Quad Patterns with the reordering
	 */
@Override
public Op transform(OpQuadPattern opQuadPattern) {
    BasicPattern pattern = opQuadPattern.getBasicPattern();
    if (pattern.size() < 2)
        return opQuadPattern;
    BasicPattern pattern2 = reorder.reorder(pattern);
    return new OpQuadPattern(opQuadPattern.getGraphNode(), pattern2);
}
Also used : OpQuadPattern(org.apache.jena.sparql.algebra.op.OpQuadPattern) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 43 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class TransformFilterPlacementConservative method transformFilterQuadPattern.

private static Op transformFilterQuadPattern(ExprList exprs, Set<Var> patternVarsScope, Node graphNode, BasicPattern pattern) {
    // Any filters that depend on no variables.
    Op op = insertAnyFilter(exprs, patternVarsScope, null);
    if (Var.isVar(graphNode)) {
        // Add in the graph node of the quad block.
        // It's picked up after the first triple is processed.
        VarUtils.addVar(patternVarsScope, Var.alloc(graphNode));
    }
    for (Triple triple : pattern) {
        OpQuadPattern opQuad = getQuads(op);
        if (opQuad == null) {
            opQuad = new OpQuadPattern(graphNode, new BasicPattern());
            op = OpSequence.create(op, opQuad);
        }
        opQuad.getBasicPattern().add(triple);
        // Update variables in scope.
        VarUtils.addVarsFromTriple(patternVarsScope, triple);
        // Attempt to place any filters
        op = insertAnyFilter(exprs, patternVarsScope, op);
    }
    return op;
}
Also used : Triple(org.apache.jena.graph.Triple) Op(org.apache.jena.sparql.algebra.Op) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 44 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class TransformFilterPlacement method placeQuadPattern.

private static Placement placeQuadPattern(ExprList exprsIn, Node graphNode, BasicPattern pattern) {
    ExprList exprs = ExprList.copy(exprsIn);
    Set<Var> patternVarsScope = new HashSet<>();
    // Any filters that depend on no variables.
    Op op = insertAnyFilter$(exprs, patternVarsScope, null);
    if (Var.isVar(graphNode)) {
        // Add in the graph node of the quad block.
        VarUtils.addVar(patternVarsScope, Var.alloc(graphNode));
    }
    for (Triple triple : pattern) {
        OpQuadPattern opQuad = getQuads(op);
        if (opQuad == null) {
            opQuad = new OpQuadPattern(graphNode, new BasicPattern());
            op = OpSequence.create(op, opQuad);
        }
        opQuad.getBasicPattern().add(triple);
        // Update variables in scope.
        VarUtils.addVarsFromTriple(patternVarsScope, triple);
        op = insertAnyFilter$(exprs, patternVarsScope, op);
    }
    return result(op, exprs);
}
Also used : Triple(org.apache.jena.graph.Triple) Op(org.apache.jena.sparql.algebra.Op) ExprList(org.apache.jena.sparql.expr.ExprList) Var(org.apache.jena.sparql.core.Var) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

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