public static List<Expr> getSubExprs(Expr expr) { List<Expr> result = expr != null && expr.isFunction() ? expr.getFunction().getArgs() : Collections.emptyList() ; return result; }
public static void reassemble( Expr viewExpr, BiMap<Node, Expr> viewNodeToExpr, Expr queryExpr, BiMap<Node, Expr> queryNodeToExpr, BiMap<Node, Node> iso ) { // If the Node queryNode = queryNodeToExpr.inverse().get(queryExpr); Node viewNode = iso.inverse().get(queryNode); if(queryExpr.isFunction()) { ExprFunction fn = queryExpr.getFunction(); for(Expr arg : fn.getArgs()) { } } }
public static List<Expr> flatten(List<Expr> args, Predicate<? super Expr> isFlattenableFunction) { List<Expr> tmpArgs = new ArrayList<>(); boolean change = false; for(Expr arg : args) { if(arg.isFunction()) { ExprFunction fn = arg.getFunction(); if(isFlattenableFunction.test(fn)) { change = true; tmpArgs.addAll(fn.getArgs()); } else { tmpArgs.add(arg); } } else { tmpArgs.add(arg); } } List<Expr> result = change ? tmpArgs : args; return result; } }
@Override public SqlExprType getType() { SqlExprType result; if(expr.isConstant()) { result = SqlExprType.Constant; } else if(expr.isVariable()) { result = SqlExprType.Variable; } else if(expr.isFunction()) { result = SqlExprType.Function; } else { throw new RuntimeException("Should not happen: could not determine expression type of " + expr); } return result; }
public static List<Expr> flatten(List<Expr> args, Predicate<? super Expr> isFlattenableFunction) { List<Expr> tmpArgs = new ArrayList<>(); boolean change = false; for(Expr arg : args) { if(arg.isFunction()) { ExprFunction fn = arg.getFunction(); if(isFlattenableFunction.test(fn)) { change = true; tmpArgs.addAll(fn.getArgs()); } else { tmpArgs.add(arg); } } else { tmpArgs.add(arg); } } List<Expr> result = change ? tmpArgs : args; return result; } }
@Deprecated public static void getSubExpressions(Expr expr, Set<Expr> result) { if(expr.isFunction()) { ExprFunction f = (ExprFunction)expr; for(int i = 1; i <= f.numArgs(); ++i) { Expr arg = f.getArg(i); if(!result.contains(arg)) { result.add(arg); getSubExpressions(arg, result); } } } }
public static E_RdfTerm expandRdfTerm(Expr expr) { E_RdfTerm result = null; if(expr.isFunction()) { result = expandRdfTerm(expr.getFunction()); } /* else if(expr.isConstant()) { result = expandConstant(expr); }*/ return result; }
public static int classify(Expr e) { int result = e.isConstant() ? 0 : e.isVariable() ? 1 : e.isFunction() ? 2 : 3; return result; }
public static E_RdfTerm expand(Expr expr) { E_RdfTerm result; if(expr.isFunction()) { ExprFunction fn = expr.getFunction(); result = expand(fn); } else { result = null; } return result; }
public static Entry<Var, Var> tryGetVarVar(Expr e) { Entry<Var, Var> result = null; if(e.isFunction()) { ExprFunction fn = e.getFunction(); List<Expr> args = fn.getArgs(); if(args.size() == 2) { Expr a = args.get(0); Expr b = args.get(1); result = tryGetVarVar(a, b); if(result == null) { result = tryGetVarVar(b, a); } } } return result; }
public static Entry<Var, Node> tryGetVarConst(Expr e) { Entry<Var, Node> result = null; if(e.isFunction()) { ExprFunction fn = e.getFunction(); List<Expr> args = fn.getArgs(); if(args.size() == 2) { Expr a = args.get(0); Expr b = args.get(1); result = tryGetVarConst(a, b); if(result == null) { result = tryGetVarConst(b, a); } } } return result; }
public Expr copy(Expr proto, List<Expr> args) { Expr result; if(!proto.isFunction()) { throw new RuntimeException("Must not be called on non-functions"); } ExprFunction fn = proto.getFunction(); result = copy(fn, args); return result; }
/** * Apply unnesting of concats * * @param exprs * @return */ public static String toTemplate(Expr concatExpr) { // TODO We implicitly assume that the expression is a concat one - we should validate this Expr expr = normalizeConcatExpressions(concatExpr); List<Expr> args = expr.isFunction() ? expr.getFunction().getArgs() : Collections.singletonList(expr); String result = toTemplateCore(args); return result; }
/** * Apply unnesting of concats * * @param exprs * @return */ public static String toTemplate(Expr concatExpr) { // TODO We implicitly assume that the expression is a concat one - we should validate this Expr expr = normalizeConcatExpressions(concatExpr); List<Expr> args = expr.isFunction() ? expr.getFunction().getArgs() : Collections.singletonList(expr); String result = toTemplateCore(args); return result; }
public static boolean evalPredicate(Expr expr, Predicate<Expr> predicate) { if(predicate.evaluate(expr)) { return true; } else if(expr.isFunction()) { for(Expr arg : expr.getFunction().getArgs()) { if(evalPredicate(arg, predicate)) { return true; } } } return false; }
public Expr deepCopy(Expr proto) { Expr result; if(proto == null) { throw new NullPointerException(); } if(proto.isConstant()) { result = deepCopy(proto.getConstant()); } else if(proto.isFunction()) { result = deepCopy(proto.getFunction()); } else if(proto.isVariable()) { result = deepCopy(proto.getExprVar()); } else { throw new RuntimeException("Don't know how to copy " + proto + " of type " + proto.getClass()); } return result; //return deepCopy(proto, ExprArgs.getArgs(proto)); }
public SqlExpr translate(Expr expr, Map<String, TypeToken> typeMap) { //assert expr != null : "Null pointer exception"; if(expr == null) { throw new NullPointerException(); } //System.out.println(expr); SqlExpr result = null; if(expr.isConstant()) { result = translate(expr.getConstant()); } else if(expr.isFunction()) { ExprFunction fn = expr.getFunction(); result = translate(fn, typeMap); } else if(expr.isVariable()) { result = translate(expr.getExprVar(), typeMap); } else { throw new RuntimeException("Unknown expression type encountered: " + expr); } return result; }
public static String derivePrefix(Expr expr) { String result; if(expr.isFunction()) { result = derivePrefix(expr.getFunction()); } else if(expr.isConstant()) { result = derivePrefix(expr.getConstant().getNode()); } else { result = null; } return result; }
public static RdfTermType deriveType(Expr expr) { RdfTermType result = null; if(expr.isConstant()) { result = deriveType(expr.getConstant().asNode()); } else if(expr.isFunction()) { result = deriveType(expr.getFunction()); } return result; } }
public Expr normalize(Expr expr, Map<String, TypeToken> typeMap) { Expr result; if(expr == null) { result = NodeValue.nvNothing; } else if(expr.isVariable()) { result = normalize(expr.getExprVar(), typeMap); } else if(expr.isConstant()) { result = normalize(expr.getConstant(), typeMap); } else if(expr.isFunction()) { result = normalize(expr.getFunction(), typeMap); } else { throw new RuntimeException("Unknown expression type: " + expr); } return result; //return MultiMethod.invokeStatic(ExprDatatypeNorm.class, "_nomalize", expr, columnToDatatype); }