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);
}
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;
}
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();
}
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());
}
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)));
}
Aggregations