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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations