Search in sources :

Example 1 with Sk

use of catdata.aql.exp.InstExpRaw.Sk in project fql by CategoricalData.

the class QueryExpRaw method eval.

@Override
public Query<Ty, En, Sym, Fk, Att, En, Fk, Att> eval(AqlEnv env) {
    Schema<Ty, En, Sym, Fk, Att> src0 = src.eval(env);
    Schema<Ty, En, Sym, Fk, Att> dst0 = dst.eval(env);
    Ctx<En, Triple<Ctx<Var, En>, Collection<Eq<Ty, En, Sym, Fk, Att, Var, Var>>, AqlOptions>> ens0 = new Ctx<>();
    Ctx<Att, Term<Ty, En, Sym, Fk, Att, Var, Var>> atts0 = new Ctx<>();
    Ctx<Fk, Pair<Ctx<Var, Term<Void, En, Void, Fk, Void, Var, Void>>, Boolean>> fks0 = new Ctx<>();
    Ctx<Var, Ty> xxx = new Ctx<>();
    Ctx<Var, Term<Ty, Void, Sym, Void, Void, Void, Void>> yyy = new Ctx<>();
    for (String k : imports) {
        @SuppressWarnings("unchecked") Query<Ty, En, Sym, Fk, Att, En, Fk, Att> v = env.defs.qs.get(k);
        for (Var var : v.params.keySet()) {
            // allow benign collisions
            xxx.map.put(var, v.params.get(var));
        }
        for (Var var : v.consts.keySet()) {
            yyy.map.put(var, v.consts.get(var));
        }
        for (En En : v.ens.keySet()) {
            ens0.put(En, new Triple<>(v.ens.get(En).gens, v.ens.get(En).eqs, v.ens.get(En).options));
        }
        for (Att Att : v.atts.keySet()) {
            atts0.put(Att, v.atts.get(Att));
        }
        for (Fk Fk : v.fks.keySet()) {
            fks0.put(Fk, new Pair<>(v.fks.get(Fk).gens(), v.doNotValidate.get(Fk)));
        }
    }
    Ctx<En, Collage<Ty, En, Sym, Fk, Att, Var, Var>> cols = new Ctx<>();
    for (Block p : blocks) {
        try {
            if (!dst0.ens.contains(p.en)) {
                throw new RuntimeException("the proposed target entity " + p.en + " does not actually appear in the target schema");
            }
            processBlock(options, env, src0, ens0, cols, p, params);
        } catch (RuntimeException ex) {
            ex.printStackTrace();
            throw new LocException(b1.get(p.en), "In block for target entity " + p.en + ", " + ex.getMessage());
        }
        for (Pair<catdata.aql.exp.SchExpRaw.Att, RawTerm> pp : p.atts) {
            try {
                processAtt(src0, dst0, ens0, atts0, cols, pp, params);
            } catch (Exception ex) {
                ex.printStackTrace();
                throw new LocException(b3.get(pp.first), "In return clause for " + pp.first + ", " + ex.getMessage());
            }
        }
    }
    // two loops bc need stuff in en to do this part
    for (Block p : blocks) {
        for (Pair<catdata.aql.exp.SchExpRaw.Fk, Trans> pp : p.fks) {
            try {
                Ctx<Var, Term<Void, En, Void, Fk, Void, Var, Void>> trans = new Ctx<>();
                for (Pair<Var, RawTerm> v : pp.second.gens) {
                    Ctx<String, Chc<Ty, En>> ctx = unVar(ens0.get(dst0.fks.get(pp.first).first).first.inRight());
                    Collage<Ty, En, Sym, Fk, Att, Var, Var> col = cols.get(dst0.fks.get(pp.first).first);
                    Chc<Ty, En> required = Chc.inRight(ens0.get(dst0.fks.get(pp.first).second).first.get(v.first));
                    Term<catdata.aql.exp.TyExpRaw.Ty, catdata.aql.exp.SchExpRaw.En, catdata.aql.exp.TyExpRaw.Sym, catdata.aql.exp.SchExpRaw.Fk, catdata.aql.exp.SchExpRaw.Att, Gen, Sk> term = RawTerm.infer1x(ctx.map, v.second, null, required, col.convert(), "in foreign key " + pp.first.str + ", ", src0.typeSide.js).second;
                    trans.put(v.first, freeze(term.convert(), params).convert());
                }
                boolean doNotCheckEqs = (Boolean) new AqlOptions(pp.second.options, null, env.defaults).getOrDefault(AqlOption.dont_validate_unsafe);
                fks0.put(pp.first, new Pair<>(trans, doNotCheckEqs));
            } catch (RuntimeException ex) {
                ex.printStackTrace();
                throw new LocException(b2.get(pp.first), ex.getMessage());
            }
        }
    }
    boolean doNotCheckEqs = (Boolean) new AqlOptions(options, null, env.defaults).getOrDefault(AqlOption.dont_validate_unsafe);
    boolean elimRed = (Boolean) new AqlOptions(options, null, env.defaults).getOrDefault(AqlOption.query_remove_redundancy);
    for (String s : params.keySet()) {
        xxx.put(new Var(s), new Ty(params.get(s)));
    }
    for (String s : consts.keySet()) {
        Chc<Ty, En> required = Chc.inLeft(xxx.get(new Var(s)));
        Term<catdata.aql.exp.TyExpRaw.Ty, catdata.aql.exp.SchExpRaw.En, catdata.aql.exp.TyExpRaw.Sym, catdata.aql.exp.SchExpRaw.Fk, catdata.aql.exp.SchExpRaw.Att, Gen, Sk> term = RawTerm.infer1x(new HashMap<>(), consts.get(s), null, required, src0.collage().convert(), "", src0.typeSide.js).second;
        yyy.put(new Var(s), term.convert());
    }
    return Query.makeQuery2(xxx, yyy, ens0, atts0, fks0, src0, dst0, doNotCheckEqs, elimRed);
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) HashMap(java.util.HashMap) Var(catdata.aql.Var) Ctx(catdata.Ctx) En(catdata.aql.exp.SchExpRaw.En) Eq(catdata.aql.Eq) Trans(catdata.aql.exp.QueryExpRaw.Trans) Pair(catdata.Pair) Ty(catdata.aql.exp.TyExpRaw.Ty) Fk(catdata.aql.exp.SchExpRaw.Fk) Sym(catdata.aql.exp.TyExpRaw.Sym) RawTerm(catdata.aql.RawTerm) Term(catdata.aql.Term) RawTerm(catdata.aql.RawTerm) Triple(catdata.Triple) Gen(catdata.aql.exp.InstExpRaw.Gen) Sk(catdata.aql.exp.InstExpRaw.Sk) AqlOptions(catdata.aql.AqlOptions) Collage(catdata.aql.Collage) Chc(catdata.Chc)

