Search in sources :

Example 11 with Times

use of catdata.fql.decl.InstExp.Times in project fql by CategoricalData.

the class InstOps method visit.

@Override
public List<PSM> visit(String env, Implies e) {
    List<PSM> ret = new LinkedList<>();
    Times pr = (Times) prog.insts.get(e.prop);
    Signature sig = pr.type(prog).toSig(prog);
    ret.add(new PSMAnd(sig, env, e.prop, pr.a, "implies"));
    return ret;
}
Also used : PSMAnd(catdata.fql.sql.PSMAnd) Times(catdata.fql.decl.InstExp.Times) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 12 with Times

use of catdata.fql.decl.InstExp.Times in project fql by CategoricalData.

the class InstOps method visit.

@Override
public List<PSM> visit(String env, And e) {
    List<PSM> ret = new LinkedList<>();
    Times pr = (Times) prog.insts.get(e.prop);
    Signature sig = pr.type(prog).toSig(prog);
    ret.add(new PSMAnd(sig, env, e.prop, pr.a, "and"));
    return ret;
}
Also used : PSMAnd(catdata.fql.sql.PSMAnd) Times(catdata.fql.decl.InstExp.Times) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 13 with Times

use of catdata.fql.decl.InstExp.Times in project fql by CategoricalData.

the class InstOps method visit.

