@Override public void bind(Expr exp, Expr var, Node value) { bind.bind(exp, var, value); }
@Override public Node get(Expr var) { return bind.get(var); }
@Override public boolean hasBind() { return bind != null && bind.hasBind(); }
/** * TODO: remove duplicates in getVariables() * use case: * function us:fun(?x){let (select ?x where {}) {}} * variable ?x appears twice in the stack because it is redefined in the let clause */ public static Mapping create(Query q, Binder b) { ArrayList<Node> lvar = new ArrayList(); ArrayList<Node> lval = new ArrayList(); for (Expr var : b.getVariables()) { Node node = q.getProperAndSubSelectNode(var.getLabel()); if (node != null && !lvar.contains(node)) { lvar.add(node); lval.add(b.get(var)); } } Mapping m = Mapping.create(lvar, lval); return m; }
void share(Mapping m) { if (m != null && m.getBind() != null) { if (memory.getBind() != null) { memory.getBind().share(m.getBind()); } if (m.getBind().getVisitor() != null) { // use case: let (?g = construct where) // see Interpreter exist() getMapping() setVisitor(m.getBind().getVisitor()); } } }
void share(ProcessVisitor vis) { if (vis.isShareable() && getMemory().getBind().getVisitor() == null) { getMemory().getBind().setVisitor(vis); } }
@Override public void unset(Expr exp, Expr var, Node value) { bind.unset(exp, var, value); }
@Override public void set(Expr exp, Expr var, Node value) { bind.set(exp, var, value); }
public void share(Binder target, Binder source) { if (source != null && target != null) { target.share(source); } }
/** * Is one node of subquery select already bound in memory ? */ private boolean isBound(Query subQuery, Memory env) { Query qq = query; for (Node subNode : subQuery.getSelect()) { if (env.isBound(subNode)){ return true; } // get outer node: Node outNode = qq.getOuterNodeSelf(subNode); if (outNode != null && env.isBound(outNode)) { return true; } if (env.getBind() != null && env.getBind().isBound(subNode.getLabel())){ return true; } } return false; }
/** * Copy this Bind local variable stack into this memory Use case: function * xt:foo(?x) { exists { ?x ex:pp ?y } } */ void copy(Binder bind, Exp exp) { List<Node> list = exp.getNodes(); for (Expr var : bind.getVariables()) { Node qn = getNode(var.getLabel(), list); if (qn == null) { } else { push(qn, bind.get(var)); } } }
@Override public void unset(Expr exp, List<Expr> lvar) { bind.unset(exp, lvar); }
@Override public void set(Expr exp, List<Expr> lvar, Node[] value) { bind.set(exp, lvar, value); }
@Override public void unset(Expr exp, List<Expr> lvar) { getCreateBind().unset(exp, lvar); }
@Override public void set(Expr exp, Expr var, Node value) { getCreateBind().set(exp, var, value); }
@Override public Node get(Expr var) { return getCreateBind().get(var); }
@Override public boolean hasBind() { return bind != null && bind.hasBind(); }
@Override public void bind(Expr exp, Expr var, Node value) { getCreateBind().bind(exp, var, value); }
@Override public void unset(Expr exp, Expr var, Node value) { getCreateBind().unset(exp, var, value); }
@Override public void set(Expr exp, List<Expr> lvar, Node[] value) { getCreateBind().set(exp, lvar, value); }