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();
}
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));
}
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));
}
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);
}
Aggregations