Search in sources :

Example 71 with Binding

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

the class ValuesHandlerTest method twoVarTwoBlocks.

@Test
public void twoVarTwoBlocks() {
    Node n = NodeFactory.createLiteral("hello");
    Node nn = NodeFactory.createLiteral("hola");
    Node n2 = NodeFactory.createLiteral("there");
    Node nn2 = NodeFactory.createLiteral("aqui");
    Var v = Var.alloc("x");
    Var v2 = Var.alloc("y");
    handler.addValueVar(v, null);
    handler.addValueVar(v2, null);
    handler.addValueRow(Arrays.asList(n, n2));
    handler.addValueRow(Arrays.asList(nn, nn2));
    handler.build();
    List<Var> vars = query.getValuesVariables();
    assertEquals(2, vars.size());
    assertTrue(vars.contains(v));
    assertTrue(vars.contains(v2));
    assertNotNull(query.getValuesData());
    List<Binding> lb = query.getValuesData();
    assertEquals(2, lb.size());
    List<Node> ln = new ArrayList<Node>();
    ln.add(n);
    ln.add(nn);
    List<Node> ln2 = new ArrayList<Node>();
    ln2.add(n2);
    ln2.add(nn2);
    for (Binding b : lb) {
        assertTrue(b.contains(v));
        assertTrue(ln.contains(b.get(v)));
        ln.remove(b.get(v));
        assertTrue(b.contains(v2));
        assertTrue(ln2.contains(b.get(v2)));
        ln2.remove(b.get(v2));
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 72 with Binding

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

the class ResultSetStream method nextSolution.

/** Moves onto the next result possibility.
     *  The returned object is actual the binding for this
     *  result.
     */
@Override
public QuerySolution nextSolution() {
    if (queryExecutionIter == null)
        //             ( queryExecution != null && ! queryExecution.isActive() ) )
        throw new NoSuchElementException(this.getClass() + ".next");
    Binding binding = nextBinding();
    currentQuerySolution = new ResultBinding(model, binding);
    return currentQuerySolution;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ResultBinding(org.apache.jena.sparql.core.ResultBinding) NoSuchElementException(java.util.NoSuchElementException) ResultBinding(org.apache.jena.sparql.core.ResultBinding)

Example 73 with Binding

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

the class QueryIter2LoopOnLeft method hasNextBinding.

@Override
protected final boolean hasNextBinding() {
    if (slot != null)
        return true;
    while (getLeft().hasNext()) {
        Binding bindingLeft = getLeft().nextBinding();
        slot = getNextSlot(bindingLeft);
        if (slot != null) {
            slot = bindingLeft;
            return true;
        }
    }
    getLeft().close();
    return false;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding)

Example 74 with Binding

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

the class QueryIterProcessBinding method moveToNextBinding.

/**
     * The next acceptable object in the iterator.
     * 
     * @return The next acceptable object.
     */
@Override
public Binding moveToNextBinding() {
    if (hasNext()) {
        Binding r = nextBinding;
        nextBinding = null;
        return r;
    }
    throw new NoSuchElementException();
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) NoSuchElementException(java.util.NoSuchElementException)

Example 75 with Binding

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

the class QueryIterProcessBinding method hasNextBinding.

/**
     * Are there any more acceptable objects.
     * 
     * @return true if there is another acceptable object.
     */
@Override
protected boolean hasNextBinding() {
    // Needs to be idempotent.?
    if (isFinished())
        return false;
    if (nextBinding != null)
        return true;
    // Null iterator.
    if (getInput() == null)
        throw new ARQInternalErrorException(Lib.className(this) + ": Null iterator");
    while (getInput().hasNext()) {
        // Skip forward until a binding to return is found.
        Binding input = getInput().nextBinding();
        Binding output = accept(input);
        if (output != null) {
            nextBinding = output;
            return true;
        }
    }
    nextBinding = null;
    return false;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

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