Search in sources :

Example 1 with FullSigma

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

the class InstOps method visit.

@Override
public List<PSM> visit(String env, Return e) {
    // String xxx = "return_temp_xxx";
    List<PSM> ret = new LinkedList<>();
    InstExp i1 = prog.insts.get(e.inst);
    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 Sigma) {
            Sigma input0 = ((Sigma) i2);
            String input = input0.I;
            for (Node n : f.source.nodes) {
                ret.add(new InsertSQL(env + "_" + n.string, PSMGen.compose(input + "_" + n.string, middle + "_" + f.nm.get(n) + "_subst", e.inst + "_" + n.string + "_subst"), "c0", "c1"));
            }
        } else if (i2 instanceof FullSigma) {
            FullSigma input0 = ((FullSigma) i2);
            String input = input0.I;
            for (Node n : f.source.nodes) {
                ret.add(new InsertSQL(env + "_" + n.string, PSMGen.compose(input + "_" + n.string, middle + "_" + n.string + "_e", e.inst + "_" + n.string + "_subst"), "c0", "c1"));
            }
        } else {
            throw new RuntimeException();
        }
    } else if (i1 instanceof Pi) {
        String middle = ((Pi) i1).I;
        // can't be null
        InstExp i2 = prog.insts.get(middle);
        Mapping f = ((Pi) i1).F.toMap(prog);
        if (i2 instanceof Delta) {
            Delta input0 = ((Delta) i2);
            String input = input0.I;
            for (Node n : f.target.nodes) {
                try {
                    Map<String, Triple<Node, Node, Arr<Node, Path>>[]> colmap = PSMGen.pi(f, middle, e.inst).second;
                    Triple<Node, Node, Arr<Node, Path>>[] col = colmap.get(n.string);
                    if (col.length == 0) {
                        LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
                        Map<String, String> from = new HashMap<>();
                        List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
                        from.put("lim", e.inst + "_" + n.string + "_limit");
                        from.put("middle", input + "_" + n.string);
                        select.put("c0", new Pair<>("middle", "c0"));
                        select.put("c1", new Pair<>("lim", "guid"));
                        Flower flower = new Flower(select, from, where);
                        ret.add(new InsertSQL(env + "_" + n.string, flower, "c0", "c1"));
                        return ret;
                    }
                    // LinkedHashMap<String, String> attrs = new LinkedHashMap<>();
                    // attrs.put("guid", PSM.VARCHAR());
                    LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
                    Map<String, String> from = new HashMap<>();
                    from.put("lim", e.inst + "_" + n.string + "_limit");
                    List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
                    int i = 0;
                    for (Triple<Node, Node, Arr<Node, Path>> col0 : col) {
                        from.put("c" + i + "_subst_inv", middle + "_" + col0.second.string + "_subst_inv");
                        where.add(new Pair<>(new Pair<>("lim", "c" + i), new Pair<>("c" + i + "_subst_inv", "c0")));
                        // attrs.put("c" + i, PSM.VARCHAR());
                        i++;
                    }
                    // if (col.length > 1) {
                    for (int j = 0; j < col.length; j++) {
                        if (col[j].third.arr.equals(f.target.toCategory2().second.of(new Path(f.target, n)).arr)) {
                            where.add(new Pair<>(new Pair<>("c" + 0 + "_subst_inv", "c1"), new Pair<>("c" + j + "_subst_inv", "c1")));
                        }
                    }
                    select.put("c" + 0, new Pair<>("c" + 0 + "_subst_inv", "c1"));
                    select.put("c1", new Pair<>("lim", "guid"));
                    // }
                    // ret.add(new CreateTable(xxx, attrs, false));
                    Flower flower = new Flower(select, from, where);
                    ret.add(new InsertSQL(env + "_" + n.string, flower, "c0", "c1"));
                } 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) FullSigma(catdata.fql.decl.InstExp.FullSigma) Sigma(catdata.fql.decl.InstExp.Sigma) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Pi(catdata.fql.decl.InstExp.Pi) 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) Triple(catdata.Triple) InsertSQL(catdata.fql.sql.InsertSQL) Delta(catdata.fql.decl.InstExp.Delta) FullSigma(catdata.fql.decl.InstExp.FullSigma) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with FullSigma

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

the class Driver method validateWithEds.

private static void validateWithEds(FQLProgram prog, Map<String, Instance> insts) throws FQLException {
    for (String k : prog.insts.keySet()) {
        InstExp v = prog.insts.get(k);
        if (v instanceof FullSigma) {
            FullSigma v0 = (FullSigma) v;
            Instance x = Chase.sigma(v0.F.toMap(prog), insts.get(v0.I));
            if (!Instance.quickCompare(x, insts.get(k))) {
                throw new RuntimeException("Bad sigma ED compare: ED gives\n\n" + x + "\n\nbut SIGMA gives\n\n" + insts.get(k));
            }
        }
        if (v instanceof InstExp.Sigma) {
            InstExp.Sigma v0 = (InstExp.Sigma) v;
            Instance x = Chase.sigma(v0.F.toMap(prog), insts.get(v0.I));
            if (!Instance.quickCompare(x, insts.get(k))) {
                throw new RuntimeException("Bad sigma ED compare: ED gives\n\n" + x + "\n\nbut SIGMA gives\n\n" + insts.get(k));
            }
        }
        if (v instanceof InstExp.Delta) {
            InstExp.Delta v0 = (InstExp.Delta) v;
            Instance x = Chase.delta(v0.F.toMap(prog), insts.get(v0.I));
            if (!Instance.quickCompare(x, insts.get(k))) {
                throw new RuntimeException("Bad sigma ED compare: ED gives\n\n" + x + "\n\nbut SIGMA gives\n\n" + insts.get(k));
            }
        }
    }
}
Also used : Delta(catdata.fql.decl.FullQueryExp.Delta) Sigma(catdata.fql.decl.FullQueryExp.Sigma) FullSigma(catdata.fql.decl.InstExp.FullSigma) FullSigma(catdata.fql.decl.InstExp.FullSigma)

Example 3 with FullSigma

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

the class FqlDisplay method handleInstanceFlowEdge.

private void handleInstanceFlowEdge(Object o) {
    InstExp i = (InstExp) o;
    Object f = i.accept(new Unit(), new InstExpVisitor<Object, Unit>() {

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

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

        @Override
        public MapExp visit(Unit env, Two e) {
            throw new RuntimeException();
        }

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

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

        @Override
        public MapExp visit(Unit env, Exp e) {
            throw new RuntimeException();
        }

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

        @Override
        public MapExp visit(Unit env, Delta e) {
            return e.F;
        }

        @Override
        public MapExp visit(Unit env, Sigma e) {
            return e.F;
        }

        @Override
        public MapExp visit(Unit env, Pi e) {
            return e.F;
        }

        @Override
        public MapExp visit(Unit env, FullSigma e) {
            return e.F;
        }

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

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

        @Override
        public Object visit(Unit env, Eval e) {
            return e.q;
        }

        @Override
        public Object visit(Unit env, FullEval e) {
            return e.q;
        }

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

        @Override
        public Object visit(Unit env, Step e) {
            // (Step) this should return a pair
            return null;
        }
    });
    if (f == null) {
        return;
    }
    if (f instanceof QueryExp) {
        QueryExp q = (QueryExp) f;
        if (q instanceof QueryExp.Var) {
            QueryExp.Var qq = (QueryExp.Var) q;
            yyy.setSelectedValue(indices.get(qq.v), true);
            return;
        }
        String k = FQLProgram.revLookup(prog.queries, q);
        if (k != null) {
            yyy.setSelectedValue(indices.get(k), true);
            return;
        }
        String str = q.toString();
        if (!extraInsts.contains(str)) {
            Query view = q.toQuery(prog);
            JPanel p = showQuery(prog, env, view);
            x.add(p, str);
            extraInsts.add(str);
        }
        yyy.clearSelection();
        cl.show(x, str);
    } else if (f instanceof FullQueryExp) {
        FullQueryExp q = (FullQueryExp) f;
        if (q instanceof FullQueryExp.Var) {
            FullQueryExp.Var qq = (FullQueryExp.Var) q;
            yyy.setSelectedValue(indices.get(qq.v), true);
            return;
        }
        String k = FQLProgram.revLookup(prog.full_queries, q);
        if (k != null) {
            yyy.setSelectedValue(indices.get(k), true);
            return;
        }
        String str = q.toString();
        if (!extraInsts.contains(str)) {
            FullQuery view = q.toFullQuery(prog);
            JPanel p = showFullQuery(prog, env, view, q);
            x.add(p, str);
            extraInsts.add(str);
        }
        yyy.clearSelection();
        cl.show(x, str);
    } else if (f instanceof MapExp) {
        MapExp q = (MapExp) f;
        if (q instanceof MapExp.Var) {
            MapExp.Var qq = (MapExp.Var) q;
            yyy.setSelectedValue(indices.get(qq.v), true);
            return;
        }
        String k = FQLProgram.revLookup(prog.maps, q);
        if (k != null) {
            yyy.setSelectedValue(indices.get(k), true);
            return;
        }
        String str = q.toString();
        if (!extraInsts.contains(str)) {
            Mapping view = q.toMap(prog);
            JPanel p = showMapping(env, prog.smap(view.source.toConst()), prog.smap(view.target.toConst()), view);
            x.add(p, str);
            extraInsts.add(str);
        }
        yyy.clearSelection();
        cl.show(x, str);
    } else {
        throw new RuntimeException();
    }
}
Also used : JPanel(javax.swing.JPanel) FullEval(catdata.fql.decl.InstExp.FullEval) FullQuery(catdata.fql.decl.FullQuery) Query(catdata.fql.decl.Query) FullQueryExp(catdata.fql.decl.FullQueryExp) QueryExp(catdata.fql.decl.QueryExp) Var(catdata.fql.decl.SigExp.Var) One(catdata.fql.decl.InstExp.One) FullSigma(catdata.fql.decl.InstExp.FullSigma) Sigma(catdata.fql.decl.InstExp.Sigma) FullQueryExp(catdata.fql.decl.FullQueryExp) Mapping(catdata.fql.decl.Mapping) 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) Relationalize(catdata.fql.decl.InstExp.Relationalize) FullQuery(catdata.fql.decl.FullQuery) Zero(catdata.fql.decl.InstExp.Zero) Const(catdata.fql.decl.InstExp.Const) Two(catdata.fql.decl.InstExp.Two) InstExp(catdata.fql.decl.InstExp) MapExp(catdata.fql.decl.MapExp) Delta(catdata.fql.decl.InstExp.Delta) Times(catdata.fql.decl.InstExp.Times) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.decl.InstExp.FullSigma) FullQueryExp(catdata.fql.decl.FullQueryExp) Exp(catdata.fql.decl.InstExp.Exp) MapExp(catdata.fql.decl.MapExp) QueryExp(catdata.fql.decl.QueryExp) SigExp(catdata.fql.decl.SigExp) InstExp(catdata.fql.decl.InstExp)