Example 2 with Sk

use of catdata.aql.exp.InstExpRaw.Sk in project fql by CategoricalData.

the class TransExpRaw method eval.

@Override
public synchronized Transform<Ty, En, Sym, Fk, Att, Gen, Sk, Gen, Sk, String, String, String, String> eval(AqlEnv env) {
    Instance<Ty, En, Sym, Fk, Att, Gen, Sk, String, String> src0 = src.eval(env);
    Instance<Ty, En, Sym, Fk, Att, Gen, Sk, String, String> dst0 = dst.eval(env);
    // Collage<String, String, String, String, String, Void, Void> scol = new Collage<>(src0);
    Collage<Ty, En, Sym, Fk, Att, Gen, Sk> dcol = new Collage<>(dst0.collage());
    Map<Gen, Term<Void, En, Void, Fk, Void, Gen, Void>> gens0 = new HashMap<>();
    Map<Sk, Term<Ty, En, Sym, Fk, Att, Gen, Sk>> sks0 = new HashMap<>();
    for (String k : imports) {
        @SuppressWarnings("unchecked") Transform<Ty, En, Sym, Fk, Att, Gen, Sk, Gen, Sk, String, String, String, String> v = env.defs.trans.get(k);
        Util.putAllSafely(gens0, v.gens().map);
        Util.putAllSafely(sks0, v.sks().map);
    }
    for (Pair<String, RawTerm> gen : gens) {
        try {
            RawTerm term = gen.second;
            Map<String, Chc<Ty, En>> ctx = new HashMap<>();
            Chc<Ty, En> required;
            if (src0.gens().containsKey(new Gen(gen.first)) && src0.sks().containsKey(new Sk(gen.first))) {
                throw new RuntimeException(gen.first + " is ambiguous");
            } else if (src0.gens().containsKey(new Gen(gen.first))) {
                required = Chc.inRight(src0.gens().get(new Gen(gen.first)));
            } else if (src0.sks().containsKey(new Sk(gen.first))) {
                required = Chc.inLeft(src0.sks().get(new Sk(gen.first)));
            } else {
                throw new RuntimeException(gen.first + " is not a source generator/labelled null");
            }
            Term<Ty, En, Sym, Fk, Att, Gen, Sk> term0 = RawTerm.infer1x(ctx, term, null, required, dcol, "", src0.schema().typeSide.js).second;
            if (required.left) {
                Util.putSafely(sks0, new Sk(gen.first), term0.convert());
            } else {
                Util.putSafely(gens0, new Gen(gen.first), term0.convert());
            }
        } catch (RuntimeException ex) {
            ex.printStackTrace();
            throw new LocException(find("generators", gen), "In transform for " + gen.first + ", " + ex.getMessage());
        }
    }
    AqlOptions ops = new AqlOptions(options, null, env.defaults);
    LiteralTransform<Ty, En, Sym, Fk, Att, Gen, Sk, Gen, Sk, String, String, String, String> ret = new LiteralTransform<Ty, En, Sym, Fk, Att, Gen, Sk, Gen, Sk, String, String, String, String>(gens0, sks0, src0, dst0, (Boolean) ops.getOrDefault(AqlOption.dont_validate_unsafe));
    return ret;
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) HashMap(java.util.HashMap) En(catdata.aql.exp.SchExpRaw.En) Ty(catdata.aql.exp.TyExpRaw.Ty) Fk(catdata.aql.exp.SchExpRaw.Fk) Sym(catdata.aql.exp.TyExpRaw.Sym) RawTerm(catdata.aql.RawTerm) Term(catdata.aql.Term) RawTerm(catdata.aql.RawTerm) LiteralTransform(catdata.aql.fdm.LiteralTransform) Gen(catdata.aql.exp.InstExpRaw.Gen) Sk(catdata.aql.exp.InstExpRaw.Sk) AqlOptions(catdata.aql.AqlOptions) Collage(catdata.aql.Collage) Chc(catdata.Chc)

