Search in sources :

Example 1 with FullSigmaCounit

use of catdata.fql.sql.FullSigmaCounit in project fql by CategoricalData.

the class InstOps method visit.

@Override
public List<PSM> visit(String env, Coreturn e) {
    String xxx = "coreturn_temp_xxx";
    List<PSM> ret = new LinkedList<>();
    InstExp i1 = prog.insts.get(e.inst);
    if (i1 instanceof Sigma) {
        String middle = ((Sigma) i1).I;
        // can't be null
        InstExp i2 = prog.insts.get(middle);
        Mapping f = ((Sigma) i1).F.toMap(prog);
        if (i2 instanceof Delta) {
            for (Node n : f.target.nodes) {
                List<Flower> u = new LinkedList<>();
                for (Node m : f.source.nodes) {
                    if (!f.nm.get(m).equals(n)) {
                        continue;
                    }
                    u.add(new CopyFlower(middle + "_" + m.string + "_subst_inv", "c0", "c1"));
                }
                ret.add(new SimpleCreateTable(xxx, PSM.VARCHAR(), false));
                ret.add(new InsertSQL(xxx, new Union(u), "c0", "c1"));
                ret.add(new InsertSQL(env + "_" + n.string, PSMGen.compose(e.inst + "_" + n.string + "_subst_inv", xxx), "c0", "c1"));
                ret.add(new DropTable(xxx));
            }
        }
    } else if (i1 instanceof FullSigma) {
        String middle = ((FullSigma) i1).I;
        // can't be null
        InstExp i2 = prog.insts.get(middle);
        Mapping f = ((FullSigma) i1).F.toMap(prog);
        if (i2 instanceof Delta) {
            ret.add(new FullSigmaCounit(f, ((Delta) i2).I, middle, e.inst, env));
        } else {
            throw new RuntimeException();
        }
    } else if (i1 instanceof Delta) {
        String middle = ((Delta) i1).I;
        // can't be null
        InstExp i2 = prog.insts.get(middle);
        Mapping f = ((Delta) i1).F.toMap(prog);
        if (i2 instanceof Pi) {
            Pi input0 = ((Pi) i2);
            String input = input0.I;
            try {
                Map<String, Triple<Node, Node, Arr<Node, Path>>[]> colmap = PSMGen.pi(f, input, middle).second;
                for (Node m : f.source.nodes) {
                    Node n = f.nm.get(m);
                    Triple<Node, Node, Arr<Node, Path>>[] col = colmap.get(n.string);
                    Triple<Node, Node, Arr<Node, Path>> toFind = new Triple<>(n, m, new Arr<>(new Path(f.target, n), n, n));
                    int i = 0;
                    boolean found = false;
                    for (Triple<Node, Node, Arr<Node, Path>> cand : col) {
                        if (cand.equals(toFind)) {
                            found = true;
                            Map<String, String> from = new HashMap<>();
                            from.put("lim", middle + "_" + n + "_limit");
                            LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
                            select.put("c0", new Pair<>("lim", "guid"));
                            select.put("c1", new Pair<>("lim", "c" + i));
                            List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
                            Flower flower = new Flower(select, from, where);
                            ret.add(new SimpleCreateTable(xxx, PSM.VARCHAR(), false));
                            ret.add(new InsertSQL(xxx, flower, "c0", "c1"));
                            ret.add(new InsertSQL(env + "_" + m, PSMGen.compose(e.inst + "_" + m + "_subst_inv", xxx), "c0", "c1"));
                            ret.add(new DropTable(xxx));
                            break;
                        }
                        i++;
                    }
                    if (!found) {
                        throw new RuntimeException();
                    }
                }
            } catch (FQLException fe) {
                fe.printStackTrace();
                throw new RuntimeException(fe.getMessage());
            }
        } else {
            throw new RuntimeException();
        }
    } else {
        throw new RuntimeException();
    }
    return ret;
}
Also used : Arr(catdata.fql.cat.Arr) CopyFlower(catdata.fql.sql.CopyFlower) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FullSigma(catdata.fql.decl.InstExp.FullSigma) Sigma(catdata.fql.decl.InstExp.Sigma) DropTable(catdata.fql.sql.DropTable) Union(catdata.fql.sql.Union) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) Pi(catdata.fql.decl.InstExp.Pi) Pair(catdata.Pair) FullSigmaCounit(catdata.fql.sql.FullSigmaCounit) CopyFlower(catdata.fql.sql.CopyFlower) Flower(catdata.fql.sql.Flower) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList) Triple(catdata.Triple) InsertSQL(catdata.fql.sql.InsertSQL) Delta(catdata.fql.decl.InstExp.Delta) FullSigma(catdata.fql.decl.InstExp.FullSigma)

Aggregations

Pair (catdata.Pair)1 Triple (catdata.Triple)1 FQLException (catdata.fql.FQLException)1 Arr (catdata.fql.cat.Arr)1 Delta (catdata.fql.decl.InstExp.Delta)1 FullSigma (catdata.fql.decl.InstExp.FullSigma)1 Pi (catdata.fql.decl.InstExp.Pi)1 Sigma (catdata.fql.decl.InstExp.Sigma)1 CopyFlower (catdata.fql.sql.CopyFlower)1 DropTable (catdata.fql.sql.DropTable)1 ExpPSM (catdata.fql.sql.ExpPSM)1 Flower (catdata.fql.sql.Flower)1 FullSigmaCounit (catdata.fql.sql.FullSigmaCounit)1 InsertSQL (catdata.fql.sql.InsertSQL)1 PSM (catdata.fql.sql.PSM)1 PropPSM (catdata.fql.sql.PropPSM)1 SimpleCreateTable (catdata.fql.sql.SimpleCreateTable)1 Union (catdata.fql.sql.Union)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1