Package com.hp.hpl.jena.sparql.engine.binding

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


        }
        return new TableData(vars, newRows) ;
    }
   
    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 ;
    }
View Full Code Here


        assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db)) ;
    }

    private Binding randomBinding(Var[] vars)
    {
        BindingMap binding = BindingFactory.create();
        binding.add(vars[0], NodeFactory.createAnon());
        binding.add(vars[1], NodeFactory.createURI(randomURI()));
        binding.add(vars[2], NodeFactory.createURI(randomURI()));
        binding.add(vars[3], NodeFactory.createLiteral(randomString(20)));
        binding.add(vars[4], NodeFactory.createAnon());
        binding.add(vars[5], NodeFactory.createURI(randomURI()));
        binding.add(vars[6], NodeFactory.createURI(randomURI()));
        binding.add(vars[7], NodeFactory.createLiteral(randomString(5)));
        binding.add(vars[8], NodeFactory.createLiteral("" + random.nextInt(), null, XSDDatatype.XSDinteger));
        binding.add(vars[9], NodeFactory.createAnon());
        return binding;
    }
View Full Code Here

      String value = row.get(condition);
      if (value == null || "false".equals(value) || "0".equals(value) || "".equals(value)) {
        return null;
      }
    }
    BindingMap result = new BindingHashMap();
    for (Var variableName: nodeMakers.keySet()) {
      Node node = nodeMakers.get(variableName).makeNode(row);
      if (node == null) {
        return null;
      }
      result.add(Var.alloc(variableName), node);
    }
    return result;
  }
View Full Code Here

    }
   
    @Override
    protected Binding assembleBinding(ResultSetJDBC rsHolder, Binding parent)
    {
        BindingMap b = BindingFactory.create(parent) ;
        ResultSet rs = rsHolder.get() ;
        for ( Var v : super.getProject() )
        {
            if ( ! v.isNamedVar() )
                // Skip bNodes and system variables
                continue ;

            String codename = super.getSqlName(v) ;
            if ( codename == null )
                // Not mentioned in query.
                continue ;
            try {
                int type        = rs.getInt(SQLUtils.gen(codename,"type")) ;
                // returns 0 on null : type 0 is not allocated
                // Test with "wasNull()" for safety
                if ( rs.wasNull() )
                    continue ;

                String lexColName = SQLUtils.gen(codename,"lex") ;
                // Get lexical - overriden by Oracle-specific code.
                String lex = getLexFromResultSet(rs, codename);
//                String lex = rs.getString(lexColName) ;
                if ( lex == null )
                    lex = "" ;
                String datatype = rs.getString(SQLUtils.gen(codename,"datatype")) ;
                String lang     = rs.getString(SQLUtils.gen(codename,"lang")) ;
                ValueType vType = ValueType.lookup(type) ;
                Node r          = makeNode(lex, datatype, lang, vType) ;
                b.add(v, r) ;
            } catch (SQLException ex)
            { // Unknown variable?
                //log.warn("Not reconstructed: "+n) ;
            }
        }
View Full Code Here

    }
   
    @Override
    protected Binding assembleBinding(ResultSetJDBC rs, Binding parent)
    {
        BindingMap b = BindingFactory.create(parent) ;
        for ( Var v : getProject() )
        {
            String sqlVarName = getSqlName(v) ;
           
            if ( sqlVarName == null )
                // Not mentioned in query.
                continue ;
            try {
                // because of encoding into SPARQL terms, this is never the empty string.
                String s = rs.get().getString(sqlVarName) ;
                // Same as rs.wasNull() for things that can return Java nulls.
                if ( s == null )
                    continue ;
                // TupleLoaderSimple used SqlConstant which made the string SQL-safe
                // so it could be embedded in a non-prepared statement. 
                s = SQLUtils.unescapeStr(s) ;
                Node n = codec.decode(s) ;
                b.add(v, n) ;
                // Ignore any access error (variable requested not in results)
            } catch (SQLException ex) {}
        }
        return b ;
    }