Example 3 with Sk

use of catdata.aql.exp.InstExpRaw.Sk in project fql by CategoricalData.

the class ColimSchExpModify method eval.

// TODO aql add options
@Override
public ColimitSchema<N> eval(AqlEnv env) {
    boolean checkJava = !(Boolean) env.defaults.getOrDefault(options, AqlOption.allow_java_eqs_unsafe);
    ColimitSchema<N> colim0 = colim.eval(env);
    // colim0.schemaStr.co
    for (Pair<String, String> k : ens) {
        colim0 = colim0.renameEntity(new En(k.first), new En(k.second), checkJava);
    }
    for (Pair<Pair<String, String>, String> k : fks0) {
        colim0 = colim0.renameFk(new Fk(new En(k.first.first), k.first.second), new Fk(new En(k.first.first), k.second), checkJava);
    }
    for (Pair<Pair<String, String>, String> k : atts0) {
        colim0 = colim0.renameAtt(new Att(new En(k.first.first), k.first.second), new Att(new En(k.first.first), k.second), checkJava);
    }
    for (Pair<Pair<String, String>, List<String>> k : fks) {
        if (!colim0.schemaStr.fks.containsKey(new Fk(new En(k.first.first), k.first.second))) {
            throw new RuntimeException("Not an fk: " + k.first + " in\n\n" + colim0.schemaStr);
        }
        String pre = "In processing " + k.first + " -> " + k.second + ", ";
        Collage<Ty, En, Sym, Fk, Att, Void, Void> xxx = colim0.schemaStr.collage();
        RawTerm term = RawTerm.fold(k.second, "v");
        En tr = colim0.schemaStr.fks.get(new Fk(new En(k.first.first), k.first.second)).second;
        Ctx<String, Chc<Ty, En>> ctx = new Ctx<>("v", Chc.inRight(new En(k.first.first)));
        Term<Ty, En, Sym, Fk, Att, Gen, Sk> t = RawTerm.infer1x(ctx.map, term, null, Chc.inRight(tr), xxx.convert(), pre, colim0.schemaStr.typeSide.js).second;
        // colim0 = colim0.removeAtt(new Att(k.first), new Var(k.second.first), t.convert(), checkJava);
        colim0 = colim0.removeFk(new Fk(new En(k.first.first), k.first.second), t.toFkList(), checkJava);
    }
    for (Pair<Pair<String, String>, Triple<String, String, RawTerm>> k : atts) {
        if (!colim0.schemaStr.atts.containsKey(new Att(new En(k.first.first), k.first.second))) {
            throw new RuntimeException("Not an attribute: " + k.first + " in\n\n" + colim0.schemaStr);
        }
        String pre = "In processing " + k.first + " -> lambda " + k.second.first + "." + k.second.third + ", ";
        Pair<En, Ty> r = colim0.schemaStr.atts.get(new Att(new En(k.first.first), k.first.second));
        if (k.second.second != null && !k.second.second.equals(r.first)) {
            throw new RuntimeException(pre + " given type is " + k.second.second + " but expected " + r.first);
        }
        Collage<Ty, En, Sym, Fk, Att, Void, Void> xxx = colim0.schemaStr.collage();
        Ctx<String, Chc<Ty, En>> ctx = new Ctx<>(k.second.first, Chc.inRight(r.first));
        Term<Ty, En, Sym, Fk, Att, Gen, Sk> t = RawTerm.infer1x(ctx.map, k.second.third, null, Chc.inLeft(r.second), xxx.convert(), pre, colim0.schemaStr.typeSide.js).second;
        colim0 = colim0.removeAtt(new Att(new En(k.first.first), k.first.second), new Var(k.second.first), t.convert(), checkJava);
    }
    return colim0;
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) Ctx(catdata.Ctx) Var(catdata.aql.Var) En(catdata.aql.exp.SchExpRaw.En) LinkedList(java.util.LinkedList) List(java.util.List) Pair(catdata.Pair) Fk(catdata.aql.exp.SchExpRaw.Fk) Ty(catdata.aql.exp.TyExpRaw.Ty) Sym(catdata.aql.exp.TyExpRaw.Sym) RawTerm(catdata.aql.RawTerm) Triple(catdata.Triple) Gen(catdata.aql.exp.InstExpRaw.Gen) Sk(catdata.aql.exp.InstExpRaw.Sk) Chc(catdata.Chc)