@Override
public Pair<List<PSM>, Object> visit(String dst, Times e) {
    try {
        SigExp k = e.type(prog);
        Signature s = k.toSig(prog);
        List<PSM> ret = new LinkedList<>();
        ret.addAll(PSMGen.makeTables(dst + "_fst", s, false));
        ret.addAll(PSMGen.makeTables(dst + "_snd", s, false));
        Pair<Map<Node, List<Pair<Path, Attribute<Node>>>>, List<PSM>> l_obs = Relationalizer.observations(s, dst + "_l_obs", e.a, false);
        Pair<Map<Node, List<Pair<Path, Attribute<Node>>>>, List<PSM>> r_obs = Relationalizer.observations(s, dst + "_r_obs", e.b, false);
        if (!(l_obs.first.equals(r_obs.first))) {
            throw new RuntimeException("Internal error, please report.");
        }
        ret.addAll(PSMGen.makeTables(dst + "_l_obs", s, false));
        ret.addAll(l_obs.second);
        ret.addAll(PSMGen.dropTables(dst + "_l_obs", s));
        ret.addAll(PSMGen.makeTables(dst + "_r_obs", s, false));
        ret.addAll(r_obs.second);
        ret.addAll(PSMGen.dropTables(dst + "_r_obs", s));
        for (Node n : s.nodes) {
            List<Pair<Path, Attribute<Node>>> lats = l_obs.first.get(n);
            // List<Pair<Path, Attribute<Node>>> rats = r_obs.first.get(n);
            LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
            Map<String, String> from = new HashMap<>();
            List<String> attrs = new LinkedList<>();
            Map<String, String> attrsM = new HashMap<>();
            List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
            from.put("lft", dst + "_l_obs_" + n.string + "_observables");
            from.put("rght", dst + "_r_obs_" + n.string + "_observables");
            attrs.add("lft");
            attrs.add("rght");
            attrsM.put("lft", PSM.VARCHAR());
            attrsM.put("rght", PSM.VARCHAR());
            select.put("lft", new Pair<>("lft", "id"));
            select.put("rght", new Pair<>("rght", "id"));
            int idx = 0;
            for (Pair<Path, Attribute<Node>> aa : lats) {
                Attribute<Node> a = aa.second;
                where.add(new Pair<>(new Pair<>("lft", "c" + idx), new Pair<>("rght", "c" + idx)));
                select.put("c" + idx, new Pair<>("lft", "c" + idx));
                attrs.add("c" + idx);
                attrsM.put("c" + idx, a.target.psm());
                idx++;
            }
            Flower f = new Flower(select, from, where);
            ret.add(new CreateTable(dst + "_prod_temp_" + n.string, attrsM, false));
            ret.add(new InsertSQL2(dst + "_prod_temp_" + n.string, f, attrs));
            Map<String, String> attrsM0 = new HashMap<>(attrsM);
            attrsM0.put("gguid", PSM.VARCHAR());
            ret.add(new CreateTable(dst + "_prod_guid_" + n.string, attrsM0, false));
            ret.add(new InsertKeygen(dst + "_prod_guid_" + n.string, "gguid", dst + "_prod_temp_" + n.string, attrs));
            List<Pair<Pair<String, String>, Pair<String, String>>> where0 = new LinkedList<>();
            from = new HashMap<>();
            from.put("t", dst + "_prod_guid_" + n.string);
            select = new LinkedHashMap<>();
            select.put("c0", new Pair<>("t", "gguid"));
            select.put("c1", new Pair<>("t", "lft"));
            f = new Flower(select, from, where0);
            ret.add(new InsertSQL(dst + "_fst_" + n, f, "c0", "c1"));
            from = new HashMap<>();
            from.put("t", dst + "_prod_guid_" + n.string);
            select = new LinkedHashMap<>();
            select.put("c0", new Pair<>("t", "gguid"));
            select.put("c1", new Pair<>("t", "rght"));
            f = new Flower(select, from, where0);
            ret.add(new InsertSQL(dst + "_snd_" + n, f, "c0", "c1"));
            LinkedHashMap<String, Pair<String, String>> select0 = new LinkedHashMap<>();
            select0.put("c0", new Pair<>("t", "gguid"));
            select0.put("c1", new Pair<>("t", "gguid"));
            Map<String, String> from0 = new HashMap<>();
            from0.put("t", dst + "_prod_guid_" + n.string);
            Flower sql = new Flower(select0, from0, where0);
            ret.add(new InsertSQL(dst + "_" + n.string, sql, "c0", "c1"));
            for (Attribute<Node> a : s.attrsFor(n)) {
                select0 = new LinkedHashMap<>();
                select0.put("c0", new Pair<>("t", "gguid"));
                Arr<Node, Path> ppp = s.toCategory2().first.id(n);
                int ppp0 = lats.indexOf(new Pair<>(ppp.arr, a));
                select0.put("c1", new Pair<>("t", "c" + ppp0));
                from0 = new HashMap<>();
                from0.put("t", dst + "_prod_guid_" + n.string);
                sql = new Flower(select0, from0, where0);
                ret.add(new InsertSQL(dst + "_" + a.name, sql, "c0", "c1"));
            }
        // ret.add(new DropTable(dst + "_prod_temp_" + n));
        }
        for (Edge edge : s.edges) {
            Map<String, String> from = new HashMap<>();
            from.put("leftEdge", e.a + "_" + edge.name);
            from.put("rightEdge", e.b + "_" + edge.name);
            from.put("srcGuid", dst + "_prod_guid_" + edge.source);
            from.put("dstGuid", dst + "_prod_guid_" + edge.target);
            List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
            where.add(new Pair<>(new Pair<>("leftEdge", "c0"), new Pair<>("srcGuid", "lft")));
            where.add(new Pair<>(new Pair<>("rightEdge", "c0"), new Pair<>("srcGuid", "rght")));
            where.add(new Pair<>(new Pair<>("leftEdge", "c1"), new Pair<>("dstGuid", "lft")));
            where.add(new Pair<>(new Pair<>("rightEdge", "c1"), new Pair<>("dstGuid", "rght")));
            LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
            select.put("c0", new Pair<>("srcGuid", "gguid"));
            select.put("c1", new Pair<>("dstGuid", "gguid"));
            Flower f = new Flower(select, from, where);
            ret.add(new InsertSQL(dst + "_" + edge.name, f, "c0", "c1"));
        }
        Fn<Quad<String, String, String, String>, List<PSM>> fn = x -> {
            // x.third -> e.a
            String f = x.first;
            // x.third -> e.b
            String g = x.second;
            // String C = x.third;
            String dst0 = x.fourth;
            // must be a map x.third -> dst
            List<PSM> ret1 = new LinkedList<>();
            for (Node n : s.nodes) {
                List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
                Map<String, String> from = new HashMap<>();
                from.put("f", f + "_" + n.string);
                from.put("g", g + "_" + n.string);
                from.put("lim", dst + "_prod_guid_" + n.string);
                where.add(new Pair<>(new Pair<>("f", "c0"), new Pair<>("g", "c0")));
                where.add(new Pair<>(new Pair<>("lim", "lft"), new Pair<>("f", "c1")));
                where.add(new Pair<>(new Pair<>("lim", "rght"), new Pair<>("g", "c1")));
                LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
                select.put("c0", new Pair<>("f", "c0"));
                select.put("c1", new Pair<>("lim", "gguid"));
                Flower flower = new Flower(select, from, where);
                ret1.add(new InsertSQL(dst0 + "_" + n.string, flower, "c0", "c1"));
            }
            return ret1;
        };
        return new Pair<>(ret, fn);
    } catch (FQLException fe) {
        throw new RuntimeException(fe.getLocalizedMessage());
    }
}
Also used : Inr(catdata.fql.decl.TransExp.Inr) Case(catdata.fql.decl.TransExp.Case) TransEval(catdata.fql.decl.TransExp.TransEval) Snd(catdata.fql.decl.TransExp.Snd) TransIso(catdata.fql.decl.TransExp.TransIso) Kernel(catdata.fql.decl.InstExp.Kernel) TransCurry(catdata.fql.decl.TransExp.TransCurry) Inl(catdata.fql.decl.TransExp.Inl) Coreturn(catdata.fql.decl.TransExp.Coreturn) PSMStep(catdata.fql.sql.PSMStep) CopyFlower(catdata.fql.sql.CopyFlower) Map(java.util.Map) Or(catdata.fql.decl.TransExp.Or) Squash(catdata.fql.decl.TransExp.Squash) TT(catdata.fql.decl.TransExp.TT) And(catdata.fql.decl.TransExp.And) Exp(catdata.fql.decl.InstExp.Exp) Fn(catdata.fql.Fn) Pair(catdata.Pair) Not(catdata.fql.decl.TransExp.Not) FullSigma(catdata.fql.decl.InstExp.FullSigma) PSMAnd(catdata.fql.sql.PSMAnd) Plus(catdata.fql.decl.InstExp.Plus) Quad(catdata.Quad) FullSigmaCounit(catdata.fql.sql.FullSigmaCounit) PropPSM(catdata.fql.sql.PropPSM) FullEval(catdata.fql.decl.InstExp.FullEval) Set(java.util.Set) PSMGen(catdata.fql.sql.PSMGen) FullQueryVisitor(catdata.fql.decl.FullQuery.FullQueryVisitor) Eval(catdata.fql.decl.InstExp.Eval) InsertSQL2(catdata.fql.sql.InsertSQL2) PSMUnChi(catdata.fql.sql.PSMUnChi) Times(catdata.fql.decl.InstExp.Times) Fst(catdata.fql.decl.TransExp.Fst) PSMNot(catdata.fql.sql.PSMNot) List(java.util.List) Delta(catdata.fql.decl.InstExp.Delta) ExpPSM(catdata.fql.sql.ExpPSM) TransExpVisitor(catdata.fql.decl.TransExp.TransExpVisitor) PSMBool(catdata.fql.sql.PSMBool) Triple(catdata.Triple) Flower(catdata.fql.sql.Flower) Implies(catdata.fql.decl.TransExp.Implies) Id(catdata.fql.decl.TransExp.Id) External(catdata.fql.decl.InstExp.External) InsertKeygen(catdata.fql.sql.InsertKeygen) Chi(catdata.fql.decl.TransExp.Chi) FullSigmaTrans(catdata.fql.sql.FullSigmaTrans) HashMap(java.util.HashMap) Var(catdata.fql.decl.TransExp.Var) SQL(catdata.fql.sql.SQL) FQLException(catdata.fql.FQLException) Two(catdata.fql.decl.InstExp.Two) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) PSM(catdata.fql.sql.PSM) FF(catdata.fql.decl.TransExp.FF) LinkedList(java.util.LinkedList) UnChi(catdata.fql.decl.TransExp.UnChi) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) Comp(catdata.fql.decl.TransExp.Comp) PSMIso(catdata.fql.sql.PSMIso) CreateTable(catdata.fql.sql.CreateTable) InsertValues(catdata.fql.sql.InsertValues) Prod(catdata.fql.decl.TransExp.Prod) Const(catdata.fql.decl.InstExp.Const) Relationalize(catdata.fql.decl.InstExp.Relationalize) PSMCurry(catdata.fql.sql.PSMCurry) One(catdata.fql.decl.InstExp.One) Zero(catdata.fql.decl.InstExp.Zero) Pi(catdata.fql.decl.InstExp.Pi) DropTable(catdata.fql.sql.DropTable) InstExpVisitor(catdata.fql.decl.InstExp.InstExpVisitor) Step(catdata.fql.decl.InstExp.Step) Arr(catdata.fql.cat.Arr) Return(catdata.fql.decl.TransExp.Return) InsertSQL(catdata.fql.sql.InsertSQL) Union(catdata.fql.sql.Union) Sigma(catdata.fql.decl.InstExp.Sigma) Bool(catdata.fql.decl.TransExp.Bool) PSMEval(catdata.fql.sql.PSMEval) Relationalizer(catdata.fql.sql.Relationalizer) PSMChi(catdata.fql.sql.PSMChi) Quad(catdata.Quad) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) CreateTable(catdata.fql.sql.CreateTable) InsertKeygen(catdata.fql.sql.InsertKeygen) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) 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) InsertSQL(catdata.fql.sql.InsertSQL) InsertSQL2(catdata.fql.sql.InsertSQL2) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with Times

