Search in sources :

Example 1 with OpQuadPattern

use of org.apache.jena.sparql.algebra.op.OpQuadPattern in project jena by apache.

the class tdbreorder method main.

public static void main(String... args) {
    if (args.length != 2) {
        System.err.println("Usage: PATTERN STATS");
        System.exit(1);
    }
    LogCtl.enable(StatsMatcher.class);
    LogCtl.enable(ReorderTransformationSubstitution.class);
    if (args.length != 2) {
        System.err.println("Usage: op stats");
        System.exit(1);
    }
    String pattern = args[0];
    String statsFile = args[1];
    Op op = SSE.readOp(pattern);
    BasicPattern bgp;
    if (op instanceof OpQuadPattern) {
        bgp = ((OpQuadPattern) op).getBasicPattern();
    } else if (op instanceof OpBGP) {
        bgp = ((OpBGP) op).getPattern();
    } else {
        System.err.println("Not a quad or triple pattern");
        System.exit(2);
        bgp = null;
    }
    ReorderTransformation reorder = chooseReorder(statsFile);
    // ReorderTransformation reorder = ReorderLib.fixed() ;
    BasicPattern bgp2 = reorder.reorder(bgp);
    System.out.println();
    print(bgp);
    System.out.println();
    System.out.println(" ======== >>>>>>>>");
    print(bgp2);
    System.out.println();
}
Also used : Op(org.apache.jena.sparql.algebra.Op) OpQuadPattern(org.apache.jena.sparql.algebra.op.OpQuadPattern) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 2 with OpQuadPattern

use of org.apache.jena.sparql.algebra.op.OpQuadPattern in project jena by apache.

the class LibSDB method findTriples.

/** Find triples, in the default graph or a named graph. */
public static Iterator<Triple> findTriples(DatasetGraph dsg, Node g, Node s, Node p, Node o) {
    if (Var.isVar(g))
        throw new InternalErrorException("Graph node is a variable : " + g);
    final Node vs = varOrConst(s, "s");
    final Node vp = varOrConst(p, "p");
    final Node vo = varOrConst(o, "o");
    // Evaluate as an algebra expression
    Triple triple = new Triple(vs, vp, vo);
    BasicPattern pattern = new BasicPattern();
    pattern.add(triple);
    Op op = (g != null) ? new OpQuadPattern(g, pattern) : new OpBGP(pattern);
    Plan plan = QueryEngineSDB.getFactory().create(op, dsg, BindingRoot.create(), null);
    QueryIterator qIter = plan.iterator();
    Iterator<Binding> iter;
    if (SDB.getContext().isTrue(SDB.streamGraphAPI)) {
        // Assumes iterator closed properly.
        iter = qIter;
    } else {
        // ---- Safe version: 
        List<Binding> x = Iter.toList(qIter);
        Iterator<Binding> qIter2 = x.iterator();
        qIter.close();
        iter = qIter2;
    }
    return Iter.map(iter, (b) -> bindingToTriple(vs, vp, vo, b));
}
Also used : Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op) OpQuadPattern(org.apache.jena.sparql.algebra.op.OpQuadPattern) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) BasicPattern(org.apache.jena.sparql.core.BasicPattern) Plan(org.apache.jena.sparql.engine.Plan)

Example 3 with OpQuadPattern

use of org.apache.jena.sparql.algebra.op.OpQuadPattern in project jena by apache.

the class LibSDB method findInQuads.

/** Match a quad pattern (not triples in the default graph) */
public static Iterator<Quad> findInQuads(DatasetGraph dsg, Node g, Node s, Node p, Node o) {
    // If null, create and remember a variable, else use the node.
    final Node vg = varOrConst(g, "g");
    final Node vs = varOrConst(s, "s");
    final Node vp = varOrConst(p, "p");
    final Node vo = varOrConst(o, "o");
    Triple triple = new Triple(vs, vp, vo);
    // Evaluate as an algebra expression
    BasicPattern pattern = new BasicPattern();
    pattern.add(triple);
    Op op = new OpQuadPattern(vg, pattern);
    Plan plan = QueryEngineSDB.getFactory().create(op, dsg, BindingRoot.create(), null);
    QueryIterator qIter = plan.iterator();
    Iterator<Binding> iter;
    if (SDB.getContext().isTrue(SDB.streamGraphAPI)) {
        iter = qIter;
    } else {
        // ---- Safe version: 
        List<Binding> x = Iter.toList(qIter);
        Iterator<Binding> qIter2 = x.iterator();
        qIter.close();
        iter = qIter2;
    }
    return Iter.map(iter, (b) -> bindingToQuad(vg, vs, vp, vo, b));
}
Also used : Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op) OpQuadPattern(org.apache.jena.sparql.algebra.op.OpQuadPattern) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) BasicPattern(org.apache.jena.sparql.core.BasicPattern) Plan(org.apache.jena.sparql.engine.Plan)

Example 4 with OpQuadPattern

use of org.apache.jena.sparql.algebra.op.OpQuadPattern 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)

Aggregations

OpQuadPattern (org.apache.jena.sparql.algebra.op.OpQuadPattern)4 BasicPattern (org.apache.jena.sparql.core.BasicPattern)4 Op (org.apache.jena.sparql.algebra.Op)3 Node (org.apache.jena.graph.Node)2 Triple (org.apache.jena.graph.Triple)2 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)2 Plan (org.apache.jena.sparql.engine.Plan)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)1 ReorderTransformation (org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation)1