View Full Code Here

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

        Item head = list.get(0) ;
       
        if ( ! head.isSymbolIgnoreCase(Tags.tagRow) && ! head.isSymbolIgnoreCase(Tags.tagBinding) )
            BuilderLib.broken(list, "Does not start ("+Tags.tagRow+" ...) or ("+Tags.tagBinding+" ...)", head) ;
       
        BindingMap binding = BindingFactory.create() ;
        for ( int i = 1 ; i < list.size() ; i++ )
        {
            Item item = list.get(i) ;
            BuilderLib.checkList(item, "Attempt to build a binding pair from non-list: "+item) ;
            ItemList pair = item.getList() ;
            BuilderLib.checkLength(2, pair, "Need a pair for a binding") ;
           
            Var v = BuilderNode.buildVar(pair.get(0)) ;
            Item cdr = pair.get(1) ;
            // undef
            if ( cdr.isSymbolIgnoreCase(Tags.tagUndef) || cdr.isSymbolIgnoreCase(Tags.tagNull) )
                continue ;
           
            BuilderLib.checkNode(cdr) ;
            Node node = BuilderNode.buildNode(item.getList().get(1)) ;
            if ( node == null )
                BuilderLib.broken(item.getList().get(1), "Null node from "+item.getList().get(1)) ;
            if ( node.isVariable() )
                BuilderLib.broken(item.getList().get(1), "No variables as table values: "+FmtUtils.stringForNode(node)) ;
            if ( !node.isConcrete() )
                BuilderLib.broken(item.getList().get(1), "Ony concrete nodes as table values: "+FmtUtils.stringForNode(node)) ;
            binding.add(v, node) ;
        }
        return binding ;
    }
View Full Code Here

  }
     
     
    private static 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("Error Parsing CSV results - Unterminated quoted string");
                if ( idx < line.length() )
                {
                    ch = line.charAt(idx) ;
                    if ( ch != ',' )
                        throw new QueryException("Error Parsing CSV results - Expected comma after quote") ;
                }
            }
            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("Error Parsing CSV results - Number of items does not match number of variables: "+StrUtils.strjoin(",", terms)) ;
        for ( int i = 0 ; i < vars.size() ; i++ )
            binding.add(vars.get(i), Node.createLiteral(terms.get(i))) ;
        return binding ;
    }
View Full Code Here

    { super(PropFuncArgType.PF_ARG_SINGLE, PropFuncArgType.PF_ARG_SINGLE) ; }
   
    @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) ;
    }
View Full Code Here

       
        Node namespaceNode = argObject.getArg(0) ;
        Node localnameNode = argObject.getArg(1) ;
       
        // New binding to return.
        BindingMap b = null ;
        if ( Var.isVar(namespaceNode) || Var.isVar(localnameNode) )
            b = BindingFactory.create(binding) ;
       
        if ( Var.isVar(namespaceNode) ) // .isVariable() )
        {
            b.add(Var.alloc(namespaceNode), Node.createURI(namespace)) ;
            // Check for the case of (?x ?x) (very unlikely - and even more unlikely to cause a match)
            // but it's possible for strange URI schemes.
            if ( localnameNode.isVariable() && namespaceNode.getName() == localnameNode.getName() )
                localnameNode = Node.createURI(namespace) ;
        }
        else
        {
            String ns = null ;
            // Allow both IRIs and plain literals in the namespace position.
            if ( namespaceNode.isURI() )
                ns = namespaceNode.getURI() ;
            if ( namespaceNode.isLiteral() )
                ns = NodeUtils.stringLiteral(namespaceNode) ;
            if ( ns == null || ! ns.equals(namespace) )
                return IterLib.noResults(execCxt) ;
            // Fall through and proceed to localname
        }
       
        if ( Var.isVar(localnameNode) )
            b.add(Var.alloc(localnameNode), Node.createLiteral(localname)) ;
        else
        {
            // Only string literals (plain strings or datatype xsd:string)
            String lc = NodeUtils.stringLiteral(localnameNode) ;
            if ( lc == null || ! lc.equals(localname) )
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.sparql.engine.binding.BindingMap

Copyright © 2018 www.massapicom. 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.