use of org.apache.jena.tdb2.solver.SolverLibTDB.convFromBinding 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);
}
Aggregations