use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class LibSDB method findInQuads.
/** Match a quad pattern (not triples in the default graph) */
public static Iterator<Quad> findInQuads(DatasetGraph dsg, Node g, Node s, Node p, Node o) {
// If null, create and remember a variable, else use the node.
final Node vg = varOrConst(g, "g");
final Node vs = varOrConst(s, "s");
final Node vp = varOrConst(p, "p");
final Node vo = varOrConst(o, "o");
Triple triple = new Triple(vs, vp, vo);
// Evaluate as an algebra expression
BasicPattern pattern = new BasicPattern();
pattern.add(triple);
Op op = new OpQuadPattern(vg, pattern);
Plan plan = QueryEngineSDB.getFactory().create(op, dsg, BindingRoot.create(), null);
QueryIterator qIter = plan.iterator();
Iterator<Binding> iter;
if (SDB.getContext().isTrue(SDB.streamGraphAPI)) {
iter = qIter;
} else {
// ---- Safe version:
List<Binding> x = Iter.toList(qIter);
Iterator<Binding> qIter2 = x.iterator();
qIter.close();
iter = qIter2;
}
return Iter.map(iter, (b) -> bindingToQuad(vg, vs, vp, vo, b));
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class BindingTDB method calcVars.
private List<Var> calcVars() {
List<Var> vars = new ArrayList<>(4);
// Only if not in parent.
// A (var/value) binding may have been copied down to record it's NodeId.
Binding b = idBinding.getParentBinding();
Iterator<Var> iter = idBinding.iterator();
for (Var v : idBinding) {
if (b == null || !b.contains(v))
vars.add(v);
}
return vars;
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class TextQueryPF method resultsToQueryIterator.
private QueryIterator resultsToQueryIterator(Binding binding, Node s, Node score, Node literal, Collection<TextHit> results, ExecutionContext execCxt) {
Var sVar = Var.isVar(s) ? Var.alloc(s) : null;
Var scoreVar = (score == null) ? null : Var.alloc(score);
Var literalVar = (literal == null) ? null : Var.alloc(literal);
Function<TextHit, Binding> converter = (TextHit hit) -> {
if (score == null && literal == null)
return sVar != null ? BindingFactory.binding(binding, sVar, hit.getNode()) : BindingFactory.binding(binding);
BindingMap bmap = BindingFactory.create(binding);
if (sVar != null)
bmap.add(sVar, hit.getNode());
if (scoreVar != null)
bmap.add(scoreVar, NodeFactoryExtra.floatToNode(hit.getScore()));
if (literalVar != null)
bmap.add(literalVar, hit.getLiteral());
return bmap;
};
Iterator<Binding> bIter = Iter.map(results.iterator(), converter);
QueryIterator qIter = new QueryIterPlainWrapper(bIter, execCxt);
return qIter;
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class RDFInput method buildRowsOrdered.
private void buildRowsOrdered(Resource root, int count) {
Model m = root.getModel();
// Assume one result set per file.
for (int index = 1; ; index++) {
Literal ind = m.createTypedLiteral(index);
StmtIterator sIter = m.listStatements(null, ResultSetGraphVocab.index, ind);
if (!sIter.hasNext())
break;
Statement s = sIter.nextStatement();
if (sIter.hasNext())
Log.warn(this, "More than one solution: index = " + index);
Resource soln = s.getSubject();
Binding rb = buildBinding(soln);
rows.add(rb);
sIter.close();
}
if (rows.size() != count)
Log.warn(this, "Found " + rows.size() + ": expected " + count);
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class RDFInput method buildRows.
private void buildRows(Resource root) {
// Now the results themselves
int count = 0;
StmtIterator solnIter = root.listProperties(ResultSetGraphVocab.solution);
for (; solnIter.hasNext(); ) {
Resource soln = solnIter.nextStatement().getResource();
count++;
Binding rb = buildBinding(soln);
rows.add(rb);
}
solnIter.close();
if (root.hasProperty(ResultSetGraphVocab.size)) {
try {
int size = root.getRequiredProperty(ResultSetGraphVocab.size).getInt();
if (size != count)
Log.warn(this, "Warning: Declared size = " + size + " : Count = " + count);
} catch (JenaException rdfEx) {
}
}
}
Aggregations