Search in sources :

Example 1 with ExprEvalException

use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.

the class concat method execEvaluated.

@Override
public QueryIterator execEvaluated(Binding binding, Node subject, Node predicate, PropFuncArg object, ExecutionContext execCxt) {
    if (!Var.isVar(subject))
        throw new ExprEvalException("Subject is not a variable (" + subject + ")");
    String x = "";
    for (Node node : object.getArgList()) {
        if (Var.isVar(node))
            return IterLib.noResults(execCxt);
        String str = NodeFunctions.str(node);
        x = x + str;
    }
    return IterLib.oneResult(binding, Var.alloc(subject), NodeFactory.createLiteral(x), execCxt);
}
Also used : Node(org.apache.jena.graph.Node) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 2 with ExprEvalException

use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.

the class strSplit method execEvaluated.

@Override
public QueryIterator execEvaluated(final Binding binding, final Node subject, final Node predicate, final PropFuncArg object, final ExecutionContext execCxt) {
    if (!Var.isVar(subject))
        throw new ExprEvalException("Subject is not a variable (" + subject + ")");
    if (object.getArgListSize() != 2)
        throw new ExprEvalException("Object list must contain exactly two arguments, the string to split and a regular expression");
    String s = object.getArg(0).getLiteralLexicalForm();
    String regex = object.getArg(1).getLiteralLexicalForm();
    final Var subjectVar = Var.alloc(subject);
    // StrUtils will also trim whitespace
    String[] tokens = StrUtils.split(s, regex);
    Iterator<Binding> it = Iter.map(Arrays.asList(tokens).iterator(), item -> BindingFactory.binding(binding, subjectVar, NodeFactory.createLiteral(item)));
    return new QueryIterPlainWrapper(it, 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) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 3 with ExprEvalException

use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.

the class listIndex method execOneList.

@Override
protected QueryIterator execOneList(Binding binding, Node listNode, Node predicate, List<Node> objectArgs, ExecutionContext execCxt) {
    if (Var.isVar(listNode))
        throw new ExprEvalException("ListIndex : subject not a list or variable bound to a list");
    if (objectArgs.size() != 2)
        throw new ExprEvalException("ListIndex : object not a list of length 2");
    Node indexNode = objectArgs.get(0);
    Node memberNode = objectArgs.get(1);
    Graph graph = execCxt.getActiveGraph();
    if (Var.isVar(indexNode) && !Var.isVar(memberNode))
        return findIndex(graph, binding, listNode, Var.alloc(indexNode), memberNode, execCxt);
    if (!Var.isVar(indexNode) && Var.isVar(memberNode))
        return getByIndex(graph, binding, listNode, indexNode, Var.alloc(memberNode), execCxt);
    if (!Var.isVar(indexNode) && !Var.isVar(memberNode))
        return testSlotValue(graph, binding, listNode, indexNode, memberNode, execCxt);
    return findIndexMember(graph, binding, listNode, Var.alloc(indexNode), Var.alloc(memberNode), execCxt);
}
Also used : Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) GNode(org.apache.jena.sparql.util.graph.GNode) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 4 with ExprEvalException

use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.

the class wait method exec.

@Override
public NodeValue exec(NodeValue nv) {
    if (!nv.isInteger())
        throw new ExprEvalException("Not an integer");
    int x = nv.getInteger().intValue();
    Lib.sleep(x);
    return NodeValue.TRUE;
}
Also used : ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 5 with ExprEvalException

use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.

the class localname method exec.

@Override
public NodeValue exec(NodeValue v) {
    Node n = v.asNode();
    if (!n.isURI())
        throw new ExprEvalException("Not a URI: " + FmtUtils.stringForNode(n));
    String str = n.getLocalName();
    return NodeValue.makeString(str);
}
Also used : Node(org.apache.jena.graph.Node) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Aggregations

ExprEvalException (org.apache.jena.sparql.expr.ExprEvalException)32 Node (org.apache.jena.graph.Node)14 NodeValue (org.apache.jena.sparql.expr.NodeValue)13 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)3 BigInteger (java.math.BigInteger)2 GNode (org.apache.jena.sparql.util.graph.GNode)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Duration (javax.xml.datatype.Duration)1 ArgDecl (jena.cmd.ArgDecl)1 CmdException (jena.cmd.CmdException)1 CmdLineArgs (jena.cmd.CmdLineArgs)1 TerminationException (jena.cmd.TerminationException)1 Graph (org.apache.jena.graph.Graph)1 IRI (org.apache.jena.iri.IRI)1 Violation (org.apache.jena.iri.Violation)1 QueryExecException (org.apache.jena.query.QueryExecException)1 QueryParseException (org.apache.jena.query.QueryParseException)1 SortCondition (org.apache.jena.query.SortCondition)1 PrefixMapping (org.apache.jena.shared.PrefixMapping)1