protected void emitDataBlockValue(Node n, int line, int col) { currentColumn++ ; if ( currentColumn >= variables.size() ) // Exception will be thrown later when we have the complete row count. return ; Var v = variables.get(currentColumn) ; if ( n != null ) currentValueRow().add(v, n) ; }
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) ; } }
static private Binding copyProject(VarExprList vars, Binding binding, ExecutionContext execCxt) { // No group vars (implicit or explicit) => working on whole result set. // Still need a BindingMap to assign to later. BindingMap x = BindingFactory.create() ; for ( Iterator<Var> iter = vars.getVars().iterator() ; iter.hasNext() ; ) { Var var = iter.next() ; Node node = vars.get(var, binding, execCxt) ; // Null returned for unbound and error. if ( node != null ) x.add(var, node) ; } return x ; } }
/** Create a new Binding as a copy of an existing one. * Additionally, it guarantees to touch each element of the binding */ public static Binding materialize(Binding b) { Iterator<Var> vIter = b.vars() ; BindingMap b2 = create() ; while( vIter.hasNext() ) { Var v = vIter.next(); b2.add(v, b.get(v)) ; } return b2 ; } }
private static QueryIterator findIndexMember(Graph graph, Binding binding, Node listNode, Var varIndex, Var varMember, ExecutionContext execCxt) { // Iterate over list List<Node> members = GraphList.members(new GNode(graph, listNode)) ; List<Binding> bindings = new ArrayList<Binding>() ; for ( int i = 0 ; i < members.size() ; i++ ) { Node idx = NodeFactoryExtra.intToNode(i) ; Node member = members.get(i) ; BindingMap b = BindingFactory.create(binding) ; b.add(varIndex, idx) ; b.add(varMember, member) ; bindings.add(b) ; } return new QueryIterPlainWrapper(bindings.iterator(), execCxt) ; } }
private Binding copyToBinding(QuerySolution qs) { BindingMap b = BindingFactory.create() ; for ( Iterator<String> iter = qs.varNames() ; iter.hasNext() ; ) { String varName = iter.next() ; RDFNode rn = qs.get(varName) ; b.add(Var.alloc(varName), rn.asNode()) ; } return b ; }
private boolean parseNextBinding() { String line; try { line = this.reader.readLine(); //Once EOF has been reached we'll see null for this call so we can return false because there are no further bindings if (line == null) return false; this.lineNum++; } catch (IOException e) { throw new QueryException("Error parsing CSV results - " + e.getMessage()); } if ( line.isEmpty() ) { // Empty input line - no bindings. // Only valid when we expect zero/one values as otherwise we should get a sequence of tab characters // which means a non-empty string which we handle normally if (expectedItems > 1) throw new QueryException(String.format("Error Parsing CSV results at Line %d - The result row had 0/1 values when %d were expected", this.lineNum, expectedItems)); binding = BindingFactory.create() ; if ( expectedItems == 1 ) binding.add(vars.get(0), NodeConst.emptyString) ; return true ; } binding = parseLine(vars, line) ; return true ; }
private Binding copyToBinding(QuerySolution qs) { BindingMap b = new BindingMap() ; for ( Iterator<String> iter = qs.varNames() ; iter.hasNext() ; ) { String varName = iter.next() ; RDFNode rn = qs.get(varName) ; b.add(Var.alloc(varName), rn.asNode()) ; } return b ; }
private static Table buildTable(Map<Var, Set<NodeValue>> possibleValues) { if (possibleValues.size() == 0) return TableFactory.createEmpty(); Table table = TableFactory.create(); // Although each filter condition must apply for a row to be accepted // they are actually independent since only one condition needs to fail // for the filter to reject the row. Thus for each unique variable/value // combination a single row must be produced for (Var v : possibleValues.keySet()) { for (NodeValue value : possibleValues.get(v)) { BindingMap b = BindingFactory.create(); b.add(v, value.asNode()); table.addBinding(b); } } return table; } }
public static Binding merge(Binding bindingLeft, Binding bindingRight) { // Test to see if compatible: Iterate over variables in left boolean matches = compatible(bindingLeft, bindingRight) ; if ( ! matches ) return null ; // If compatible, merge. Iterate over variables in right but not in left. BindingMap b = BindingFactory.create(bindingLeft) ; for ( Iterator<Var> vIter = bindingRight.vars() ; vIter.hasNext() ; ) { Var v = vIter.next(); Node n = bindingRight.get(v) ; if ( ! bindingLeft.contains(v) ) b.add(v, n) ; } return b ; }
static protected void addBinding(BindingMap binding, Var var, Node value) { Node n = binding.get(var) ; if ( n != null ) { // Same - silently skip. if ( n.equals(value) ) return ; Log.warn(SPARQLResult.class, String.format("Multiple occurences of a binding for variable '%s' with different values - ignored", var.getName())) ; return ; } binding.add(var, value) ; }
private static boolean insert(Node inputNode, Node outputNode, BindingMap results) { if ( ! Var.isVar(inputNode) ) return true ; Var v = Var.alloc(inputNode) ; Node x = results.get(v) ; if ( x != null ) return outputNode.equals(x) ; results.add(v, outputNode) ; return true ; }
public static void addToBinding(BindingMap binding, QuerySolution qSolution) { if ( qSolution == null ) return ; for ( Iterator<String> iter = qSolution.varNames() ; iter.hasNext() ; ) { String n = iter.next() ; RDFNode x = qSolution.get(n) ; if ( Var.isBlankNodeVarName(n) ) continue ; try { binding.add(Var.alloc(n), x.asNode()) ; } catch (ARQInternalErrorException ex) { // bad binding attempt. Log.warn(BindingUtils.class, "Attempt to bind " + n + " when already bound") ; } } }
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.convert(v) ; b2.add(v2, b.get(v)); } return b2 ; }
/** Merge two bindings, assuming they are compatible. */ public static Binding merge(Binding bind1, Binding bind2) { //Create binding from LHS BindingMap b2 = BindingFactory.create(bind1) ; Iterator<Var> vIter = bind2.vars() ; // Add any variables from the RHS for ( ; vIter.hasNext() ; ) { Var v = vIter.next() ; if ( ! b2.contains(v) ) b2.add(v, bind2.get(v)) ; else { // Checking! Node n1 = bind1.get(v) ; Node n2 = bind2.get(v) ; if ( ! n1.equals(n2) ) Log.warn(BindingUtils.class, "merge: Mismatch : "+n1+" != "+n2); } } return b2 ; }
@Override public QueryIterator execEvaluated(Binding binding, PropFuncArg subject, Node predicate, PropFuncArg object, ExecutionContext execCxt) { List<Binding> results = new ArrayList<Binding>() ; Node subj = subject.getArg() ; Node obj = object.getArg() ; Iterator<SystemInfo> iter = SystemARQ.registeredSubsystems() ; for ( ; iter.hasNext() ; ) { SystemInfo info = iter.next(); if ( ! isSameOrVar(subj, info.getIRI()) ) continue ; Node version = NodeFactory.createLiteral(info.getVersion()) ; if ( ! isSameOrVar(obj, version) ) continue ; BindingMap b = BindingFactory.create(binding) ; if ( subj.isVariable() ) b.add(Var.alloc(subj), info.getIRI()) ; if ( subj.isVariable() ) b.add(Var.alloc(obj), version) ; results.add(b) ; } return new QueryIterPlainWrapper(results.iterator(), execCxt) ; }
@Override public QueryIterator execEvaluated(Binding binding, PropFuncArg subject, Node predicate, PropFuncArg object, ExecutionContext execCxt) { BindingMap b = BindingFactory.create(binding) ; Node subj = subject.getArg() ; if ( ! isSameOrVar(subj, arq) ) IterLib.noResults(execCxt) ; if ( subj.isVariable() ) b.add(Var.alloc(subj), arq) ; Node obj = object.getArg() ; if ( ! isSameOrVar(obj, version) ) IterLib.noResults(execCxt) ; if ( obj.isVariable() ) b.add(Var.alloc(obj), version) ; return IterLib.result(b, execCxt) ; }
public Binding convert(Binding b) { if ( parentBinding == null || parentBinding.isEmpty() ) return b ; // This is the result. Could have BindingBase.setParent etc. BindingMap b2 = new BindingMap(parentBinding) ; // Copy the resultSet bindings to the combined result binding with checking. for ( Iterator<Var> iter = b.vars() ; iter.hasNext(); ) { Var v = iter.next(); Node n = b.get(v) ; if ( b2.contains(v) ) { Node n2 = b2.get(v) ; if ( n2.equals(n) ) Log.warn(this, "Binding already for "+v+" (same value)" ) ; else { Log.fatal(this, "Binding already for "+v+" (different values)" ) ; throw new ARQInternalErrorException("QueryIteratorResultSet: Incompatible bindings for "+v) ; } } b2.add(v, n) ; } return b2 ; } }
@Override public Binding convert(Binding b) { if ( parentBinding == null || parentBinding.isEmpty() ) return b ; // This is the result. Could have BindingBase.setParent etc. BindingMap b2 = BindingFactory.create(parentBinding) ; // Copy the resultSet bindings to the combined result binding with checking. for ( Iterator<Var> iter = b.vars() ; iter.hasNext(); ) { Var v = iter.next(); Node n = b.get(v) ; if ( b2.contains(v) ) { Node n2 = b2.get(v) ; if ( n2.equals(n) ) Log.warn(this, "Binding already for "+v+" (same value)" ) ; else { Log.fatal(this, "Binding already for "+v+" (different values)" ) ; throw new ARQInternalErrorException("Incompatible bindings for "+v) ; } } b2.add(v, n) ; } return b2 ; } }
continue ; b.add(v, n) ;