Search in sources :

Example 1 with ItemList

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));
}
Also used : ItemList(org.apache.jena.sparql.sse.ItemList)

Example 2 with ItemList

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);
    }
}
Also used : Item(org.apache.jena.sparql.sse.Item) ARQException(org.apache.jena.sparql.ARQException) ItemList(org.apache.jena.sparql.sse.ItemList)

Example 3 with ItemList

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);
}
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 4 with ItemList

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;
}
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 5 with ItemList

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);
}
Also used : Var(org.apache.jena.sparql.core.Var) ItemList(org.apache.jena.sparql.sse.ItemList)

Aggregations

ItemList (org.apache.jena.sparql.sse.ItemList)18 Item (org.apache.jena.sparql.sse.Item)10 Node (org.apache.jena.graph.Node)4 Var (org.apache.jena.sparql.core.Var)4 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2 ArrayList (java.util.ArrayList)1 Graph (org.apache.jena.graph.Graph)1 ARQException (org.apache.jena.sparql.ARQException)1 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)1 Op (org.apache.jena.sparql.algebra.Op)1 Table (org.apache.jena.sparql.algebra.Table)1 Quad (org.apache.jena.sparql.core.Quad)1 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)1 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)1 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)1 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)1