public static String derivePrefix(E_RdfTerm termCtor) { String result; Expr expr = termCtor.getArgs().get(1); if(expr instanceof E_StrConcat || expr instanceof E_StrConcatPermissive) { result = derivePrefixConcat(expr.getFunction()); } else { result = null; } return result; }
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 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 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 String extractPrefix(Expr expr) { if(expr instanceof E_StrConcatPermissive || expr instanceof E_StrConcat) { ExprFunction fn = expr.getFunction(); List<Expr> args = fn.getArgs(); if(args.size() == 0) { logger.warn("Zero argument concat expression detected: " + expr); } else { Expr first = args.get(0); if(first.isConstant()) { String value = first.getConstant().asUnquotedString(); return value; } } } return null; }
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; }
/** * * @param expr * @return */ public static List<Expr> getOptimizedConcatArgs(Expr expr) { List<Expr> args = isConcatExpr(expr) ? expr.getFunction().getArgs() : Collections.singletonList(expr); List<Expr> result = mergeConsecutiveConstants(args).getList(); 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 int compare(Expr a, Expr b) { int ca = classify(a); int cb = classify(b); int r = cb - ca; if(r == 0) { switch(ca) { case 0: r = NodeValue.compare(a.getConstant(), b.getConstant()); break; case 1: r = a.getVarName().compareTo(b.getVarName()); break; case 2: r = a.getFunction().getFunctionIRI().compareTo(b.getFunction().getFunctionIRI()); break; default: throw new RuntimeException("should not come here"); } } return r; }
@Override public Expr transform(ExprFunction fn) { List<Expr> newArgs = new ArrayList<Expr>(); for(Expr arg : fn.getArgs()) { if(SqlTranslationUtils.isConcatExpr(arg)) { ExprFunction fnArg = arg.getFunction(); for(Expr a : fnArg.getArgs()) { newArgs.add(a); } } else { newArgs.add(arg); } } ExprList merged = SqlTranslationUtils.mergeConsecutiveConstants(newArgs); Expr result = ExprCopy.getInstance().copy(fn, merged); return result; } }
public static Entry<Var, NodeValue> extractVarConstant(Expr expr) { Entry<Var, NodeValue> result = null; if(expr instanceof ExprFunction) { ExprFunction f = expr.getFunction(); if(f.numArgs() == 2) { Expr a = f.getArg(1); Expr b = f.getArg(2); result = extractVarConstant(a, b); } } 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 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 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 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); }
@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; }