use of org.apache.jena.sparql.core.Var in project jena by apache.
the class SolverLib method graphNames.
/** Find all the graph names in the quads table. */
public static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
List<Abortable> killList = new ArrayList<>();
Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
if (filter != null)
iter1 = Iter.filter(iter1, filter);
Iterator<NodeId> iter2 = Iter.map(iter1, (t) -> t.get(0));
iter2 = makeAbortable(iter2, killList);
Iterator<NodeId> iter3 = Iter.distinct(iter2);
iter3 = makeAbortable(iter3, killList);
Iterator<Node> iter4 = NodeLib.nodes(ds.getQuadTable().getNodeTupleTable().getNodeTable(), iter3);
final Var var = Var.alloc(graphNode);
Iterator<Binding> iterBinding = Iter.map(iter4, node -> BindingFactory.binding(var, node));
// Not abortable.
return new QueryIterTDB(iterBinding, killList, input, execCxt);
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class BindingNodeId method putAll.
public void putAll(BindingNodeId other) {
Iterator<Var> vIter = other.iterator();
for (; vIter.hasNext(); ) {
Var v = vIter.next();
if (v == null)
throw new IllegalArgumentException("Null key");
NodeId n = other.get(v);
if (n == null)
throw new IllegalArgumentException("(" + v + "," + n + ")");
super.put(v, n);
}
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class BinRDF method writeResultSet.
public static void writeResultSet(TProtocol protocol, ResultSet resultSet, boolean encodeValues) {
List<Var> vars = Var.varList(resultSet.getResultVars());
try (Binding2Thrift b2t = new Binding2Thrift(protocol, vars, encodeValues)) {
for (; resultSet.hasNext(); ) {
Binding b = resultSet.nextBinding();
b2t.output(b);
}
}
//Done by Binding2Thrift.close() -- LibThriftRDF.flush(protocol) ;
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class Binding2Thrift method output.
public void output(Binding binding) {
Iterator<Var> vIter = (vars == null ? null : vars.iterator());
if (vIter == null)
vIter = binding.vars();
// }) ;
while (vIter.hasNext()) {
Var v = vIter.next();
Node n = binding.get(v);
RDF_Term rt = (n == null) ? TRDF.tUNDEF : ThriftConvert.convert(n, encodeValues);
row.addToRow(rt);
}
try {
row.write(protocol);
} catch (TException e) {
TRDF.exception(e);
}
row.clear();
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class Eval method evalGraph.
static Table evalGraph(OpGraph opGraph, Evaluator evaluator) {
ExecutionContext execCxt = evaluator.getExecContext();
if (!Var.isVar(opGraph.getNode())) {
DatasetGraph dsg = execCxt.getDataset();
Node graphNode = opGraph.getNode();
if (!dsg.containsGraph(graphNode))
return new TableEmpty();
Graph graph = execCxt.getDataset().getGraph(opGraph.getNode());
if (// But contains was true?!!
graph == null)
throw new InternalErrorException("Graph was present, now it's not");
ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
Evaluator e2 = EvaluatorFactory.create(execCxt2);
return eval(e2, opGraph.getSubOp());
}
// Graph node is a variable.
Var gVar = Var.alloc(opGraph.getNode());
Table current = null;
for (Iterator<Node> iter = execCxt.getDataset().listGraphNodes(); iter.hasNext(); ) {
Node gn = iter.next();
Graph graph = execCxt.getDataset().getGraph(gn);
ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
Evaluator e2 = EvaluatorFactory.create(execCxt2);
Table tableVarURI = TableFactory.create(gVar, gn);
// Evaluate the pattern, join with this graph node possibility.
// XXX If Var.ANON then no-opt.
Table patternTable = eval(e2, opGraph.getSubOp());
Table stepResult = evaluator.join(patternTable, tableVarURI);
if (current == null)
current = stepResult;
else
current = evaluator.union(current, stepResult);
}
if (current == null)
// Nothing to loop over
return new TableEmpty();
return current;
}
Aggregations