Search in sources :

Example 21 with Item

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

the class ParseHandlerPlain method emitIRI.

@Override
public void emitIRI(int line, int column, String iriStr) {
    Node n = NodeFactory.createURI(iriStr);
    Item item = Item.createNode(n, line, column);
    listAdd(item);
}
Also used : Item(org.apache.jena.sparql.sse.Item) Node(org.apache.jena.graph.Node)

Example 22 with Item

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

the class BuilderExpr method buildFunctionCall.

protected static Expr buildFunctionCall(ItemList list) {
    Item head = list.get(0);
    Node node = head.getNode();
    if (node.isBlank())
        BuilderLib.broken(head, "Blank node for function call!");
    if (node.isLiteral())
        BuilderLib.broken(head, "Literal node for function call!");
    ExprList args = buildExprListUntagged(list, 1);
    // Args
    return new E_Function(node.getURI(), args);
}
Also used : Item(org.apache.jena.sparql.sse.Item) VarExprList(org.apache.jena.sparql.core.VarExprList) Node(org.apache.jena.graph.Node)

Example 23 with Item

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

the class BuilderExpr method buildKnownFunction.

protected Expr buildKnownFunction(ItemList list) {
    if (list.size() == 0)
        BuilderLib.broken(list, "Empty list for expression");
    Item item = list.get(0);
    String tag = item.getSymbol();
    if (tag == null)
        BuilderLib.broken(item, "Null tag");
    Build b = findBuild(tag);
    if (b == null)
        BuilderLib.broken(item, "No known symbol for " + tag);
    return b.make(list);
}
Also used : Item(org.apache.jena.sparql.sse.Item)

Example 24 with Item

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

the class BuilderGraph method buildDataset.

public static DatasetGraph buildDataset(DatasetGraph dsg, ItemList list) {
    BuilderLib.checkTag(list, Tags.tagDataset);
    list = list.cdr();
    for (Item item : list) {
        if (!item.isTagged(Tags.tagGraph)) {
            // Not (graph ...) so it's (quad), short form quad or an error.
            Quad q = BuilderGraph.buildQuad(item.getList(), "Expected (graph ...) or a quad () as elements of a dataset");
            dsg.add(q);
            continue;
        }
        Node name = null;
        ItemList graphContent = item.getList().cdr();
        if (!graphContent.isEmpty() && graphContent.car().isNode()) {
            name = graphContent.car().getNode();
            graphContent = graphContent.cdr();
        }
        Graph g;
        if (name == null) {
            g = dsg.getDefaultGraph();
            if (g == null) {
                g = GraphFactory.createDefaultGraph();
                dsg.setDefaultGraph(g);
            }
        } else {
            g = dsg.getGraph(name);
            if (g == null) {
                g = GraphFactory.createDefaultGraph();
                dsg.addGraph(name, g);
            }
        }
        BuilderGraph.buildGraph(g, graphContent);
    }
    return dsg;
}
Also used : Item(org.apache.jena.sparql.sse.Item) Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) ItemList(org.apache.jena.sparql.sse.ItemList)

Example 25 with Item

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

the class BuilderBinding method buildBinding.

private static Binding buildBinding(ItemList list) {
    // (row or (binding
    if (list.size() == 0)
        BuilderLib.broken(list, "Empty list");
    Item head = list.get(0);
    if (!head.isSymbolIgnoreCase(Tags.tagRow) && !head.isSymbolIgnoreCase(Tags.tagBinding))
        BuilderLib.broken(list, "Does not start (" + Tags.tagRow + " ...) or (" + Tags.tagBinding + " ...)", head);
    BindingMap binding = BindingFactory.create();
    for (int i = 1; i < list.size(); i++) {
        Item item = list.get(i);
        BuilderLib.checkList(item, "Attempt to build a binding pair from non-list: " + item);
        ItemList pair = item.getList();
        BuilderLib.checkLength(2, pair, "Need a pair for a binding");
        Var v = BuilderNode.buildVar(pair.get(0));
        Item cdr = pair.get(1);
        // undef
        if (cdr.isSymbolIgnoreCase(Tags.tagUndef) || cdr.isSymbolIgnoreCase(Tags.tagNull))
            continue;
        BuilderLib.checkNode(cdr);
        Node node = BuilderNode.buildNode(item.getList().get(1));
        if (node == null)
            BuilderLib.broken(item.getList().get(1), "Null node from " + item.getList().get(1));
        if (node.isVariable())
            BuilderLib.broken(item.getList().get(1), "No variables as table values: " + FmtUtils.stringForNode(node));
        if (!node.isConcrete())
            BuilderLib.broken(item.getList().get(1), "Ony concrete nodes as table values: " + FmtUtils.stringForNode(node));
        binding.add(v, node);
    }
    return binding;
}
Also used : Item(org.apache.jena.sparql.sse.Item) Var(org.apache.jena.sparql.core.Var) ItemList(org.apache.jena.sparql.sse.ItemList) Node(org.apache.jena.graph.Node) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap)

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