Search in sources :

Example 41 with Binding

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

the class BinRDF method writeResultSet.

public static void writeResultSet(TProtocol protocol, ResultSet resultSet, boolean encodeValues) {
    List<Var> vars = Var.varList(resultSet.getResultVars());
    try (Binding2Thrift b2t = new Binding2Thrift(protocol, vars, encodeValues)) {
        for (; resultSet.hasNext(); ) {
            Binding b = resultSet.nextBinding();
            b2t.output(b);
        }
    }
//Done by Binding2Thrift.close() -- LibThriftRDF.flush(protocol) ;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var)

Example 42 with Binding

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

the class EvaluatorSimple method filter.

@Override
public Table filter(ExprList expressions, Table table) {
    if (debug) {
        System.out.println("Restriction");
        System.out.println(expressions);
        dump(table);
    }
    QueryIterator iter = table.iterator(execCxt);
    List<Binding> output = new ArrayList<>();
    for (; iter.hasNext(); ) {
        Binding b = iter.nextBinding();
        if (expressions.isSatisfied(b, execCxt))
            output.add(b);
    }
    return new TableN(new QueryIterPlainWrapper(output.iterator(), execCxt));
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ArrayList(java.util.ArrayList) TableN(org.apache.jena.sparql.algebra.table.TableN)

Example 43 with Binding

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

the class EvaluatorSimple method minusWorker.

private Table minusWorker(Table tableLeft, Table tableRight) {
    // Minus(Ω1, Ω2) = { μ | μ in Ω1 such that for all μ' in Ω2, either μ and μ' are not compatible or dom(μ) and dom(μ') are disjoint }
    TableN results = new TableN();
    QueryIterator iterLeft = tableLeft.iterator(execCxt);
    for (; iterLeft.hasNext(); ) {
        Binding bindingLeft = iterLeft.nextBinding();
        boolean includeThisRow = true;
        // Find a reason not to include the row.
        // That's is not disjoint and not compatible.
        QueryIterator iterRight = tableRight.iterator(execCxt);
        for (; iterRight.hasNext(); ) {
            Binding bindingRight = iterRight.nextBinding();
            if (Algebra.disjoint(bindingLeft, bindingRight))
                // Disjoint - not a reason to exclude
                continue;
            if (!Algebra.compatible(bindingLeft, bindingRight))
                // Compatible - not a reason to exclude.
                continue;
            includeThisRow = false;
            break;
        }
        iterRight.close();
        if (includeThisRow)
            results.addBinding(bindingLeft);
    }
    iterLeft.close();
    return results;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) TableN(org.apache.jena.sparql.algebra.table.TableN)

Example 44 with Binding

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

the class OpExecutor method debug.

// Use this to debug evaluation
// Example:
// input = debug(input) ;
private QueryIterator debug(String marker, QueryIterator input) {
    List<Binding> x = all(input);
    for (Binding b : x) {
        System.out.print(marker);
        System.out.print(": ");
        System.out.println(b);
    }
    return new QueryIterPlainWrapper(x.iterator(), execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding)

Example 45 with Binding

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

the class EvaluatorSimple method diffWorker.

// @@ Abstract compatibility
private Table diffWorker(Table tableLeft, Table tableRight) {
    QueryIterator left = tableLeft.iterator(execCxt);
    TableN r = new TableN();
    for (; left.hasNext(); ) {
        Binding b = left.nextBinding();
        if (tableRight.contains(b))
            r.addBinding(b);
    }
    tableLeft.close();
    tableRight.close();
    return r;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) TableN(org.apache.jena.sparql.algebra.table.TableN)

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