use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class QueryExecutionBase method getPlan.
public Plan getPlan() {
if (plan == null) {
DatasetGraph dsg = prepareDataset(dataset, query);
Binding inputBinding = null;
if (initialBinding != null)
inputBinding = BindingUtils.asBinding(initialBinding);
if (inputBinding == null)
inputBinding = BindingRoot.create();
plan = qeFactory.create(query, dsg, inputBinding, getContext());
}
return plan;
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class TSVOutput method format.
@Override
public void format(OutputStream out, ResultSet resultSet) {
// Use a Turtle formatter to format terms
NodeFormatterTTL formatter = new NodeFormatterTTL(null, null);
AWriter w = IO.wrapUTF8(out);
String sep = null;
List<String> varNames = resultSet.getResultVars();
List<Var> vars = new ArrayList<>(varNames.size());
// writes the variables on the first line
for (String v : varNames) {
if (sep != null)
w.write(sep);
else
sep = SEP;
Var var = Var.alloc(v);
w.write(var.toString());
vars.add(var);
}
w.write(NL);
// writes one binding by line
for (; resultSet.hasNext(); ) {
sep = null;
Binding b = resultSet.nextBinding();
for (Var v : vars) {
if (sep != null)
w.write(sep);
sep = SEP;
Node n = b.get(v);
if (n != null) {
// This will not include a raw tab.
formatter.format(w, n);
}
}
w.write(NL);
}
w.flush();
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class QuerySerializer method outputDataBlock.
public static void outputDataBlock(IndentedWriter out, List<Var> variables, List<Binding> values, SerializationContext cxt) {
out.print("VALUES ");
if (variables.size() == 1) {
// Short form.
out.print("?");
out.print(variables.get(0).getVarName());
out.print(" {");
out.incIndent();
for (Binding valueRow : values) outputValuesOneRow(out, variables, valueRow, cxt);
out.decIndent();
out.print(" }");
return;
}
// Long form.
out.print("(");
for (Var v : variables) {
out.print(" ");
out.print(v.toString());
}
out.print(" )");
out.print(" {");
out.incIndent();
for (Binding valueRow : values) {
out.println();
out.print("(");
outputValuesOneRow(out, variables, valueRow, cxt);
out.print(" )");
}
out.decIndent();
out.ensureStartOfLine();
out.print("}");
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class ResultSetCompare method equivalentByOrder.
private static boolean equivalentByOrder(List<Binding> rows1, List<Binding> rows2, EqualityTest match) {
if (rows1.size() != rows2.size())
return false;
Iterator<Binding> iter1 = rows1.iterator();
Iterator<Binding> iter2 = rows2.iterator();
while (iter1.hasNext()) {
// Does not need backtracking because rows must
// align and so must variables in a row.
Binding row1 = iter1.next();
Binding row2 = iter2.next();
if (!equal(row1, row2, match))
return false;
}
return true;
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class ResultSetCompare method equivalent.
// static boolean equivalentByTerm(ResultSet rs1, ResultSet rs2)
// {
// return equivalent(convert(rs1), convert(rs2), sameTerm) ;
// }
private static boolean equivalent(Collection<Binding> rows1, Collection<Binding> rows2, EqualityTest match) {
if (rows1.size() != rows2.size())
return false;
for (Binding row1 : rows1) {
// find in rows2.
Binding matched = null;
for (Binding row2 : rows2) {
if (equal(row1, row2, match)) {
matched = row2;
break;
}
}
if (matched == null)
return false;
// Remove matching.
rows2.remove(matched);
}
return true;
}
Aggregations