use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class SolverRX method matchQuadPattern.
// Entry point from SolverLib.
/*package*/
static Iterator<BindingNodeId> matchQuadPattern(Iterator<BindingNodeId> chain, Node graphNode, Triple tPattern, NodeTupleTable nodeTupleTable, Tuple<Node> patternTuple, boolean anyGraph, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
if (DATAPATH) {
if (!tripleHasEmbTripleWithVars(tPattern))
// No RDF-star <<>> with variables.
return StageMatchTuple.access(nodeTupleTable, chain, patternTuple, filter, anyGraph, execCxt);
}
// RDF-star <<>> with variables.
// This path should work regardless.
boolean isTriple = (patternTuple.len() == 3);
NodeTable nodeTable = nodeTupleTable.getNodeTable();
Function<BindingNodeId, Iterator<BindingNodeId>> step = bnid -> find(bnid, nodeTupleTable, graphNode, tPattern, anyGraph, filter, execCxt);
return Iter.flatMap(chain, step);
}
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 IsoMatcher method tuplesQuads.
private static List<Tuple<Node>> tuplesQuads(Iterator<Quad> iter) {
List<Tuple<Node>> tuples = new ArrayList<>();
for (; iter.hasNext(); ) {
Quad q = iter.next();
Tuple<Node> tuple = tuple(q.getGraph(), q.getSubject(), q.getPredicate(), q.getObject());
tuples.add(tuple);
}
return tuples;
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class DatasetPrefixesTDB method loadPrefixMapping.
@Override
public synchronized void loadPrefixMapping(String graphName, PrefixMapping pmap) {
Node g = NodeFactory.createURI(graphName);
Iterator<Tuple<Node>> iter = nodeTupleTable.find(g, null, null);
for (; iter.hasNext(); ) {
Tuple<Node> t = iter.next();
String prefix = t.get(1).getLiteralLexicalForm();
String uri = t.get(2).getURI();
pmap.setNsPrefix(prefix, uri);
}
Iter.close(iter);
}
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 = ProgressMonitor.create(log, label, tickQuantum, superTick);
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();
long time = monitor.finish();
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());
}
Aggregations