use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class StageGeneratorDirectTDB method execute.
@Override
public QueryIterator execute(BasicPattern pattern, QueryIterator input, ExecutionContext execCxt) {
// --- In case this isn't for TDB
Graph g = execCxt.getActiveGraph();
if (!(g instanceof GraphTDB))
// Not us - bounce up the StageGenerator chain
return above.execute(pattern, input, execCxt);
GraphTDB graph = (GraphTDB) g;
Predicate<Tuple<NodeId>> filter = QC2.getFilter(execCxt.getContext());
return PatternMatchTDB1.execute(graph, pattern, input, filter, execCxt);
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class SolverRX method find.
private static Iterator<BindingNodeId> find(BindingNodeId bnid, NodeTupleTable nodeTupleTable, Node xGraphNode, Triple xPattern, boolean anyGraph, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
NodeTable nodeTable = nodeTupleTable.getNodeTable();
Binding input = bnid.isEmpty() ? BindingFactory.empty() : new BindingTDB(bnid, nodeTable);
Triple tPattern = Substitute.substitute(xPattern, input);
Node graphNode = Substitute.substitute(xGraphNode, input);
Node tGraphNode = anyGraph ? Quad.unionGraph : graphNode;
// graphNode is ANY for union graph and null for default graph.
// Var to ANY, Triple Term to ANY.
Node g = (graphNode == null) ? null : nodeTopLevel(graphNode);
Node s = nodeTopLevel(tPattern.getSubject());
Node p = nodeTopLevel(tPattern.getPredicate());
Node o = nodeTopLevel(tPattern.getObject());
Tuple<Node> patternTuple = (g == null) ? TupleFactory.create3(s, p, o) : TupleFactory.create4(g, s, p, o);
Iterator<Quad> dsgIter = accessData(patternTuple, nodeTupleTable, anyGraph, filter, execCxt);
Iterator<Binding> matched = Iter.iter(dsgIter).map(dQuad -> SolverRX4.matchQuad(input, dQuad, tGraphNode, tPattern)).removeNulls();
return convFromBinding(matched, nodeTable);
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class ProcIndexCopy method tupleIndexCopy.
private static void tupleIndexCopy(TupleIndex index1, TupleIndex index2, String label) {
ProgressMonitor monitor = ProgressMonitorOutput.create(log, label, tickQuantum, superTick);
Timer timer = new Timer();
timer.startTimer();
monitor.start();
Iterator<Tuple<NodeId>> iter1 = index1.all();
long counter = 0;
for (; iter1.hasNext(); ) {
counter++;
Tuple<NodeId> tuple = iter1.next();
index2.add(tuple);
monitor.tick();
}
index2.sync();
monitor.finish();
long time = timer.endTimer();
float elapsedSecs = time / 1000F;
float rate = (elapsedSecs != 0) ? counter / elapsedSecs : 0;
print("Total: %,d records : %,.2f seconds : %,.2f records/sec [%s]", counter, elapsedSecs, rate, DateTimeUtils.nowAsString());
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class TupleIndex method scan.
public static Iterator<Tuple<NodeId>> scan(Iterator<Tuple<NodeId>> iter, Tuple<NodeId> pattern) {
int tupleLength = pattern.len();
Predicate<Tuple<NodeId>> filter = new Predicate<Tuple<NodeId>>() {
@Override
public boolean test(Tuple<NodeId> item) {
// Check on pattern and item (both in natural order)
for (int i = 0; i < tupleLength; i++) {
NodeId n = pattern.get(i);
// The pattern must be null/Any or match the tuple being tested.
if (!NodeId.isAny(n))
if (!item.get(i).equals(n))
return false;
}
return true;
}
};
return Iter.filter(iter, filter);
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class GraphTDB method graphBaseSize.
@Override
protected final int graphBaseSize() {
if (isDefaultGraph())
return (int) getNodeTupleTable().size();
Node gn = getGraphName();
boolean unionGraph = isUnionGraph(gn);
gn = unionGraph ? Node.ANY : gn;
QuadTable quadTable = getDatasetGraphTDB().getQuadTable();
Iterator<Tuple<NodeId>> iter = quadTable.getNodeTupleTable().findAsNodeIds(gn, null, null, null);
if (unionGraph) {
iter = Iter.map(iter, project4TupleTo3Tuple);
iter = Iter.distinctAdjacent(iter);
}
return (int) Iter.count(iter);
}
Aggregations