use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class version method execEvaluated.
@Override
public QueryIterator execEvaluated(Binding binding, PropFuncArg subject, Node predicate, PropFuncArg object, ExecutionContext execCxt) {
List<Binding> results = new ArrayList<>();
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;
BindingBuilder builder = Binding.builder(binding);
if (subj.isVariable())
builder.add(Var.alloc(subj), info.getIRI());
if (subj.isVariable())
builder.add(Var.alloc(obj), version);
results.add(builder.build());
}
return QueryIterPlainWrapper.create(results.iterator(), execCxt);
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class CSVInputIterator method parseLine.
private Binding parseLine(List<Var> vars, String line) {
BindingBuilder rowBuilder = Binding.builder();
List<String> terms = new ArrayList<>();
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());
// 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++) rowBuilder.add(vars.get(i), NodeFactory.createLiteral(terms.get(i)));
return rowBuilder.build();
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class RDFInput method buildRowsOrdered.
private void buildRowsOrdered(Resource root, int count) {
Model m = root.getModel();
BindingBuilder builder = Binding.builder();
// Assume one result set per file.
for (int index = 1; ; index++) {
Literal ind = m.createTypedLiteral(index, XSDDatatype.XSDinteger);
StmtIterator sIter = m.listStatements(null, ResultSetGraphVocab.index, ind);
if (!sIter.hasNext())
break;
Statement s = sIter.nextStatement();
if (sIter.hasNext())
Log.warn(this, "More than one solution: index = " + index);
Resource soln = s.getSubject();
Binding rb = buildBinding(builder, soln);
rows.add(rb);
sIter.close();
}
if (rows.size() != count)
Log.warn(this, "Found " + rows.size() + ": expected " + count);
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class RDFInput method buildRows.
private void buildRows(Resource root) {
// Now the results themselves
int count = 0;
StmtIterator solnIter = root.listProperties(ResultSetGraphVocab.solution);
BindingBuilder builder = Binding.builder();
for (; solnIter.hasNext(); ) {
Resource soln = solnIter.nextStatement().getResource();
count++;
Binding rb = buildBinding(builder, soln);
rows.add(rb);
}
solnIter.close();
if (root.hasProperty(ResultSetGraphVocab.size)) {
try {
int size = root.getRequiredProperty(ResultSetGraphVocab.size).getInt();
if (size != count)
Log.warn(this, "Warning: Declared size = " + size + " : Count = " + count);
} catch (JenaException rdfEx) {
}
}
}
use of org.apache.jena.sparql.engine.binding.BindingBuilder in project jena by apache.
the class versionARQ method execEvaluated.
@Override
public QueryIterator execEvaluated(Binding binding, PropFuncArg subject, Node predicate, PropFuncArg object, ExecutionContext execCxt) {
BindingBuilder builder = Binding.builder(binding);
Node subj = subject.getArg();
if (!isSameOrVar(subj, arq))
IterLib.noResults(execCxt);
if (subj.isVariable())
builder.add(Var.alloc(subj), arq);
Node obj = object.getArg();
if (!isSameOrVar(obj, version))
IterLib.noResults(execCxt);
if (obj.isVariable())
builder.add(Var.alloc(obj), version);
return IterLib.result(builder.build(), execCxt);
}
Aggregations