use of org.apache.jena.tdb2.store.NodeId in project jena by apache.
the class tdbstats method stats$.
private static StatsResults stats$(DatasetGraphTDB dsg, Node gn) {
NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable();
StatsCollectorNodeId stats = new StatsCollectorNodeId(nt);
if (gn == null) {
Iterator<Tuple<NodeId>> iter = dsg.getTripleTable().getNodeTupleTable().findAll();
for (; iter.hasNext(); ) {
Tuple<NodeId> t = iter.next();
stats.record(null, t.get(0), t.get(1), t.get(2));
}
} else {
// If the union graph, then we need to scan all quads but with uniqueness.
boolean unionGraph = Quad.isUnionGraph(gn);
NodeId gnid = null;
if (!unionGraph) {
gnid = nt.getNodeIdForNode(gn);
if (NodeId.isDoesNotExist(gnid))
Log.warn(tdbstats.class, "No such graph: " + gn);
}
NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable();
Iterator<Tuple<NodeId>> iter = unionGraph ? SolverLibTDB.unionGraph(ntt) : ntt.find(gnid, null, null, null);
for (; iter.hasNext(); ) {
Tuple<NodeId> t = iter.next();
stats.record(t.get(0), t.get(1), t.get(2), t.get(3));
}
}
return stats.results();
}
use of org.apache.jena.tdb2.store.NodeId in project jena by apache.
the class PatternMatchTDB2 method execute.
// The worker. Callers choose the NodeTupleTable.
// graphNode may be Node.ANY, meaning we should make triples unique.
// graphNode may be null, meaning default graph
private static QueryIterator execute(NodeTupleTable nodeTupleTable, Node graphNode, BasicPattern pattern, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
if (Quad.isUnionGraph(graphNode))
graphNode = Node.ANY;
if (Quad.isDefaultGraph(graphNode))
graphNode = null;
List<Triple> triples = pattern.getList();
boolean anyGraph = (graphNode == null ? false : (Node.ANY.equals(graphNode)));
int tupleLen = nodeTupleTable.getTupleTable().getTupleLen();
if (graphNode == null) {
if (3 != tupleLen)
throw new TDBException("SolverLib: Null graph node but tuples are of length " + tupleLen);
} else {
if (4 != tupleLen)
throw new TDBException("SolverLib: Graph node specified but tuples are of length " + tupleLen);
}
// Convert from a QueryIterator (Bindings of Var/Node) to BindingNodeId
NodeTable nodeTable = nodeTupleTable.getNodeTable();
Iterator<BindingNodeId> chain = Iter.map(input, SolverLibTDB.convFromBinding(nodeTable));
List<Abortable> killList = new ArrayList<>();
for (Triple triple : triples) {
Tuple<Node> patternTuple = null;
if (graphNode == null)
// 3-tuples
patternTuple = TupleFactory.create3(triple.getSubject(), triple.getPredicate(), triple.getObject());
else
// 4-tuples.
patternTuple = TupleFactory.create4(graphNode, triple.getSubject(), triple.getPredicate(), triple.getObject());
// Plain RDF, no RDF-star
// chain = solve(nodeTupleTable, tuple, anyGraph, chain, filter, execCxt)
// ;
// RDF-star SA
chain = matchQuadPattern(chain, graphNode, triple, nodeTupleTable, patternTuple, anyGraph, filter, execCxt);
chain = makeAbortable(chain, killList);
}
Iterator<Binding> iterBinding = SolverLibTDB.convertToNodes(chain, nodeTable);
// "killList" will be aborted on timeout.
return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
use of org.apache.jena.tdb2.store.NodeId 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.tdb2.store.NodeId 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.tdb2.store.NodeId in project jena by apache.
the class StageMatchTuple method prepare.
/**
* Prepare a pattern (tuple of nodes), and an existing binding of NodeId, into
* NodeIds and Variables. A variable in the pattern is replaced by its binding or
* null in the NodeIds. A variable that is not bound by the binding is placed in
* the var array. Return false if preparation detects the pattern can not match.
*/
private static boolean prepare(NodeTable nodeTable, Tuple<Node> patternTuple, BindingNodeId input, NodeId[] ids, Var[] var) {
// we wish to abort if an unknown node is seen.
for (int i = 0; i < patternTuple.len(); i++) {
Node n = patternTuple.get(i);
// Substitution and turning into NodeIds
// Variables unsubstituted are null NodeIds
NodeId nId = idFor(nodeTable, input, n);
if (NodeId.isDoesNotExist(nId))
return false;
ids[i] = nId;
if (nId == null)
var[i] = asVar(n);
}
return true;
}
Aggregations