use of catdata.fql.decl.InstExp.Times in project fql by CategoricalData.

the class InstOps method visit.

@Override
public List<PSM> visit(String env, TransCurry e) {
    List<PSM> ret = new LinkedList<>();
    Signature sig = prog.insts.get(e.inst).type(prog).toSig(prog);
    Pair<String, String> k = prog.transforms.get(e.trans).type(prog);
    Times t = (Times) prog.insts.get(k.first);
    ret.add(new PSMCurry(env, t.a, e.inst, e.trans, k.first, k.second, t.b, sig));
    return ret;
}
Also used : PSMCurry(catdata.fql.sql.PSMCurry) Times(catdata.fql.decl.InstExp.Times) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 15 with Times

use of catdata.fql.decl.InstExp.Times in project fql by CategoricalData.

the class FQLProgram method build.

private Graph<String, Object> build() {
    // Graph<V, E> where V is the type of the vertices
    Graph<String, Object> g2 = new DirectedSparseMultigraph<>();
    Ref<Integer> guid = new Ref<>(0);
    for (String k : insts.keySet()) {
        InstExp i = insts.get(k);
        i.type(this).toConst(this);
        g2.addVertex(k);
        i.accept(new Unit(), new InstExpVisitor<Unit, Unit>() {

            @Override
            public Unit visit(Unit env, Zero e) {
                return null;
            }

            @Override
            public Unit visit(Unit env, One e) {
                return null;
            }

            @Override
            public Unit visit(Unit env, Two e) {
                return null;
            }

            @Override
            public Unit visit(Unit env, Plus e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.a, k);
                g2.addEdge(new Pair<>(pp(guid), e), e.b, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Times e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.a, k);
                g2.addEdge(new Pair<>(pp(guid), e), e.b, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Exp e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.a, k);
                g2.addEdge(new Pair<>(pp(guid), e), e.b, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Const e) {
                return null;
            }

            @Override
            public Unit visit(Unit env, Delta e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.I, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Sigma e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.I, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Pi e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.I, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, FullSigma e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.I, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Relationalize e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.I, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, External e) {
                return null;
            }

            @Override
            public Unit visit(Unit env, Eval e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.e, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, FullEval e) {
                g2.addEdge(new Pair<>(pp(guid), e), e.e, k);
                return null;
            }

            @Override
            public Unit visit(Unit env, Kernel e) {
                TransExp t = transforms.get(e.trans);
                Pair<String, String> p = t.type(FQLProgram.this);
                g2.addEdge(new Pair<>(pp(guid), e), p.first, k);
                g2.addEdge(new Pair<>(pp(guid), e), p.second, k);
                return null;
            }

            private Integer pp(Ref<Integer> ref) {
                int ret = ref.x;
                ref.x = ret + 1;
                return ref.x;
            }

            @Override
            public Unit visit(Unit env, Step e) {
                // (Step) this should add an edge
                return null;
            }
        });
    }
    return g2;
}
Also used : FullEval(catdata.fql.decl.InstExp.FullEval) One(catdata.fql.decl.InstExp.One) FullSigma(catdata.fql.decl.InstExp.FullSigma) Sigma(catdata.fql.decl.InstExp.Sigma) Step(catdata.fql.decl.InstExp.Step) Unit(catdata.Unit) Pi(catdata.fql.decl.InstExp.Pi) Plus(catdata.fql.decl.InstExp.Plus) FullEval(catdata.fql.decl.InstExp.FullEval) Eval(catdata.fql.decl.InstExp.Eval) Kernel(catdata.fql.decl.InstExp.Kernel) Pair(catdata.Pair) Relationalize(catdata.fql.decl.InstExp.Relationalize) Zero(catdata.fql.decl.InstExp.Zero) Const(catdata.fql.decl.InstExp.Const) Two(catdata.fql.decl.InstExp.Two) Ref(catdata.Ref) Delta(catdata.fql.decl.InstExp.Delta) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Times(catdata.fql.decl.InstExp.Times) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.decl.InstExp.FullSigma) Exp(catdata.fql.decl.InstExp.Exp)

Aggregations

Times (catdata.fql.decl.InstExp.Times)16 Pair (catdata.Pair)9 InstExp (catdata.fql.decl.InstExp)9 Exp (catdata.fql.decl.InstExp.Exp)8 ExpPSM (catdata.fql.sql.ExpPSM)7 PSM (catdata.fql.sql.PSM)7 PropPSM (catdata.fql.sql.PropPSM)7 LinkedList (java.util.LinkedList)7 Two (catdata.fql.decl.InstExp.Two)6 External (catdata.fql.decl.InstExp.External)5 Kernel (catdata.fql.decl.InstExp.Kernel)5 One (catdata.fql.decl.InstExp.One)5 Delta (catdata.fql.decl.InstExp.Delta)4 Eval (catdata.fql.decl.InstExp.Eval)4 FullEval (catdata.fql.decl.InstExp.FullEval)4 FullSigma (catdata.fql.decl.InstExp.FullSigma)4 Plus (catdata.fql.decl.InstExp.Plus)4 Relationalize (catdata.fql.decl.InstExp.Relationalize)4 Step (catdata.fql.decl.InstExp.Step)4 Zero (catdata.fql.decl.InstExp.Zero)4