Example 4 with Sk

use of catdata.aql.exp.InstExpRaw.Sk in project fql by CategoricalData.

the class RawTerm method toHeadNoPrim.

// @SuppressWarnings("unchecked")
// only used for precedences with aql options
public static Head<Ty, En, Sym, Fk, Att, Gen, Sk> toHeadNoPrim(String head, Collage<Ty, En, Sym, Fk, Att, Gen, Sk> col) {
    Util.assertNotNull(head);
    Util.assertNotNull(col);
    assertUnambig(head, col);
    if (col.syms.containsKey(new Sym(head))) {
        return Head.Sym(new Sym(head));
    } else if (col.gens.containsKey(new Gen(head))) {
        return Head.Gen(new Gen(head));
    } else if (col.sks.containsKey(new Sk(head))) {
        return Head.Sk(new Sk(head));
    }
    for (En en : col.ens) {
        // TODO aql won't work with ambig
        if (col.fks.containsKey(new Fk(en, head))) {
            return Head.Fk(new Fk(en, head));
        }
        if (col.atts.containsKey(new Att(en, head))) {
            return Head.Att(new Att(en, head));
        }
    }
    throw new RuntimeException("Anomaly: please report");
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) Gen(catdata.aql.exp.InstExpRaw.Gen) Fk(catdata.aql.exp.SchExpRaw.Fk) Sym(catdata.aql.exp.TyExpRaw.Sym) Sk(catdata.aql.exp.InstExpRaw.Sk) En(catdata.aql.exp.SchExpRaw.En)

