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; }
@Override protected boolean _contains(String varName) { return binding.contains(Var.alloc(varName)); }
public static void addVar(Collection<Var> acc, Node n) { if (n == null) return; if (n.isVariable()) acc.add(Var.alloc(n)); }
@Override protected RDFNode _get(String varName) { Node n = binding.get(Var.alloc(varName)); if (n == null) return null; return ModelUtils.convertGraphNodeToRDFNode(n, model); }