Search in sources :

Example 1 with FullEval

use of catdata.fql.decl.InstExp.FullEval 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 2 with FullEval

use of catdata.fql.decl.InstExp.FullEval 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 3 with FullEval

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

Example 4 with FullEval

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

the class Driver method rewriteQueries.

private static FQLProgram rewriteQueries(FQLProgram prog) {
    List<String> norder = new LinkedList<>();
    LinkedHashMap<String, InstExp> insts = new LinkedHashMap<>();
    for (String k : prog.order) {
        if (prog.insts.get(k) == null) {
            norder.add(k);
            continue;
        }
        InstExp v = prog.insts.get(k);
        if (v instanceof FullEval) {
            FullEval u = (FullEval) v;
            List<Pair<String, InstExp>> n = u.q.toFullQueryExp(prog).accept(u.e, new ExpandFull(prog.full_queries));
            n.get(n.size() - 1).first = k;
            // int pos = prog.order.indexOf(k);
            for (Pair<String, InstExp> x : n) {
                insts.put(x.first, x.second);
                norder.add(x.first);
            }
        } else {
            norder.add(k);
            insts.put(k, v);
        }
    }
    return new FQLProgram(prog.enums, prog.sigs, prog.maps, insts, prog.full_queries, prog.queries, prog.transforms, prog.lines, prog.drop, norder);
}
Also used : FullEval(catdata.fql.decl.InstExp.FullEval) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair)

Aggregations

FullEval (catdata.fql.decl.InstExp.FullEval)4 Pair (catdata.Pair)3 Eval (catdata.fql.decl.InstExp.Eval)3 Exp (catdata.fql.decl.InstExp.Exp)3 External (catdata.fql.decl.InstExp.External)3 FullSigma (catdata.fql.decl.InstExp.FullSigma)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 Unit (catdata.Unit)2 FullQueryExp (catdata.fql.decl.FullQueryExp)2 InstExp (catdata.fql.decl.InstExp)2 Const (catdata.fql.decl.InstExp.Const)2 Delta (catdata.fql.decl.InstExp.Delta)2 Pi (catdata.fql.decl.InstExp.Pi)2