Search in sources :

Example 66 with Item

use of org.apache.jena.sparql.sse.Item in project jena by apache.

the class BuilderExpr method buildItem.

public Expr buildItem(Item item) {
    Expr expr = null;
    if (item.isList()) {
        ItemList list = item.getList();
        if (list.size() == 0)
            BuilderLib.broken(item, "Empty list for expression");
        Item head = list.get(0);
        if (head.isNode()) {
            if (head.getNode().isVariable() && list.size() == 1) {
                // The case of (?z)
                return new ExprVar(Var.alloc(head.getNode()));
            }
            return buildFunctionCall(list);
        } else if (head.isList())
            BuilderLib.broken(item, "Head is a list");
        else if (head.isSymbol()) {
            if (item.isTagged(Tags.tagExpr)) {
                BuilderLib.checkLength(2, list, "Wrong length: " + item.shortString());
                item = list.get(1);
                return buildItem(item);
            }
            return buildKnownFunction(list);
        }
        throw new ARQInternalErrorException();
    }
    if (item.isNode()) {
        if (Var.isVar(item.getNode()))
            return new ExprVar(Var.alloc(item.getNode()));
        return NodeValue.makeNode(item.getNode());
    }
    if (item.isSymbolIgnoreCase(Tags.tagTrue))
        return NodeValue.TRUE;
    if (item.isSymbolIgnoreCase(Tags.tagFalse))
        return NodeValue.FALSE;
    BuilderLib.broken(item, "Not a list or a node or recognized symbol: " + item);
    return null;
}
Also used : Item(org.apache.jena.sparql.sse.Item) ItemList(org.apache.jena.sparql.sse.ItemList) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Example 67 with Item

use of org.apache.jena.sparql.sse.Item in project jena by apache.

the class BuilderGraph method buildGraph.

public static Graph buildGraph(Graph graph, ItemList list) {
    if (!list.isEmpty() && list.get(0).isSymbol()) {
        if (list.get(0).isSymbol(Tags.tagGraph))
            list = list.cdr();
    }
    for (Item item : list) {
        BuilderLib.checkList(item);
        Triple triple = buildTriple(item.getList());
        graph.add(triple);
    }
    return graph;
}
Also used : Triple(org.apache.jena.graph.Triple) Item(org.apache.jena.sparql.sse.Item)

Example 68 with Item

use of org.apache.jena.sparql.sse.Item in project jena by apache.

the class BuilderGraph method loadGraph.

private static void loadGraph(Graph graph, ItemList list) {
    BuilderLib.checkLength(2, list, Tags.tagLoad);
    Item item = list.get(1);
    if (!item.isNode())
        BuilderLib.broken(item, "Expected: (" + Tags.tagLoad + " 'filename')");
    String s = NodeUtils.stringLiteral(item.getNode());
    if (s == null)
        BuilderLib.broken(item, "Expected: (" + Tags.tagLoad + " 'filename')");
    Model model = ModelFactory.createModelForGraph(graph);
    FileManager.get().readModel(model, s);
}
Also used : Item(org.apache.jena.sparql.sse.Item) Model(org.apache.jena.rdf.model.Model)

Example 69 with Item

use of org.apache.jena.sparql.sse.Item in project jena by apache.

the class ParseHandlerForm method listFinish.

@Override
public void listFinish(int line, int column) {
    ItemList list = currentList();
    if (!frameStack.isCurrent(list)) {
        // Nothing special - proceed as normal.
        super.listFinish(line, column);
        return;
    }
    if (inDecl)
        throwException("Inconsistent form: Still in DECL at end of the form", line, column);
    // For later: no exception: ensure this is cleared.
    inDecl = false;
    finishForm(list);
    // Frame
    Frame f = frameStack.pop();
    // Drop the form list.
    popList();
    //setCurrentItem(null) ;  // Clear, in case top level item is a form of nothing.
    // Form output skipped if no result registered.
    Item item = f.result;
    // If all forms at least evaluate to nil.
    //        if ( item == null )
    //            item = Item.createNil(list.getLine(), list.getColumn()) ;
    // And emit a result as a listAdd.
    // Must go through our listAdd() here to handle nested forms.
    // item==null : remove nil code above to allow forms that have no output.
    //        if ( item != null )
    listAdd(item);
}
Also used : Item(org.apache.jena.sparql.sse.Item) ItemList(org.apache.jena.sparql.sse.ItemList)

Example 70 with Item

use of org.apache.jena.sparql.sse.Item in project jena by apache.

the class ParseHandlerPlain method emitVar.

@Override
public void emitVar(int line, int column, String varName) {
    Var var = null;
    switch(varName) {
        case "":
            // "?"
            var = varAlloc.allocVar();
            break;
        case ARQConstants.allocVarAnonMarker:
            // "??" -- Allocate a non-distinguished variable
            var = varAllocND.allocVar();
            break;
        case ARQConstants.allocVarMarker:
            // "?." -- Allocate a named variable
            var = varAllocIntern.allocVar();
            break;
        default:
            var = Var.alloc(varName);
            break;
    }
    Item item = Item.createNode(var, line, column);
    listAdd(item);
}
Also used : Item(org.apache.jena.sparql.sse.Item) Var(org.apache.jena.sparql.core.Var)

Aggregations

Item (org.apache.jena.sparql.sse.Item)78 Test (org.junit.Test)31 Node (org.apache.jena.graph.Node)11 ItemList (org.apache.jena.sparql.sse.ItemList)10 Var (org.apache.jena.sparql.core.Var)6 ArrayList (java.util.ArrayList)5 Binding (org.apache.jena.sparql.engine.binding.Binding)3 Graph (org.apache.jena.graph.Graph)2 Triple (org.apache.jena.graph.Triple)2 ARQException (org.apache.jena.sparql.ARQException)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 VarExprList (org.apache.jena.sparql.core.VarExprList)2 ItemException (org.apache.jena.sparql.sse.ItemException)2 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)1 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)1 QueryParseException (org.apache.jena.query.QueryParseException)1 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)1 Model (org.apache.jena.rdf.model.Model)1 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)1 Table (org.apache.jena.sparql.algebra.Table)1