use of org.apache.jena.sparql.sse.ItemList in project jena by apache.
the class Stats method addTypeTriple.
private static void addTypeTriple(ItemList statsList, Node type, Node intCount) {
ItemList triple = new ItemList();
triple.add("VAR");
triple.add(NodeConst.nodeRDFType);
triple.add(type);
addPair(statsList, Item.createList(triple), Item.createNode(intCount));
}
use of org.apache.jena.sparql.sse.ItemList in project jena by apache.
the class StatsMatcher method init.
private void init(Item stats) {
if (!stats.isTagged(STATS))
throw new ARQException("Not a tagged '" + STATS + "'");
// Skip tag
ItemList list = stats.getList().cdr();
if (list.car().isTagged(META)) {
// Process the meta tag.
Item elt1 = list.car();
// Move list on
list = list.cdr();
// Get count.
Item x = Item.find(elt1.getList(), COUNT);
if (x != null)
count = x.getList().get(1).asInteger();
}
while (!list.isEmpty()) {
Item elt = list.car();
list = list.cdr();
onePattern(elt);
}
}
use of org.apache.jena.sparql.sse.ItemList 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.sse.ItemList 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.sse.ItemList in project jena by apache.
the class BuilderExpr method buildNamedExpr.
private static void buildNamedExpr(Item item, VarExprList varExprList) {
if (item.isNode()) {
Var v = BuilderNode.buildVar(item);
varExprList.add(v);
return;
}
if (!item.isList() || item.getList().size() != 2)
BuilderLib.broken(item, "Not a var or var/expression pair");
ItemList list = item.getList();
if (list.size() == 1) {
Var v = BuilderNode.buildVar(list.car());
varExprList.add(v);
return;
}
if (list.size() != 2)
BuilderLib.broken(list, "Not a var or var/expression pair");
Var var = BuilderNode.buildVar(list.get(0));
Expr expr = BuilderExpr.buildExpr(list.get(1));
varExprList.add(var, expr);
}
Aggregations