Search in sources :

Example 11 with BindingMap

use of org.apache.jena.sparql.engine.binding.BindingMap in project jena by apache.

the class TestResultSet method make2.

private ResultSet make2(String var, Node val) {
    BindingMap b1 = BindingFactory.create();
    b1.add(Var.alloc(var), val);
    BindingMap b2 = BindingFactory.create();
    b2.add(Var.alloc(var), val);
    List<String> vars = new ArrayList<>();
    vars.add(var);
    List<Binding> solutions = new ArrayList<>();
    solutions.add(b1);
    solutions.add(b2);
    QueryIterator qIter = new QueryIterPlainWrapper(solutions.iterator(), null);
    ResultSet rs = new ResultSetStream(vars, null, qIter);
    return rs;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ArrayList(java.util.ArrayList) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 12 with BindingMap

use of org.apache.jena.sparql.engine.binding.BindingMap in project jena by apache.

the class SQLBridge2 method assembleBinding.

@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"));
            // 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) ;
        }
    }
    return b;
}
Also used : SQLException(java.sql.SQLException) Var(org.apache.jena.sparql.core.Var) SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode) Node(org.apache.jena.graph.Node) ResultSet(java.sql.ResultSet) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Example 13 with BindingMap

use of org.apache.jena.sparql.engine.binding.BindingMap in project jena by apache.

the class Thift2Binding method moveToNext.

@Override
protected Binding moveToNext() {
    try {
        row.read(protocol);
    } catch (TTransportException e) {
        return null;
    } catch (TException e) {
        TRDF.exception(e);
    }
    if (row.getRowSize() != vars.size())
        throw new RiotThriftException(String.format("Vars %d : Row length : %d", vars.size(), row.getRowSize()));
    BindingMap b = BindingFactory.create();
    for (int i = 0; i < vars.size(); i++) {
        // Old school
        Var v = vars.get(i);
        RDF_Term rt = row.getRow().get(i);
        if (rt.isSetUndefined())
            continue;
        Node n = ThriftConvert.convert(rt);
        b.add(v, n);
    }
    row.clear();
    return b;
}
Also used : TException(org.apache.thrift.TException) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TTransportException(org.apache.thrift.transport.TTransportException) RDF_Term(org.apache.jena.riot.thrift.wire.RDF_Term) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Example 14 with BindingMap

use of org.apache.jena.sparql.engine.binding.BindingMap in project jena by apache.

the class QueryIteratorMapped method moveToNextBinding.

@Override
protected Binding moveToNextBinding() {
    Binding b = super.moveToNextBinding();
    if (this.varMapping == null)
        return b;
    // Apply remapping
    BindingMap binding = BindingFactory.create();
    Iterator<Var> vs = b.vars();
    while (vs.hasNext()) {
        Var v = vs.next();
        Node value = b.get(v);
        // Only remap non-null variables for which there is a mapping
        if (value == null)
            continue;
        if (this.varMapping.containsKey(v)) {
            binding.add(this.varMapping.get(v), value);
        }
    }
    return binding;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Example 15 with BindingMap

use of org.apache.jena.sparql.engine.binding.BindingMap in project jena by apache.

the class RDFInput method buildBinding.

private Binding buildBinding(Resource soln) {
    // foreach row
    BindingMap rb = BindingFactory.create();
    StmtIterator bindingIter = soln.listProperties(ResultSetGraphVocab.binding);
    for (; bindingIter.hasNext(); ) {
        Resource binding = bindingIter.nextStatement().getResource();
        String var = binding.getRequiredProperty(ResultSetGraphVocab.variable).getString();
        try {
            RDFNode val = binding.getRequiredProperty(ResultSetGraphVocab.value).getObject();
            rb.add(Var.alloc(var), val.asNode());
        } catch (PropertyNotFoundException ex) {
            Log.warn(this, "Failed to get value for ?" + var);
        }
    // We include the value even if it is the marker term "rs:undefined"
    // if ( val.equals(ResultSetVocab.undefined))
    // continue ;
    // The ResultSetFormatter code equates null (not found) with
    // rs:undefined. When Jena JUnit testing, it does not matter if the
    // recorded result has the term absent or explicitly undefined.
    }
    bindingIter.close();
    return rb;
}
Also used : PropertyNotFoundException(org.apache.jena.shared.PropertyNotFoundException) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

Aggregations

BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)29 Node (org.apache.jena.graph.Node)18 Var (org.apache.jena.sparql.core.Var)12 Binding (org.apache.jena.sparql.engine.binding.Binding)10 ArrayList (java.util.ArrayList)8 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)5 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)4 ResultSet (org.apache.jena.query.ResultSet)3 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)3 SQLException (java.sql.SQLException)2 SqlNode (org.apache.jena.sdb.core.sqlnode.SqlNode)2 BuilderResultSet (org.apache.jena.sparql.sse.builders.BuilderResultSet)2 ResultSet (java.sql.ResultSet)1 List (java.util.List)1 Function (java.util.function.Function)1 CSVParser (org.apache.jena.atlas.csv.CSVParser)1 IteratorDelayedInitialization (org.apache.jena.atlas.iterator.IteratorDelayedInitialization)1 JsonArray (org.apache.jena.atlas.json.JsonArray)1 JsonObject (org.apache.jena.atlas.json.JsonObject)1 JsonValue (org.apache.jena.atlas.json.JsonValue)1