Example 5 with Sk

use of catdata.aql.exp.InstExpRaw.Sk in project fql by CategoricalData.

the class RawTerm method infer_good.

private static Set<Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>>> infer_good(RawTerm e, Chc<Ty, En> expected, Collage<Ty, En, Sym, Fk, Att, Gen, Sk> col, String pre, AqlJs<Ty, Sym> js, Map<Var, Chc<Ty, En>> vars) {
    if (e.annotation != null && !col.tys.contains(new Ty(e.annotation))) {
        throw new RuntimeException(pre + "Annotation " + e.annotation + " is not a type (" + col.tys + ").");
    }
    Set<Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>>> ret = new HashSet<>();
    if (vars.keySet().contains(new Var((String) e.head)) && e.annotation == null) {
        Term<Ty, En, Sym, Fk, Att, Gen, Sk> ret1 = Term.Var(new Var((String) e.head));
        if (expected != null) {
            Ctx<Var, Chc<Ty, En>> ret2 = new Ctx<>();
            ret2.put(new Var((String) e.head), expected);
            if (ret2.agreeOnOverlap(Ctx.fromNullable(vars))) {
                ret.add(new Triple<>(ret1, ret2, expected));
            }
        } else {
            for (En en : col.ens) {
                Ctx<Var, Chc<Ty, En>> ret2 = new Ctx<>();
                ret2.put(new Var((String) e.head), Chc.inRight(en));
                if (ret2.agreeOnOverlap(Ctx.fromNullable(vars))) {
                    ret.add(new Triple<>(ret1, ret2, Chc.inRight(en)));
                }
            }
            for (Ty ty : col.tys) {
                Ctx<Var, Chc<Ty, En>> ret2 = new Ctx<>();
                if (ret2.agreeOnOverlap(Ctx.fromNullable(vars))) {
                    ret2.put(new Var((String) e.head), Chc.inLeft(ty));
                }
                ret.add(new Triple<>(ret1, ret2, Chc.inLeft(ty)));
            }
        }
    }
    if (col.syms.containsKey(new Sym(e.head)) && e.annotation == null) {
        // //System.out.println("a " + e);
        List<List<Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>>>> l = new LinkedList<>();
        l.add(new LinkedList<>());
        for (int i = 0; i < e.args.size(); i++) {
            RawTerm arg = e.args.get(i);
            // //System.out.println("arg " + arg);
            Ty ty = col.syms.get(new Sym(e.head)).first.get(i);
            Set<Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>>> z = infer_good(arg, Chc.inLeft(ty), col, pre, js, vars);
            List<List<Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>>>> l2 = new LinkedList<>();
            for (List<Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>>> old : l) {
                // //System.out.println("old " + old);
                for (Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>> y : z) {
                    if (y.third.equals(Chc.inLeft(ty))) {
                        // //System.out.println("z z");
                        l2.add(Util.append(old, Util.singList(y)));
                    }
                }
            }
            l = l2;
        }
        outer: for (List<Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>>> outcome : l) {
            // //System.out.println("outcome " + outcome);
            List<Term<Ty, En, Sym, Fk, Att, Gen, Sk>> w = outcome.stream().map(x -> x.first).collect(Collectors.toList());
            Term<Ty, En, Sym, Fk, Att, Gen, Sk> ret1 = Term.Sym(new Sym(e.head), w);
            Ctx<Var, Chc<Ty, En>> ret2 = new Ctx<>();
            for (Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>> ctx0 : outcome) {
                if (!ctx0.second.agreeOnOverlap(ret2) || !ctx0.second.agreeOnOverlap(Ctx.fromNullable(vars))) {
                    // //System.out.println("xxx ");
                    continue outer;
                }
                // //System.out.println("yyy");
                ret2.map.putAll(ctx0.second.map);
            }
            for (int i = 0; i < e.args.size(); i++) {
                RawTerm arg = e.args.get(i);
                // //System.out.println("2arx " + arg);
                Chc<Ty, En> ty = Chc.inLeft(col.syms.get(new Sym(e.head)).first.get(i));
                Var v = new Var((String) arg.head);
                if (vars.keySet().contains(v)) {
                    // //System.out.println("a " + v);
                    if (ret2.containsKey(v) && !ret2.get(v).equals(ty)) {
                        // //System.out.println("b " + v);
                        continue;
                    } else if (!ret2.containsKey(v)) {
                        // //System.out.println("c " + v);
                        ret2.put(new Var(e.args.get(i).head), ty);
                    }
                }
            }
            Chc<Ty, En> ret3 = Chc.inLeft(col.syms.get(new Sym(e.head)).second);
            if (expected != null && !expected.equals(ret3)) {
            // //System.out.println("d " );
            } else {
                // //System.out.println("e " );
                if (ret2.agreeOnOverlap(Ctx.fromNullable(vars))) {
                    ret.add(new Triple<>(ret1, ret2, ret3));
                }
            }
        }
    }
    for (En en : col.ens) {
        if (col.fks.containsKey(new Fk(en, e.head)) && e.args.size() == 1 && e.annotation == null) {
            for (Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>> outcome : infer_good(e.args.get(0), Chc.inRight(col.fks.get(new Fk(en, e.head)).first), col, pre, js, vars)) {
                Term<Ty, En, Sym, Fk, Att, Gen, Sk> ret1 = Term.Fk(new Fk(en, e.head), outcome.first);
                // System.out.println("trying " + en + " and " + e.head);
                Ctx<Var, Chc<Ty, En>> ret2 = new Ctx<>(outcome.second.map);
                Var v = new Var(e.args.get(0).head);
                Chc<Ty, En> ty = Chc.inRight(col.fks.get(new Fk(en, e.head)).first);
                if (vars.keySet().contains(v)) {
                    if (ret2.containsKey(v) && !ret2.get(v).equals(ty)) {
                        // System.out.println("no1");
                        continue;
                    } else if (!ret2.containsKey(v)) {
                        ret2.put(new Var(e.args.get(0).head), ty);
                    }
                }
                Chc<Ty, En> ret3 = Chc.inRight(col.fks.get(new Fk(en, e.head)).second);
                Chc<Ty, En> argt = Chc.inRight(col.fks.get(new Fk(en, e.head)).first);
                if (expected != null && !expected.equals(ret3)) {
                } else {
                    if (argt.equals(outcome.third)) {
                        if (ret2.agreeOnOverlap(Ctx.fromNullable(vars))) {
                            ret.add(new Triple<>(ret1, ret2, ret3));
                        } else {
                        // System.out.println("b3");
                        }
                    } else {
                    // System.out.println("c3");
                    }
                }
            }
        }
        if (col.atts.containsKey(new Att(en, e.head)) && e.args.size() == 1 && e.annotation == null) {
            // System.out.println("x " + e);
            for (Triple<Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Ctx<Var, Chc<Ty, En>>, Chc<Ty, En>> outcome : infer_good(e.args.get(0), Chc.inRight(col.atts.get(new Att(en, e.head)).first), col, pre, js, vars)) {
                // System.out.println("y " + outcome);
                Term<Ty, En, Sym, Fk, Att, Gen, Sk> ret1 = Term.Att(new Att(en, e.head), outcome.first);
                Ctx<Var, Chc<Ty, En>> ret2 = new Ctx<>(outcome.second.map);
                Var v = new Var(e.args.get(0).head);
                Chc<Ty, En> ty = Chc.inRight(col.atts.get(new Att(en, e.head)).first);
                if (vars.keySet().contains(v)) {
                    if (ret2.containsKey(v) && !ret2.get(v).equals(ty)) {
                        continue;
                    } else if (!ret2.containsKey(v)) {
                        // System.out.println("b " + v);
                        ret2.put(v, ty);
                    }
                }
                Chc<Ty, En> ret3 = Chc.inLeft(col.atts.get(new Att(en, e.head)).second);
                Chc<Ty, En> argt = Chc.inRight(col.atts.get(new Att(en, e.head)).first);
                if (expected != null && !expected.equals(ret3)) {
                // System.out.println("d " + v);
                } else {
                    // System.out.println("e " + v);
                    if (argt.equals(outcome.third)) {
                        // System.out.println("f " + v);
                        if (ret2.agreeOnOverlap(Ctx.fromNullable(vars))) {
                            ret.add(new Triple<>(ret1, ret2, ret3));
                        }
                    }
                }
            }
        }
    }
    if (col.gens.containsKey(new Gen(e.head)) && e.args.isEmpty() && e.annotation == null) {
        Term<Ty, En, Sym, Fk, Att, Gen, Sk> ret1 = Term.Gen(new Gen(e.head));
        Chc<Ty, En> ret3 = Chc.inRight(col.gens.get(new Gen(e.head)));
        if (expected != null && !expected.equals(ret3)) {
        } else {
            ret.add(new Triple<>(ret1, new Ctx<>(), ret3));
        }
    }
    if (col.sks.containsKey(new Sk(e.head)) && e.args.isEmpty() && e.annotation == null) {
        Term<Ty, En, Sym, Fk, Att, Gen, Sk> ret1 = Term.Sk(new Sk(e.head));
        Chc<Ty, En> ret3 = Chc.inLeft(col.sks.get(new Sk(e.head)));
        if (expected != null && !expected.equals(ret3)) {
        } else {
            ret.add(new Triple<>(ret1, new Ctx<>(), ret3));
        }
    }
    if (e.args.isEmpty() && e.annotation != null) {
        Ty ty = new Ty(e.annotation);
        Term<Ty, En, Sym, Fk, Att, Gen, Sk> ret1 = Term.Obj(js.parse(ty, e.head), ty);
        Chc<Ty, En> ret3 = Chc.inLeft(ty);
        if (expected != null && !expected.equals(ret3)) {
        } else {
            ret.add(new Triple<>(ret1, new Ctx<>(), ret3));
        }
    }
    // as primitive - only if not a variable/generator/etc in scope i.e. none above fired
    if (e.args.isEmpty() && e.annotation == null && ret.isEmpty()) {
        for (Ty ty : col.tys) {
            if (expected != null && !expected.equals(Chc.inLeft(ty))) {
                continue;
            }
            try {
                Term<Ty, En, Sym, Fk, Att, Gen, Sk> ret1 = Term.Obj(js.parse(ty, e.head), ty);
                Chc<Ty, En> ret3 = Chc.inLeft(ty);
                if (expected != null && !expected.equals(ret3)) {
                // System.out.println("zzz");
                } else {
                    ret.add(new Triple<>(ret1, new Ctx<>(), ret3));
                // System.out.println("added " + ret + " and " + ret3);
                }
            } catch (Exception ex) {
                if (expected != null) {
                    ex.printStackTrace();
                // throw ex;
                }
            // //ex.printStackTrace();
            }
        }
    }
    return ret;
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) Ctx(catdata.Ctx) En(catdata.aql.exp.SchExpRaw.En) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Ty(catdata.aql.exp.TyExpRaw.Ty) Fk(catdata.aql.exp.SchExpRaw.Fk) Sym(catdata.aql.exp.TyExpRaw.Sym) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Gen(catdata.aql.exp.InstExpRaw.Gen) Sk(catdata.aql.exp.InstExpRaw.Sk) Chc(catdata.Chc)

Aggregations

Gen (catdata.aql.exp.InstExpRaw.Gen)11 Sk (catdata.aql.exp.InstExpRaw.Sk)11 Att (catdata.aql.exp.SchExpRaw.Att)11 En (catdata.aql.exp.SchExpRaw.En)11 Fk (catdata.aql.exp.SchExpRaw.Fk)11 Sym (catdata.aql.exp.TyExpRaw.Sym)11 Ty (catdata.aql.exp.TyExpRaw.Ty)10 Ctx (catdata.Ctx)9 Chc (catdata.Chc)8 RawTerm (catdata.aql.RawTerm)8 Pair (catdata.Pair)7 AqlOptions (catdata.aql.AqlOptions)7 Collage (catdata.aql.Collage)7 Term (catdata.aql.Term)7 HashSet (java.util.HashSet)6 Triple (catdata.Triple)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 Var (catdata.aql.Var)4 It (catdata.aql.It)3