Search in sources :

Example 16 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class BindingUtils method addToBinding.

public static void addToBinding(BindingMap binding, QuerySolution qSolution) {
    if (qSolution == null)
        return;
    for (Iterator<String> iter = qSolution.varNames(); iter.hasNext(); ) {
        String n = iter.next();
        RDFNode x = qSolution.get(n);
        if (Var.isBlankNodeVarName(n))
            continue;
        try {
            binding.add(Var.alloc(n), x.asNode());
        } catch (ARQInternalErrorException ex) {
            // bad binding attempt.
            Log.warn(BindingUtils.class, "Attempt to bind " + n + " when already bound");
        }
    }
}
Also used : ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) RDFNode(org.apache.jena.rdf.model.RDFNode)

Example 17 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class PathLib method evalGroundedOneEnd.

private static QueryIterator evalGroundedOneEnd(Binding binding, Iterator<Node> iter, Node endNode, ExecutionContext execCxt) {
    List<Binding> results = new ArrayList<>();
    if (!Var.isVar(endNode))
        throw new ARQInternalErrorException("Non-variable endnode in _execTriplePath");
    Var var = Var.alloc(endNode);
    // Assign.
    for (; iter.hasNext(); ) {
        Node n = iter.next();
        results.add(BindingFactory.binding(binding, var, n));
    }
    return new QueryIterPlainWrapper(results.iterator(), execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) Var(org.apache.jena.sparql.core.Var) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList)

Example 18 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class Eval method evalDS.

static Table evalDS(OpDatasetNames opDSN, Evaluator evaluator) {
    Node graphNode = opDSN.getGraphNode();
    if (graphNode.isURI()) {
        if (evaluator.getExecContext().getDataset().containsGraph(graphNode)) {
            return new TableUnit();
        } else // WRONG
        {
            return new TableEmpty();
        }
    }
    if (!Var.isVar(graphNode))
        throw new ARQInternalErrorException("OpDatasetNames: Not a URI or variable: " + graphNode);
    DatasetGraph dsg = evaluator.getExecContext().getDataset();
    Iterator<Node> iter = dsg.listGraphNodes();
    List<Binding> list = new ArrayList<>((int) dsg.size());
    for (; iter.hasNext(); ) {
        Node gn = iter.next();
        Binding b = BindingFactory.binding(Var.alloc(graphNode), gn);
        list.add(b);
    }
    QueryIterator qIter = new QueryIterPlainWrapper(list.iterator(), evaluator.getExecContext());
    return TableFactory.create(qIter);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterPlainWrapper(org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ArrayList(java.util.ArrayList) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) TableUnit(org.apache.jena.sparql.algebra.table.TableUnit) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 19 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException in project jena by apache.

the class Eval method evalQuadPattern.

static Table evalQuadPattern(OpQuadPattern opQuad, Evaluator evaluator) {
    if (opQuad.isEmpty())
        return TableFactory.createUnit();
    ExecutionContext cxt = evaluator.getExecContext();
    DatasetGraph ds = cxt.getDataset();
    BasicPattern pattern = opQuad.getBasicPattern();
    if (!opQuad.getGraphNode().isVariable()) {
        if (!opQuad.getGraphNode().isURI()) {
            throw new ARQInternalErrorException("Not a URI or variable: " + opQuad.getGraphNode());
        }
        Graph g = null;
        if (opQuad.isDefaultGraph())
            g = ds.getDefaultGraph();
        else
            g = ds.getGraph(opQuad.getGraphNode());
        if (g == null)
            return new TableEmpty();
        ExecutionContext cxt2 = new ExecutionContext(cxt, g);
        QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2);
        return TableFactory.create(qIter);
    } else {
        // Variable.
        Var gVar = Var.alloc(opQuad.getGraphNode());
        // Or just just devolve to OpGraph and get OpUnion chain of OpJoin
        QueryIterConcat concat = new QueryIterConcat(cxt);
        for (Iterator<Node> graphNodes = cxt.getDataset().listGraphNodes(); graphNodes.hasNext(); ) {
            Node gn = graphNodes.next();
            //Op tableVarURI = TableFactory.create(gn.getName(), Node.createURI(uri)) ;
            Graph g = cxt.getDataset().getGraph(gn);
            Binding b = BindingFactory.binding(BindingRoot.create(), gVar, gn);
            ExecutionContext cxt2 = new ExecutionContext(cxt, g);
            // Eval the pattern, eval the variable, join.
            // Pattern may be non-linear in the variable - do a pure execution.  
            Table t1 = TableFactory.create(gVar, gn);
            QueryIterator qIter = executeBGP(pattern, QueryIterRoot.create(cxt2), cxt2);
            Table t2 = TableFactory.create(qIter);
            Table t3 = evaluator.join(t1, t2);
            concat.add(t3.iterator(cxt2));
        }
        return TableFactory.create(concat);
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Table(org.apache.jena.sparql.algebra.Table) Var(org.apache.jena.sparql.core.Var) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) Node(org.apache.jena.graph.Node) BasicPattern(org.apache.jena.sparql.core.BasicPattern) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) QueryIterConcat(org.apache.jena.sparql.engine.iterator.QueryIterConcat) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) OpGraph(org.apache.jena.sparql.algebra.op.OpGraph) Graph(org.apache.jena.graph.Graph) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 20 with ARQInternalErrorException

use of org.apache.jena.sparql.ARQInternalErrorException 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)

Aggregations

ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)34 Node (org.apache.jena.graph.Node)6 NodeValue (org.apache.jena.sparql.expr.NodeValue)6 ArrayList (java.util.ArrayList)5 Binding (org.apache.jena.sparql.engine.binding.Binding)5 Var (org.apache.jena.sparql.core.Var)4 BigDecimal (java.math.BigDecimal)3 BasicPattern (org.apache.jena.sparql.core.BasicPattern)3 ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)3 BigInteger (java.math.BigInteger)2 CmdException (jena.cmd.CmdException)2 TerminationException (jena.cmd.TerminationException)2 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)2 Graph (org.apache.jena.graph.Graph)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 JenaException (org.apache.jena.shared.JenaException)2 TableEmpty (org.apache.jena.sparql.algebra.table.TableEmpty)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)2 QueryIterPlainWrapper (org.apache.jena.sparql.engine.iterator.QueryIterPlainWrapper)2