use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class blankNode method execEvaluated.
@Override
public QueryIterator execEvaluated(Binding binding, Node subject, Node predicate, Node object, ExecutionContext execCxt) {
if (Var.isVar(subject))
throw new ExprEvalException("bnode: subject is an unbound variable");
if (!subject.isBlank())
return IterLib.noResults(execCxt);
String str = subject.getBlankNodeLabel();
Node obj = NodeFactory.createLiteral(str);
if (Var.isVar(object))
return IterLib.oneResult(binding, Var.alloc(object), obj, execCxt);
// Subject and object are concrete
if (object.sameValueAs(obj))
return IterLib.result(binding, execCxt);
return IterLib.noResults(execCxt);
}
use of org.apache.jena.sparql.expr.ExprEvalException in project jena by apache.
the class qexpr method main2.
public static void main2(String... argv) {
CmdLineArgs cl = new CmdLineArgs(argv);
ArgDecl helpDecl = new ArgDecl(ArgDecl.NoValue, "h", "help");
cl.add(helpDecl);
ArgDecl verboseDecl = new ArgDecl(ArgDecl.NoValue, "v", "verbose");
cl.add(verboseDecl);
ArgDecl versionDecl = new ArgDecl(ArgDecl.NoValue, "ver", "version", "V");
cl.add(versionDecl);
ArgDecl quietDecl = new ArgDecl(ArgDecl.NoValue, "q", "quiet");
cl.add(quietDecl);
ArgDecl reduceDecl = new ArgDecl(ArgDecl.NoValue, "reduce", "fold", "simplify");
cl.add(reduceDecl);
ArgDecl strictDecl = new ArgDecl(ArgDecl.NoValue, "strict");
cl.add(strictDecl);
ArgDecl printDecl = new ArgDecl(ArgDecl.HasValue, "print");
cl.add(printDecl);
try {
cl.process();
} catch (IllegalArgumentException ex) {
System.err.println(ex.getMessage());
usage(System.err);
throw new CmdException();
}
if (cl.contains(helpDecl)) {
usage();
throw new TerminationException(0);
}
if (cl.contains(versionDecl)) {
System.out.println("ARQ Version: " + ARQ.VERSION + " (Jena: " + Jena.VERSION + ")");
throw new TerminationException(0);
}
// ==== General things
boolean verbose = cl.contains(verboseDecl);
boolean quiet = cl.contains(quietDecl);
if (cl.contains(strictDecl))
ARQ.setStrictMode();
boolean actionCopySubstitute = cl.contains(reduceDecl);
boolean actionPrintPrefix = false;
boolean actionPrintSPARQL = false;
boolean actionPrint = cl.contains(printDecl);
for (String v : cl.getValues(printDecl)) {
if (v.equalsIgnoreCase("prefix") || v.equalsIgnoreCase("op")) {
actionPrintPrefix = true;
} else if (v.equalsIgnoreCase("expr")) {
actionPrintSPARQL = true;
} else {
System.err.println("Unknown print form: " + v);
throw new TerminationException(0);
}
}
for (int i = 0; i < cl.getNumPositional(); i++) {
String exprStr = cl.getPositionalArg(i);
exprStr = cl.indirect(exprStr);
try {
PrefixMapping pmap = PrefixMapping.Factory.create();
pmap.setNsPrefixes(ARQConstants.getGlobalPrefixMap());
pmap.setNsPrefix("", "http://example/");
pmap.setNsPrefix("ex", "http://example/ns#");
// Node n = asNode() ;
// return makeNode(n) ;
Expr expr = ExprUtils.parse(exprStr, pmap);
if (verbose)
System.out.print(expr.toString() + " => ");
if (actionPrint) {
if (actionPrintSPARQL)
System.out.println(ExprUtils.fmtSPARQL(expr));
if (actionPrintPrefix)
WriterSSE.out(IndentedWriter.stdout, expr, new Prologue(pmap));
continue;
}
try {
if (actionCopySubstitute) {
Expr e = ExprLib.foldConstants(expr);
System.out.println(e);
} else {
// Default action
ARQ.getContext().set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
FunctionEnv env = new ExecutionContext(ARQ.getContext(), null, null, null);
NodeValue r = expr.eval(null, env);
//System.out.println(r.asQuotedString()) ;
Node n = r.asNode();
String s = NodeFmtLib.displayStr(n);
System.out.println(s);
}
} catch (ExprEvalException ex) {
System.out.println("Exception: " + ex.getMessage());
throw new TerminationException(2);
}
} catch (QueryParseException ex) {
System.err.println("Parse error: " + ex.getMessage());
throw new TerminationException(2);
}
}
}
Aggregations