Search in sources :

Example 61 with Binding

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;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 62 with Binding

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();
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) AWriter(org.apache.jena.atlas.io.AWriter) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) NodeFormatterTTL(org.apache.jena.riot.out.NodeFormatterTTL)

Example 63 with Binding

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("}");
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var)

Example 64 with Binding

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;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding)

Example 65 with Binding

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;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding)

Aggregations

Binding (org.apache.jena.sparql.engine.binding.Binding)132 Node (org.apache.jena.graph.Node)39 ArrayList (java.util.ArrayList)36 Var (org.apache.jena.sparql.core.Var)33 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)27 Test (org.junit.Test)21 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)16 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)10 BindingComparator (org.apache.jena.sparql.engine.binding.BindingComparator)8 BuilderBinding (org.apache.jena.sparql.sse.builders.BuilderBinding)8 NoSuchElementException (java.util.NoSuchElementException)7 Triple (org.apache.jena.graph.Triple)7 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)7 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)5 Op (org.apache.jena.sparql.algebra.Op)5 BasicPattern (org.apache.jena.sparql.core.BasicPattern)5 ResultSet (org.apache.jena.query.ResultSet)4 SortCondition (org.apache.jena.query.SortCondition)4 TableN (org.apache.jena.sparql.algebra.table.TableN)4 File (java.io.File)3