Examples of BindingMap


Examples of com.hp.hpl.jena.sparql.engine.binding.BindingMap

    }
   
    @Override
    public Binding accept(Binding binding)
    {
        BindingMap b = BindingFactory.create(binding) ;
        for ( Var v : exprs.getVars() )
        {
            // Not this, where expressions do not see the new bindings.
            // Node n = exprs.get(v, bind, funcEnv) ;
            // which gives (Lisp) "let" semantics, not "let*" semantics
            Node n = exprs.get(v, b, getExecContext()) ;
           
            if ( n == null )
                // Expression failed to evaluate - no assignment
                continue ;
               
            // Check is already has a value; if so, must be sameValueAs
            if ( b.contains(v) )
            {
                if ( mustBeNewVar )
                    throw new QueryExecException("Already set: "+v) ;
               
                Node n2 = b.get(v) ;
                if ( ! n2.sameValueAs(n) )
                    //throw new QueryExecException("Already set: "+v) ;
                    // Error in single assignment.
                    return null ;
                continue ;
            }
            b.add(v, n) ;
        }
        return b ;
    }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.binding.BindingMap

                List<Binding> results = new ArrayList<Binding>() ;

                for ( Binding k : accumulators.keys() )
                {
                    Collection<Pair<Var, Accumulator>> accs = accumulators.get(k) ;
                    BindingMap b = BindingFactory.create(k) ;
                   
                    for ( Pair<Var, Accumulator> pair : accs )
                    {
                        Var v = pair.getLeft() ;
                        NodeValue value = pair.getRight().getValue() ;
                        Node n = (value==null) ? null : value.asNode() ;
                        if ( v == null || n == null )
                        {}
                        else
                            b.add(v, n) ;
                    }
                    results.add(b) ;
                }
                return results.iterator() ;
            }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.binding.BindingMap

   
    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 ;
    }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.binding.BindingMap

            } else {
              int num_tokens = tokens.length;
                  if ( num_tokens != vars.size() ) {
                     throw new ARQException(String.format("Line %d has %d values instead of %d.", line, num_tokens, vars.size()));
                  }
                  BindingMap binding = BindingFactory.create();
                  for ( int i = 0; i < tokens.length; i++ ) {
                    String token = tokens[i];
                    Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(token);
                    if ( tokenizer.hasNext() && token.length() > 0 ) {
                      Node node = tokenizer.next().asNode();
                      binding.add(vars.get(i), node);
                    }
                  }
                  bindings.add(binding);
            }
          }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.binding.BindingMap

        JsonArray array = results.get(kBindings).getAsArray() ;
        Iterator<JsonValue> iter = array.iterator() ;
       
        for ( ; iter.hasNext() ; )
        {
            BindingMap b = BindingFactory.create() ;
            JsonValue v = iter.next() ;
            if ( ! v.isObject() )
                throw new ResultSetException("Entry in 'bindings' array must be an object {}";
            JsonObject x = v.getAsObject() ;
            Set<String> varNames = x.keys() ;
            for ( String vn : varNames )
            {
                if ( ! vars.contains(vn) )
                    ; // Warning
                JsonValue vt = x.get(vn) ;
                if ( ! vt.isObject() )
                    throw new ResultSetException("Binding for variable '"+vn+"' is not a JSON object: "+vt;
                Node n = parseOneTerm(vt.getAsObject()) ;
                b.add(Var.alloc(vn), n) ;
            }
            rows.add(b) ;
        }
    }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.binding.BindingMap

    {
        List<Binding> bindings = new ArrayList<Binding>()  ;
        while(resultsActual.hasNext())
        {
            Binding b = resultsActual.nextBinding() ;
            BindingMap b2 = BindingFactory.create() ;
           
            for ( String vn : resultsActual.getResultVars() )
            {
                Var v = Var.alloc(vn) ;
                Node n = b.get(v) ;
                String s ;
                if ( n == null )
                    s = "" ;
                else if ( n.isBlank() )
                    s = "_:"+n.getBlankNodeLabel() ;
                else
                    s = NodeFunctions.str(n) ;
                b2.add(v, NodeFactory.createLiteral(s)) ;
            }
            bindings.add(b2) ;
        }
        ResultSet rs = new ResultSetStream(resultsActual.getResultVars(), null, new QueryIterPlainWrapper(bindings.iterator())) ;
        return ResultSetFactory.makeRewindable(rs) ;
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.binding.BindingMap

          return BasicPattern.wrap(triples);
        }
       
        private Binding mapper(Row r)
        {
            BindingMap results = BindingFactory.create(binding) ;

            if ( ! insert(pattern, r, results) )
                return null ;
            return results ;
        }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.binding.BindingMap

        if ( true )
            return new BindingTDB(bindingNodeIds, nodeTable) ;
        else
        {
            // Makes nodes immediately.  Causing unnecessary NodeTable accesses (e.g. project)
            BindingMap b = BindingFactory.create() ;
            for ( Var v : bindingNodeIds )
            {
                NodeId id = bindingNodeIds.get(v) ;
                Node n = nodeTable.getNodeForNodeId(id) ;
                b.add(v, n) ;
            }
            return b ;
        }
    }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.binding.BindingMap

  }
     
     
    private BindingMap parseLine(List<Var> vars, String line)
    {
        BindingMap binding = BindingFactory.create() ;
        List<String> terms = new ArrayList<String>() ;
        int idx = 0 ;
       
        while(idx < line.length())
        {
            char ch = line.charAt(idx) ;
           
            StringBuilder s = new StringBuilder() ;
            if ( ch == '\"' || ch == '\'' )
            {
                char qCh = ch ;
                idx++ ;
                while(idx < line.length() )
                {
                    ch = line.charAt(idx) ;
                    idx++ ;
                    if ( ch == qCh )
                        break ;
                    // escapes??
                    s.append(ch) ;
                }
                if ( ch != qCh )
                    throw new QueryException(String.format("Error Parsing CSV results at Line %d  - Unterminated quoted string", this.lineNum));
                if ( idx < line.length() )
                {
                    ch = line.charAt(idx) ;
                    if ( ch != ',' )
                        throw new QueryException(String.format("Error Parsing CSV results at Line %d - Expected comma after quote", this.lineNum)) ;
                }
            }
            else
            {
                while(idx < line.length() )
                {
                    ch = line.charAt(idx) ;
                    if ( ch == ',' )
                        break ;
                    idx++ ;
                    // escapes
                    s.append(ch) ;
                }
            }
           
            terms.add(s.toString()) ;
            // At end of per-term processing, we are looking at "," or EOL. 

            // Looking at , or EOL.
            if ( ch == ',' && idx==line.length()-1 )
            {
                //EOL
                terms.add("") ;
                break ;
            }
            // Skip ","
            idx++ ;
        }
       
        if ( terms.size() != vars.size() )
            throw new QueryException(String.format("Error Parsing CSV results at Line %d - The result row '%s' has %d items when %d was expected", this.lineNum, line, terms.size(), vars.size())) ;
        for ( int i = 0 ; i < vars.size() ; i++ )
            binding.add(vars.get(i), Node.createLiteral(terms.get(i))) ;
        return binding ;
    }
View Full Code Here

Examples of com.hp.hpl.jena.sparql.engine.binding.BindingMap

    { return ; }
   
    private Binding getOneSolution() throws XMLStreamException
    {
        // At the start of <result>
        BindingMap binding = BindingFactory.create() ;
        String varName = null ;
       
        while(parser.hasNext())
        {
            int event = parser.next();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.