/** Return the value in the binding or the variable itself. */ public static Node lookup(Binding binding, Var var) { Node n = binding.get(var); if ( n != null ) return n; return var; }
@Override public Node get(Var var) { return binding.get(var) ; }
@Override public boolean containsCompatibleWithSharedDomain(Binding binding) { Node value = binding.get(this.var); if ( value == null ) // No shared domain. return false; return this.values.contains(value); }
private Key convertToKey(Binding binding) { Node[] indexKey = new Node[varColumns.size()] ; for ( Map.Entry<Var,Integer> varCol : varColumns.entrySet() ) { Node value = binding.get(varCol.getKey()) ; if ( value == null ) missingValue = true ; indexKey[varCol.getValue()] = value ; } return new Key(indexKey) ; }
@Override protected Node get1(Var var) { if ( !accept(var) ) return null ; return binding.get(var) ; }
/** Return the object bound to a name, or null */ @Override final public Node get(Var var) { Node node = get1(var); if ( node != null ) return node; if ( parent == null ) return null; return parent.get(var); }
public static void addAll(BindingMap dest, Binding src) { Iterator<Var> iter = src.vars(); for ( ; iter.hasNext() ; ) { Var v = iter.next(); Node n = src.get(v); dest.add(v, n); } }
@Override protected Node getNode(String columnLabel) throws SQLException { if (this.isClosed()) throw new SQLException("Result Set is closed"); if (this.getCurrentRow() == null) throw new SQLException("Not currently at a row"); if (!this.columns.contains(columnLabel)) throw new SQLException("The given column does not exist in the result set"); return this.getCurrentRow().get(Var.alloc(columnLabel)); }
private static Node substitute(Node node, Binding binding) { if ( Var.isVar(node) ) { Node x = binding.get(Var.alloc(node)) ; if ( x != null ) return x ; } return node ; }
@Override protected Node getNode(String columnLabel) throws SQLException { if (this.isClosed()) throw new SQLException("Result Set is closed"); if (this.getCurrentRow() == null) throw new SQLException("Not currently at a row"); if (!this.columns.contains(columnLabel)) throw new SQLException("The given column does not exist in the result set"); return this.getCurrentRow().get(Var.alloc(columnLabel)); }
public static int hashCode(Binding bind) { int hash = 0xC0; for ( Iterator<Var> iter = bind.vars() ; iter.hasNext() ; ) { Var var = iter.next(); Node node = bind.get(var); hash ^= var.hashCode(); hash ^= node.hashCode(); } return hash; }
@Override protected RDFNode _get(String varName) { Node n = binding.get(Var.alloc(varName)) ; if ( n == null ) return null; return ModelUtils.convertGraphNodeToRDFNode(n, model) ; }
/** Bound value or null */ private static Node resolve(Binding b, Node n) { if ( ! n.isVariable() ) return n ; return b.get(Var.alloc(n)) ; }
private Triple resolveTriple(final Triple t, final Binding values) { int idx = variables.indexOf(t.getSubject()); final Node s = idx == -1 ? t.getSubject() : values.get(Var .alloc(variables.get(idx))); idx = variables.indexOf(t.getPredicate()); final Node p = idx == -1 ? t.getPredicate() : values.get(Var .alloc(variables.get(idx))); idx = variables.indexOf(t.getObject()); final Node o = idx == -1 ? t.getObject() : values.get(Var .alloc(variables.get(idx))); return new Triple(s, p, o); }
static NodeValue eval(Var v, Binding binding, FunctionEnv env) { if ( binding == null ) throw new VariableNotBoundException("Not bound: (no binding): "+v) ; Node nv = binding.get(v) ; if ( nv == null ) throw new VariableNotBoundException("Not bound: variable "+v) ; // Wrap as a NodeValue. return NodeValue.makeNode(nv) ; }
private static Node value(PropFuncArg arg, Binding b) { Node x = arg.getArg() ; if ( !Var.isVar(x) ) return x ; return b.get(Var.alloc(x)) ; } }
public static Binding transform(Binding b, NodeTransform transform) { BindingMap b2 = BindingFactory.create() ; List<Var> vars = Iter.toList(b.vars()) ; for ( Var v : vars ) { Var v2 = (Var)transform.apply(v) ; b2.add(v2, b.get(v)); } return b2 ; }
@Override public Expr copySubstitute(Binding binding) { Var v = varNode ; if ( binding == null || !binding.contains(v) ) return new ExprVar(v) ; Node v2 = binding.get(v); return v2.isVariable() ? new ExprVar(v2) : eval(binding, null) ; }
@Test public void path_38() { // Same end points. List<Binding> x = eval(graph6, "?x", "(pathN+ :p)", "?x" ) ; assertEquals(2, x.size()) ; Node node1 = x.get(0).get(Var.alloc("x")) ; Node node2 = x.get(1).get(Var.alloc("x")) ; assertFalse(node1.equals(node2)) ; assertTrue(node1.equals(n1) || node1.equals(n2)) ; assertTrue(node2.equals(n1) || node2.equals(n2)) ; }
@Test public void path_37() { List<Binding> x = eval(graph6, "?x", "(path* :p)", "?x" ) ; assertEquals(2, x.size()) ; Node node1 = x.get(0).get(Var.alloc("x")) ; Node node2 = x.get(1).get(Var.alloc("x")) ; assertFalse(node1.equals(node2)) ; assertTrue(node1.equals(n1) || node1.equals(n2)) ; assertTrue(node2.equals(n1) || node2.equals(n2)) ; }