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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations