Search in sources :

Example 46 with Binding

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

the class BuilderResultSet method build.

public static ResultSet build(Item item) {
    BuilderLib.checkTagged(item, Tags.tagResultSet, "Not a (resultset ...)");
    ItemList list = item.getList();
    List<Var> vars = BuilderNode.buildVarList(list.get(1));
    // skip tag, skip vars.
    int start = 2;
    List<Binding> bindings = new ArrayList<>();
    for (int i = start; i < list.size(); i++) {
        Item itemRow = list.get(i);
        Binding b = BuilderBinding.build(itemRow);
        bindings.add(b);
    }
    QueryIterator qIter = new QueryIterPlainWrapper(bindings.listIterator());
    return new ResultSetStream(Var.varNames(vars), null, qIter);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Item(org.apache.jena.sparql.sse.Item) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Var(org.apache.jena.sparql.core.Var) ItemList(org.apache.jena.sparql.sse.ItemList) ArrayList(java.util.ArrayList) ResultSetStream(org.apache.jena.sparql.engine.ResultSetStream)

Example 47 with Binding

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

the class BuilderTable method build.

public static Table build(Item item) {
    BuilderLib.checkTagged(item, Tags.tagTable, "Not a (table ...)");
    ItemList list = item.getList();
    int start = 1;
    if (list.size() == 1)
        // Null table;
        return TableFactory.createEmpty();
    // Maybe vars.
    List<Var> vars = null;
    if (list.size() > 1) {
        Item item0 = list.get(1);
        if (item0.isTagged(Tags.tagVars)) {
            vars = BuilderNode.buildVarList(item0);
            list = list.cdr();
        }
    }
    if (list.size() == 2 && list.get(1).isSymbol()) {
        //  Short hand for well known tables
        String symbol = list.get(1).getSymbol();
        if (symbol.equals("unit"))
            return TableFactory.createUnit();
        if (symbol.equals("empty"))
            return TableFactory.createEmpty();
        BuilderLib.broken(list, "Don't recognized table symbol");
    }
    Table table = TableFactory.create(vars);
    int count = 0;
    Binding lastBinding = null;
    for (int i = start; i < list.size(); i++) {
        Item itemRow = list.get(i);
        Binding b = BuilderBinding.build(itemRow);
        table.addBinding(b);
        lastBinding = b;
        count++;
    }
    if (table.size() == 1) {
        // One row, no bindings.
        if (lastBinding.isEmpty())
            return TableFactory.createUnit();
    }
    return table;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Item(org.apache.jena.sparql.sse.Item) Table(org.apache.jena.sparql.algebra.Table) Var(org.apache.jena.sparql.core.Var) ItemList(org.apache.jena.sparql.sse.ItemList)

Example 48 with Binding

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

the class WriterTable method outputPlain.

public static void outputPlain(IndentedWriter out, Table table, SerializationContext sCxt) {
    QueryIterator qIter = table.iterator(null);
    for (; qIter.hasNext(); ) {
        Binding b = qIter.nextBinding();
        output(out, b, sCxt);
        out.println();
    }
    qIter.close();
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 49 with Binding

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

the class TestSpecialGraphs method union_dft_1.

private void union_dft_1(Mode mode) {
    Op op = op("(bgp (?s ?p ?o))", mode);
    List<Binding> results = exec(op);
    assertEquals(5, results.size());
    Op op2 = Algebra.unionDefaultGraph(op);
    List<Binding> results2 = exec(op2);
    assertEquals(4, results2.size());
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op)

Example 50 with Binding

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

the class TestIndexTable method testTableData.

private void testTableData(IndexTable index) {
    // positive test for matching
    for (Binding b : fData) assertTrue(index.containsCompatibleWithSharedDomain(b));
    assertTrue(index.containsCompatibleWithSharedDomain(binding("abcd", 10, 11, 12, 13)));
    assertTrue(index.containsCompatibleWithSharedDomain(binding("ab", 10, 11)));
    assertTrue(index.containsCompatibleWithSharedDomain(binding("bc", 11, 12)));
    assertTrue(index.containsCompatibleWithSharedDomain(binding("ac", 10, 12)));
    assertTrue(index.containsCompatibleWithSharedDomain(binding("a", 10)));
    assertTrue(index.containsCompatibleWithSharedDomain(binding("ab", 70, 71)));
    assertTrue(index.containsCompatibleWithSharedDomain(binding("bc", 71, 72)));
    assertTrue(index.containsCompatibleWithSharedDomain(binding("ac", 70, 72)));
    // a=70 won't match for partData
    assertTrue(index.containsCompatibleWithSharedDomain(binding("a", 80)));
    // negative test for matching
    assertFalse(index.containsCompatibleWithSharedDomain(binding("abc", 10, 11, 11)));
    assertFalse(index.containsCompatibleWithSharedDomain(binding("d", 10)));
    assertFalse(index.containsCompatibleWithSharedDomain(binding("abc", 10, 21, 32)));
    assertFalse(index.containsCompatibleWithSharedDomain(binding("xyz", 10, 11, 12)));
}
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