private E_Function asFunction() { return new E_Function(iri, exprList); }
@Override public Expr copy(ExprList newArgs) { return new E_Function(getFunctionIRI(), newArgs) ; } }
if(expr.getFunctionIRI().equals(SparqlifyConstants.rdfTermLabel)) { if(expr.getArgs().size() != 4) { throw new RuntimeException("RdfTerm requires 4 arguments, instead got: " + expr); expr.getArg(1), expr.getArg(2), expr.getArg(3), expr.getArg(4)); } else if (expr.getFunctionIRI().equals(SparqlifyConstants.uriLabel)) { return new E_RdfTerm( NodeValue.makeDecimal(1), expr.getArgs().get(0), NodeValue.makeString(""), NodeValue.makeString("")); } else if (expr.getFunctionIRI() .equals(SparqlifyConstants.plainLiteralLabel)) { if (expr.getArgs().size() == 2) { Expr tmp = expr.getArgs().get(1); if (tmp != null) { lang = tmp; NodeValue.makeDecimal(2), expr.getArgs().get(0), lang, NodeValue.makeString("")); } else if (expr.getFunctionIRI() .equals(SparqlifyConstants.typedLiteralLabel)) { return new E_RdfTerm( NodeValue.makeDecimal(3), expr.getArgs().get(0), NodeValue.makeString(""), expr.getArgs().get(1)); } else if (expr.getFunctionIRI().equals(SparqlifyConstants.blankNodeLabel)) { return new E_RdfTerm( NodeValue.makeDecimal(0), expr.getArgs().get(0), NodeValue.makeString(""), NodeValue.makeString(""));
/** * Returns the expr representing the dynamic function to be invoked * <p> * Uses caching wherever possible to avoid * </p> */ private Expr buildFunction(String functionIRI, List<Expr> args, Context cxt) { //Use our cached version of the expression wherever possible if (functionCache.containsKey(functionIRI)) { return functionCache.get(functionIRI); } //Otherwise generate a new function and cache it try { E_Function e = new E_Function(functionIRI, new ExprList(args)); e.buildFunction(cxt); functionCache.put(functionIRI, e); return e; } catch (Throwable e) { //Anything goes wrong in creating the function cache a null so we don't retry every time we see this IRI functionCache.put(functionIRI, null); return null; } } }
public static RdfTermPattern _deriveRegex(E_Function expr) { if(SparqlifyConstants.rdfTermLabel.equals(expr.getFunctionIRI())) { return new RdfTermPattern( new PatternPro(RegexDerivation.deriveRegex(expr.getArg(2)))); } return null; }
return function.exec(binding, args, getFunctionIRI(), env); } catch (ExprUndefFunction ex) { buildFunction(env.getContext()) ; if ( function == null ) throw new ExprEvalException("URI <" + getFunctionIRI() + "> not bound") ; NodeValue r = function.exec(binding, args, getFunctionIRI(), env) ; return r ;
@Override public void visit(ExprFunctionN func) { if ( func instanceof E_Function ) { // Causes unbindable functions to complain now, not later. E_Function f = (E_Function)func ; f.buildFunction(context) ; } } }
public void buildFunction(Context cxt) { if ( javaScriptFunction != null ) return; try { bindFunction(cxt) ; } catch (ExprUndefFunction ex) { if ( WarnOnUnknownFunction ) ARQ.getExecLogger().warn("URI <"+functionIRI+"> has no registered function factory") ; } }
/** * Creates a function call as per the SPARQL 11 query definition. * * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rFunctionCall * * @see org.apache.jena.sparql.expr.E_Function * * @param name * the name of the function. * @param args * the arguments to the function. * @return an E_Function instance. */ public final E_Function function(String name, ExprList args) { return new E_Function(name, args); }
@Test public void test_function_non_expansion_01() { Expr square = new E_Multiply(new ExprVar("x"), new ExprVar("x")); UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<>(square.getVarsMentioned())); //Test that with preserveDependencies set to true that the definition of cube is not expanded Expr cube = new E_Multiply(new E_Function("http://example/square", new ExprList(new ExprVar("x"))), new ExprVar("x")); UserDefinedFunctionFactory.getFactory().add("http://example/cube", cube, new ArrayList<>(cube.getVarsMentioned())); UserDefinedFunctionDefinition def = UserDefinedFunctionFactory.getFactory().get("http://example/cube"); Expr base = def.getBaseExpr(); Assert.assertTrue(base instanceof E_Multiply); E_Multiply multiply = (E_Multiply)base; Assert.assertTrue(multiply.getArg1() instanceof E_Function); Assert.assertTrue(multiply.getArg2() instanceof ExprVar); E_Function lhs = (E_Function)multiply.getArg1(); Assert.assertEquals("http://example/square", lhs.getFunctionIRI()); Assert.assertEquals(1, base.getVarsMentioned().size()); }
/** * Creates a function call as per the SPARQL 11 query definition. * * https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#rFunctionCall * * @see org.apache.jena.sparql.expr.E_Function * * @param name * the name of the function. * @param args * the arguments to the function. * @return an E_Function instance. */ public final E_Function function(String name, ExprList args) { return new E_Function(name, args); }
public InverseFunctionManagerImpl() { // urlEncode^-1 = urlDecode inverseFactory.put(SparqlifyConstants.urlEncode, (arg) -> new E_Function(SparqlifyConstants.urlDecode, new ExprList(arg))); // urlDecode^-1 = urlEncode inverseFactory.put(SparqlifyConstants.urlDecode, (arg) -> new E_Function(SparqlifyConstants.urlEncode, new ExprList(arg))); }
final public Expr FunctionCall() throws ParseException { String fname ; ExprList a ; ExprList aParam = null ; boolean distinct = false ; fname = IRIref(); a = ArgList(); {if (true) return new E_Function(fname, a) ;} throw new Error("Missing return statement in function"); }
/** * Convert an aggregator to a function object. * By this we can use the same infrastructure * as being used for all other types of functions. * * @param agg * @return */ public static E_Function aggregatorToFunction(Aggregator agg) { ExprList args = agg.getExprList(); /* Expr arg = agg.getExpr(); ExprList args = new ExprList(); if(arg != null) { args.add(arg); }*/ if(args == null) { args = new ExprList(); } String fnName = agg.getClass().getSimpleName(); E_Function result = new E_Function(fnName, args); return result; }
@Override public NodeValue eval(List<NodeValue> args, FunctionEnv env) { // Instead of evalSpecial, we can rely on the machinery to evaluate the arguments to CALL first. // This precludes special forms for CALL first argument. // This code here is not usually called - evalSpecial is more general and is the main code path, NodeValue func = args.get(0) ; if (func == null) throw new ExprEvalException("CALL: Function identifier unbound"); if (func.isIRI()) { ExprList a = new ExprList() ; for ( int i = 1 ; i < args.size() ; i++ ) a.add(args.get(i)) ; //Expr e = null ; Expr e = new E_Function(func.getNode().getURI(), a); //Calling this may throw an error which we will just let bubble up return e.eval(null, env) ; } else throw new ExprEvalException("CALL: Function identifier not an IRI"); }
final public Expr IRIrefOrFunction() throws ParseException { String iri ; ExprList a = null ; ExprList aParam = null ; boolean distinct = false ; iri = IRIref(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LPAREN: case NIL: a = ArgList(); break; default: jj_la1[69] = jj_gen; ; } if ( a == null ) {if (true) return asExpr(createNode(iri)) ;} {if (true) return new E_Function(iri, a) ;} throw new Error("Missing return statement in function"); }
@Override public E_RdfTerm transform(Expr orig, E_RdfTerm a) { String typeName = ExprUtils.getFunctionId(orig.getFunction()); NodeValue typeExpr = NodeValue.makeString(typeName); Expr av = a.getLexicalValue(); //Expr c = new E_Cast(av, bv); Expr c = new E_Function(typeName, new ExprList(av)); E_RdfTerm result = E_RdfTerm.createTypedLiteral(c, typeExpr); return result; }
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) ; }
final public Expr FunctionCall() throws ParseException { String fname ; Args a ; fname = iri(); a = ArgList(); if ( AggregateRegistry.isRegistered(fname) ) { if ( ! getAllowAggregatesInExpressions() ) throwParseException("Aggregate expression not legal at this point : "+fname, -1, -1) ; Aggregator agg = AggregatorFactory.createCustom(fname, a) ; Expr exprAgg = getQuery().allocAggregate(agg) ; {if (true) return exprAgg ;} } {if (true) return new E_Function(fname, a) ;} throw new Error("Missing return statement in function"); }
ExprFunction exprFn = new E_Function(name, newArgs);