Example 4 with FullSigma

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

the class FQLParser method toInst.

@SuppressWarnings("rawtypes")
private static InstExp toInst(Object o) {
    try {
        Tuple4 t = (Tuple4) o;
        Token z = (Token) t.a;
        String y = z.toString();
        if (y.equals("step")) {
            return new Step(t.d.toString(), toMapping(t.b), toMapping(t.c));
        }
    } catch (RuntimeException cce) {
    }
    try {
        Tuple3 t = (Tuple3) o;
        Token z = (Token) t.a;
        String y = z.toString();
        switch(y) {
            case "delta":
                return new InstExp.Delta(toMapping(t.b), t.c.toString());
            case "sigma":
                return new InstExp.Sigma(toMapping(t.b), t.c.toString());
            case "SIGMA":
                return new FullSigma(toMapping(t.b), t.c.toString());
            case "pi":
                return new InstExp.Pi(toMapping(t.b), t.c.toString());
            case "external":
                return new External(toSchema(t.b), t.c.toString());
            case "eval":
                return new Eval(toQuery(t.b), t.c.toString());
            case "EVAL":
                return new FullEval(toFullQuery(t.b), t.c.toString());
            default:
                break;
        }
    } catch (RuntimeException cce) {
    }
    try {
        Tuple3 t = (Tuple3) o;
        Token z = (Token) t.b;
        String y = z.toString();
        if (y.equals("+")) {
            return new Plus(t.a.toString(), t.c.toString());
        } else if (y.equals("*")) {
            return new Times(t.a.toString(), t.c.toString());
        }
        if (y.equals("^")) {
            return new Exp(t.a.toString(), (t.c).toString());
        }
    } catch (RuntimeException cce) {
    }
    try {
        org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) o;
        if (pr.a.toString().equals("unit")) {
            return new One(toSchema(pr.b));
        } else if (pr.a.toString().equals("void")) {
            return new Zero(toSchema(pr.b));
        } else if (pr.a.toString().equals("prop")) {
            return new Two(toSchema(pr.b));
        } else if (pr.a.toString().equals("relationalize")) {
            return new Relationalize(pr.b.toString());
        } else if (pr.a.toString().equals("kernel")) {
            return new Kernel(pr.b.toString());
        }
        throw new RuntimeException();
    } catch (RuntimeException cce) {
    }
    return toInstConst(o);
}
Also used : FullEval(catdata.fql.decl.InstExp.FullEval) Sigma(catdata.fql.decl.FullQueryExp.Sigma) FullSigma(catdata.fql.decl.InstExp.FullSigma) One(catdata.fql.decl.InstExp.One) Token(org.jparsec.Token) Step(catdata.fql.decl.InstExp.Step) Pi(catdata.fql.decl.FullQueryExp.Pi) Plus(catdata.fql.decl.InstExp.Plus) TransEval(catdata.fql.decl.TransExp.TransEval) 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) Two(catdata.fql.decl.InstExp.Two) Tuple4(org.jparsec.functors.Tuple4) Delta(catdata.fql.decl.FullQueryExp.Delta) Tuple3(org.jparsec.functors.Tuple3) Times(catdata.fql.decl.InstExp.Times) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.decl.InstExp.FullSigma) FullQueryExp(catdata.fql.decl.FullQueryExp) Exp(catdata.fql.decl.InstExp.Exp) MapExp(catdata.fql.decl.MapExp) TransExp(catdata.fql.decl.TransExp) QueryExp(catdata.fql.decl.QueryExp) SigExp(catdata.fql.decl.SigExp) InstExp(catdata.fql.decl.InstExp)

Example 5 with FullSigma

use of catdata.fql.decl.InstExp.FullSigma 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

FullSigma (catdata.fql.decl.InstExp.FullSigma)6 Pair (catdata.Pair)4 Delta (catdata.fql.decl.InstExp.Delta)4 Pi (catdata.fql.decl.InstExp.Pi)4 Sigma (catdata.fql.decl.InstExp.Sigma)4 Eval (catdata.fql.decl.InstExp.Eval)3 Exp (catdata.fql.decl.InstExp.Exp)3 External (catdata.fql.decl.InstExp.External)3 FullEval (catdata.fql.decl.InstExp.FullEval)3 Kernel (catdata.fql.decl.InstExp.Kernel)3 One (catdata.fql.decl.InstExp.One)3 Plus (catdata.fql.decl.InstExp.Plus)3 Relationalize (catdata.fql.decl.InstExp.Relationalize)3 Step (catdata.fql.decl.InstExp.Step)3 Times (catdata.fql.decl.InstExp.Times)3 Two (catdata.fql.decl.InstExp.Two)3 Zero (catdata.fql.decl.InstExp.Zero)3 Triple (catdata.Triple)2 Unit (catdata.Unit)2 FQLException (catdata.fql.FQLException)2