Search in sources :

Example 1 with Category

use of catdata.fqlpp.cat.Category in project fql by CategoricalData.

the class XCtx method satcat.

private Category<C, Triple<C, C, List<C>>> satcat() {
    Category<C, Triple<C, C, List<C>>> sch = schema.cat();
    eqm = new HashMap<>();
    Set<Triple<C, C, List<C>>> new_arrs = new HashSet<>();
    for (C a : schema.allIds()) {
        for (C v : types.keySet()) {
            Pair<C, C> t = type(v);
            C b = t.second;
            if (b.equals("_1")) {
                continue;
            }
            List<C> l = new LinkedList<>();
            @SuppressWarnings("unchecked") C ccc = (C) ("!_" + a);
            l.add(ccc);
            l.add(v);
            Triple<C, C, List<C>> arr = new Triple<>(a, b, l);
            new_arrs.add(arr);
        }
    }
    Set<Triple<C, C, List<C>>> arrs = new HashSet<>();
    arrs.addAll(sch.arrows());
    arrs.addAll(new_arrs);
    Map<Pair<Triple<C, C, List<C>>, Triple<C, C, List<C>>>, Triple<C, C, List<C>>> comp_cache = new HashMap<>();
    @SuppressWarnings("serial") Category<C, Triple<C, C, List<C>>> ret = new Category<C, Triple<C, C, List<C>>>() {

        @Override
        public Set<C> objects() {
            return sch.objects();
        }

        @Override
        public Set<Triple<C, C, List<C>>> arrows() {
            return arrs;
        }

        @Override
        public C source(Triple<C, C, List<C>> a) {
            return a.first;
        }

        @Override
        public C target(Triple<C, C, List<C>> a) {
            return a.second;
        }

        @Override
        public Triple<C, C, List<C>> identity(C o) {
            return sch.identity(o);
        }

        @Override
        public Triple<C, C, List<C>> compose(Triple<C, C, List<C>> f, Triple<C, C, List<C>> g) {
            Pair<Triple<C, C, List<C>>, Triple<C, C, List<C>>> p = new Pair<>(f, g);
            Triple<C, C, List<C>> ret = comp_cache.get(p);
            if (ret != null) {
                return ret;
            }
            ret = local_compose(f, g);
            comp_cache.put(p, ret);
            return ret;
        }

        @SuppressWarnings({ "rawtypes", "unchecked", "cast", "ConstantConditions" })
        private Triple<C, C, List<C>> local_compose(Triple<C, C, List<C>> f, Triple<C, C, List<C>> g) {
            if (!arrows().contains(f)) {
                throw new RuntimeException(f.toString());
            }
            if (!arrows().contains(g)) {
                throw new RuntimeException(g.toString());
            }
            if (!f.second.equals(g.first)) {
                throw new RuntimeException("cannot compose " + f + " and " + g);
            }
            if (sch.hom(f.first, f.second).contains(f) && sch.hom(g.first, g.second).contains(g)) {
                return sch.compose(f, g);
            }
            if (new_arrs.contains(f) && new_arrs.contains(g)) {
                Pair<C, C> ft = new Pair<>(f.first, f.second);
                Pair<C, C> gt = new Pair<>(g.first, g.second);
                C a = ft.first;
                C b = gt.first;
                // C v = f.third.get(1);
                C v0 = g.third.get(1);
                if (schema.allIds().contains(a) && !b.equals("_1")) {
                    List<C> l = new LinkedList<>();
                    C ccc = (C) ("!_" + a);
                    l.add(ccc);
                    l.add(v0);
                    Triple<C, C, List<C>> ret = new Triple<>(a, type(v0).second, l);
                    if (!ret.first.equals(f.first) || !ret.second.equals(g.second)) {
                        throw new RuntimeException();
                    }
                    if (!arrows().contains(ret)) {
                        throw new RuntimeException(ret.toString());
                    }
                    return ret;
                }
            }
            if (new_arrs.contains(f) && sch.arrows().contains(g)) {
                if (g.third.isEmpty()) {
                    if (!f.first.equals(g.first) || !f.second.equals(g.second)) {
                        throw new RuntimeException();
                    }
                    if (!arrows().contains(f)) {
                        throw new RuntimeException(f.toString());
                    }
                    return f;
                }
                // C b = g.first;
                C b0 = g.second;
                C a = f.first;
                C v = f.third.get(1);
                if (b0.equals("_1") && a.equals("_1")) {
                    Triple ret = new Triple("_1", "_1", new LinkedList());
                    if (!ret.first.equals(f.first) || !ret.second.equals(g.second)) {
                        throw new RuntimeException();
                    }
                    if (!arrows().contains(ret)) {
                        throw new RuntimeException(ret.toString());
                    }
                    return ret;
                }
                if (b0.equals("_1") && !a.equals("_1")) {
                    List l = new LinkedList();
                    l.add("!_" + a);
                    Triple ret = new Triple(a, "_1", l);
                    if (!ret.first.equals(f.first) || !ret.second.equals(g.second)) {
                        throw new RuntimeException();
                    }
                    if (!arrows().contains(ret)) {
                        throw new RuntimeException(ret.toString());
                    }
                    return ret;
                }
                if (g.third.get(0).toString().startsWith("!") && !a.equals("_1")) {
                    List<C> l = new LinkedList();
                    l.add((C) ("!_" + a));
                    l.addAll(g.third.subList(1, g.third.size()));
                    Triple<C, C, List<C>> ret = new Triple<>(a, g.second, l);
                    ret = find_old(getKB(), ret, hom(ret.first, ret.second));
                    if (ret == null) {
                        throw new RuntimeException("Anomaly: please report");
                    }
                    if (!ret.first.equals(f.first) || !ret.second.equals(g.second)) {
                        throw new RuntimeException();
                    }
                    if (!arrows().contains(ret)) {
                        throw new RuntimeException(ret.toString());
                    }
                    return ret;
                }
                if (g.third.get(0).toString().startsWith("!") && a.equals("_1")) {
                    List<C> l = new LinkedList();
                    l.addAll(g.third.subList(1, g.third.size()));
                    Triple<C, C, List<C>> ret = new Triple<>(f.first, g.second, l);
                    if (!ret.first.equals(f.first) || !ret.second.equals(g.second)) {
                        throw new RuntimeException();
                    }
                    // must find equivalent - see CTDB example
                    ret = find_old(getKB(), ret, hom(ret.first, ret.second));
                    if (!arrows().contains(ret)) {
                        throw new RuntimeException("Anomaly: please report: " + ret);
                    }
                    return ret;
                }
                List<C> vl = new LinkedList<>();
                vl.add(v);
                Triple<C, C, List<C>> sofar = new Triple<>(type(v).first, type(v).second, vl);
                List gnX = new LinkedList<>(g.third);
                for (C gn : g.third) {
                    gnX.remove(0);
                    sofar = findEq(sofar, gn);
                    if (sch.arrows().contains(sofar)) {
                        List hhh = new LinkedList();
                        hhh.add("!_" + a);
                        hhh.addAll(sofar.third);
                        hhh.addAll(gnX);
                        Triple<C, C, List<C>> ret0 = new Triple<>(a, g.second, hhh);
                        Triple ret = find_old(schema.getKB(), ret0, sch.hom(ret0.first, ret0.second));
                        if (!arrows().contains(ret)) {
                            throw new RuntimeException("f " + f + " and " + g + "\n\nbad: " + ret + " not found inn\n\n" + Util.sep(arrows(), "\n"));
                        }
                        if (!ret.first.equals(f.first) || !ret.second.equals(g.second)) {
                            throw new RuntimeException();
                        }
                        return ret;
                    }
                }
                List<C> retl = new LinkedList<>();
                retl.add((C) ("!_" + a));
                retl.addAll(sofar.third);
                Triple<C, C, List<C>> ret = new Triple<>(f.first, g.second, retl);
                if (a.equals("_1") && global.allIds().contains(sofar.second) && global.cat().hom((C) "_1", sofar.second).contains(sofar)) {
                    if (!arrows().contains(sofar)) {
                        throw new RuntimeException(sofar.toString());
                    }
                    if (!sofar.first.equals(f.first) || !sofar.second.equals(g.second)) {
                        throw new RuntimeException();
                    }
                    return sofar;
                }
                if (!ret.first.equals(f.first) || !ret.second.equals(g.second)) {
                    throw new RuntimeException(ret + " not " + f + " and " + g);
                }
                // another one where have to use KB
                ret = find_old(getKB(), ret, hom(ret.first, ret.second));
                if (!arrows().contains(ret)) {
                    throw new RuntimeException("f " + f + " and " + g + "\n\nbad: " + ret + " not found inn\n\n" + Util.sep(arrows(), "\n"));
                }
                return ret;
            }
            if (sch.arrows().contains(f) && new_arrs.contains(g)) {
                C a0 = f.first;
                // C a = f.second;
                C v = g.third.get(1);
                List<C> l = new LinkedList<>();
                l.add((C) ("!_" + a0));
                l.add(v);
                Triple<C, C, List<C>> ret = new Triple<>(a0, g.second, l);
                if (!ret.first.equals(f.first) || !ret.second.equals(g.second)) {
                    throw new RuntimeException();
                }
                if (!arrows().contains(ret)) {
                    throw new RuntimeException(ret.toString());
                }
                return ret;
            }
            throw new RuntimeException("bottomed out: " + f + " and " + g + "\n" + sch.hom(f.first, f.second) + "\n" + sch.hom(g.first, g.second));
        }

        @SuppressWarnings({ "unchecked" })
        private Triple<C, C, List<C>> findEq(Triple<C, C, List<C>> sofar, C gn) {
            if (sofar.third.size() != 1) {
                throw new RuntimeException("sofar third not length 1 is " + sofar);
            }
            C v = sofar.third.get(0);
            List<C> tofind = new LinkedList<>();
            tofind.add(v);
            tofind.add(gn);
            List<C> found = eqm.get(new Pair<>(v, gn));
            // Pair<List<C>, List<C>> xxx = null;
            for (Pair<List<C>, List<C>> eq : eqs) {
                if (found != null) {
                    break;
                }
                if (eq.first.equals(tofind)) {
                    found = eq.second;
                    // xxx = eq;
                    break;
                }
                if (eq.second.equals(tofind)) {
                    found = eq.first;
                    // xxx = eq;
                    break;
                }
            }
            eqm.put(new Pair<>(v, gn), found);
            if (found == null) {
                throw new RuntimeException("sofar " + sofar + " gn " + gn + "\n\n" + allEqs());
            }
            @SuppressWarnings("rawtypes") List l = new LinkedList<>();
            l.addAll(found);
            Triple<C, C, List<C>> ret = new Triple<>(type(found).first, type(found).second, l);
            return ret;
        }
    };
    // cache the composition table
    if (DefunctGlobalOptions.debug.fpql.validate_amalgams) {
        ret.validate();
    }
    return ret;
}
Also used : Category(catdata.fqlpp.cat.Category) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) Triple(catdata.Triple) LinkedList(java.util.LinkedList) List(java.util.List) HashSet(java.util.HashSet) Pair(catdata.Pair)

Example 2 with Category

use of catdata.fqlpp.cat.Category in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, Iso e) {
    Category l = e.l.accept(env, this);
    Category r = e.r.accept(env, this);
    Optional<Pair<Functor, Functor>> k = FinCat.iso(l, r);
    if (!k.isPresent()) {
        throw new RuntimeException("Not isomorphic: " + e.l + " and " + e.r);
    }
    return e.lToR ? k.get().first : k.get().second;
}
Also used : FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) Pair(catdata.Pair)

Example 3 with Category

use of catdata.fqlpp.cat.Category in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, MapConst ic) {
    Triple<Category, Category, Mapping<String, String, String, String>> xxx = toMapping(env, ic);
    Mapping<String, String, String, String> I = xxx.third;
    FUNCTION f = p0 -> {
        Path p = (Path) p0;
        return I.apply(p);
    };
    Functor et = new Functor(xxx.first, xxx.second, x -> I.nm.get(x), f);
    et.mapping0 = xxx.third;
    return et;
}
Also used : PeterApply(catdata.fqlpp.TransExp.PeterApply) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Named(catdata.fqlpp.CatExp.Named) Edge(catdata.fqlpp.cat.Signature.Edge) Snd(catdata.fqlpp.FunctorExp.Snd) Comp(catdata.fqlpp.FunctorExp.Comp) ToInst(catdata.fqlpp.TransExp.ToInst) Id(catdata.fqlpp.FunctorExp.Id) Inr(catdata.fqlpp.FunctorExp.Inr) FF(catdata.fqlpp.FunctorExp.FF) Migrate(catdata.fqlpp.FunctorExp.Migrate) Colim(catdata.fqlpp.CatExp.Colim) Exp(catdata.fqlpp.CatExp.Exp) Pushout(catdata.fqlpp.FunctorExp.Pushout) FinCat(catdata.fqlpp.cat.FinCat) FunCat(catdata.fqlpp.cat.FunCat) Pair(catdata.Pair) CoMonad(catdata.fqlpp.cat.CoMonad) Iso(catdata.fqlpp.FunctorExp.Iso) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Inj(catdata.fqlpp.TransExp.Inj) Fn(catdata.fqlpp.cat.FinSet.Fn) Bool(catdata.fqlpp.TransExp.Bool) Case(catdata.fqlpp.FunctorExp.Case) ToMap(catdata.fqlpp.TransExp.ToMap) Zero(catdata.fqlpp.CatExp.Zero) Monad(catdata.fqlpp.cat.Monad) Plus(catdata.fqlpp.CatExp.Plus) Category(catdata.fqlpp.cat.Category) CatConst(catdata.fqlpp.FunctorExp.CatConst) Inst(catdata.fqlpp.cat.Inst) ToSet(catdata.fqlpp.TransExp.ToSet) Groth(catdata.fqlpp.cat.Groth) Mapping(catdata.fqlpp.cat.Mapping) Serializable(java.io.Serializable) Kleisli(catdata.fqlpp.CatExp.Kleisli) ApplyTrans(catdata.fqlpp.TransExp.ApplyTrans) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) Dom(catdata.fqlpp.CatExp.Dom) Triple(catdata.Triple) Eval(catdata.fqlpp.FunctorExp.Eval) Var(catdata.fqlpp.FunctorExp.Var) Times(catdata.fqlpp.CatExp.Times) Const(catdata.fqlpp.CatExp.Const) java.util(java.util) Prod(catdata.fqlpp.FunctorExp.Prod) InstConst(catdata.fqlpp.FunctorExp.InstConst) Node(catdata.fqlpp.cat.Signature.Node) Chc(catdata.Chc) TT(catdata.fqlpp.FunctorExp.TT) Functor(catdata.fqlpp.cat.Functor) Proj(catdata.fqlpp.TransExp.Proj) Prop(catdata.fqlpp.FunctorExp.Prop) CatExpVisitor(catdata.fqlpp.CatExp.CatExpVisitor) Signature(catdata.fqlpp.cat.Signature) TransExpVisitor(catdata.fqlpp.TransExp.TransExpVisitor) Union(catdata.fqlpp.CatExp.Union) ToCat(catdata.fqlpp.TransExp.ToCat) One(catdata.fqlpp.CatExp.One) FDM(catdata.fqlpp.cat.FDM) Ker(catdata.fqlpp.TransExp.Ker) Fst(catdata.fqlpp.FunctorExp.Fst) Whisker(catdata.fqlpp.TransExp.Whisker) Curry(catdata.fqlpp.FunctorExp.Curry) Transform(catdata.fqlpp.cat.Transform) Apply(catdata.fqlpp.FunctorExp.Apply) Instance(catdata.fqlpp.cat.Instance) MapConst(catdata.fqlpp.FunctorExp.MapConst) Path(catdata.fqlpp.cat.Signature.Path) Pivot(catdata.fqlpp.FunctorExp.Pivot) Chr(catdata.fqlpp.TransExp.Chr) Cod(catdata.fqlpp.CatExp.Cod) FinSet(catdata.fqlpp.cat.FinSet) Uncurry(catdata.fqlpp.FunctorExp.Uncurry) FunctorExpVisitor(catdata.fqlpp.FunctorExp.FunctorExpVisitor) Adj(catdata.fqlpp.TransExp.Adj) SetSet(catdata.fqlpp.TransExp.SetSet) AndOrNotImplies(catdata.fqlpp.TransExp.AndOrNotImplies) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Inl(catdata.fqlpp.FunctorExp.Inl) CoProd(catdata.fqlpp.TransExp.CoProd) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Path(catdata.fqlpp.cat.Signature.Path) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) Mapping(catdata.fqlpp.cat.Mapping) Functor(catdata.fqlpp.cat.Functor)

Example 4 with Category

use of catdata.fqlpp.cat.Category in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, FinalConst ic) {
    CatExp e = resolve(env, ic.src);
    if (!(e instanceof Const)) {
        throw new RuntimeException("Can only create functors from finitely-presented categories.");
    }
    Const c = (Const) e;
    Category cat = c.accept(env, this);
    Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);
    Category target = ic.C.accept(env, this);
    Map<Node, Functor> nm = new HashMap<>();
    for (Node n : sig.nodes) {
        FunctorExp kkk = ic.nm.get(n.name);
        if (kkk == null) {
            throw new RuntimeException("Missing node mapping from " + n);
        }
        Functor F = kkk.accept(env, this);
        nm.put(n, F);
    }
    Map<Edge, Transform> em = new HashMap<>();
    for (Edge n : sig.edges) {
        TransExp chc = ic.em.get(n.name);
        if (chc == null) {
            throw new RuntimeException("Missing edge mapping from " + n);
        }
        em.put(n, chc.accept(env, this));
    }
    FUNCTION fff = p0 -> {
        Path p = (Path) p0;
        Object fn = target.identity(nm.get(p.source));
        for (Object nnn : p.path) {
            Edge n = (Edge) nnn;
            fn = target.compose(fn, em.get(n));
        }
        return fn;
    };
    return new Functor(cat, target, nm::get, fff);
}
Also used : PeterApply(catdata.fqlpp.TransExp.PeterApply) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Named(catdata.fqlpp.CatExp.Named) Edge(catdata.fqlpp.cat.Signature.Edge) Snd(catdata.fqlpp.FunctorExp.Snd) Comp(catdata.fqlpp.FunctorExp.Comp) ToInst(catdata.fqlpp.TransExp.ToInst) Id(catdata.fqlpp.FunctorExp.Id) Inr(catdata.fqlpp.FunctorExp.Inr) FF(catdata.fqlpp.FunctorExp.FF) Migrate(catdata.fqlpp.FunctorExp.Migrate) Colim(catdata.fqlpp.CatExp.Colim) Exp(catdata.fqlpp.CatExp.Exp) Pushout(catdata.fqlpp.FunctorExp.Pushout) FinCat(catdata.fqlpp.cat.FinCat) FunCat(catdata.fqlpp.cat.FunCat) Pair(catdata.Pair) CoMonad(catdata.fqlpp.cat.CoMonad) Iso(catdata.fqlpp.FunctorExp.Iso) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Inj(catdata.fqlpp.TransExp.Inj) Fn(catdata.fqlpp.cat.FinSet.Fn) Bool(catdata.fqlpp.TransExp.Bool) Case(catdata.fqlpp.FunctorExp.Case) ToMap(catdata.fqlpp.TransExp.ToMap) Zero(catdata.fqlpp.CatExp.Zero) Monad(catdata.fqlpp.cat.Monad) Plus(catdata.fqlpp.CatExp.Plus) Category(catdata.fqlpp.cat.Category) CatConst(catdata.fqlpp.FunctorExp.CatConst) Inst(catdata.fqlpp.cat.Inst) ToSet(catdata.fqlpp.TransExp.ToSet) Groth(catdata.fqlpp.cat.Groth) Mapping(catdata.fqlpp.cat.Mapping) Serializable(java.io.Serializable) Kleisli(catdata.fqlpp.CatExp.Kleisli) ApplyTrans(catdata.fqlpp.TransExp.ApplyTrans) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) Dom(catdata.fqlpp.CatExp.Dom) Triple(catdata.Triple) Eval(catdata.fqlpp.FunctorExp.Eval) Var(catdata.fqlpp.FunctorExp.Var) Times(catdata.fqlpp.CatExp.Times) Const(catdata.fqlpp.CatExp.Const) java.util(java.util) Prod(catdata.fqlpp.FunctorExp.Prod) InstConst(catdata.fqlpp.FunctorExp.InstConst) Node(catdata.fqlpp.cat.Signature.Node) Chc(catdata.Chc) TT(catdata.fqlpp.FunctorExp.TT) Functor(catdata.fqlpp.cat.Functor) Proj(catdata.fqlpp.TransExp.Proj) Prop(catdata.fqlpp.FunctorExp.Prop) CatExpVisitor(catdata.fqlpp.CatExp.CatExpVisitor) Signature(catdata.fqlpp.cat.Signature) TransExpVisitor(catdata.fqlpp.TransExp.TransExpVisitor) Union(catdata.fqlpp.CatExp.Union) ToCat(catdata.fqlpp.TransExp.ToCat) One(catdata.fqlpp.CatExp.One) FDM(catdata.fqlpp.cat.FDM) Ker(catdata.fqlpp.TransExp.Ker) Fst(catdata.fqlpp.FunctorExp.Fst) Whisker(catdata.fqlpp.TransExp.Whisker) Curry(catdata.fqlpp.FunctorExp.Curry) Transform(catdata.fqlpp.cat.Transform) Apply(catdata.fqlpp.FunctorExp.Apply) Instance(catdata.fqlpp.cat.Instance) MapConst(catdata.fqlpp.FunctorExp.MapConst) Path(catdata.fqlpp.cat.Signature.Path) Pivot(catdata.fqlpp.FunctorExp.Pivot) Chr(catdata.fqlpp.TransExp.Chr) Cod(catdata.fqlpp.CatExp.Cod) FinSet(catdata.fqlpp.cat.FinSet) Uncurry(catdata.fqlpp.FunctorExp.Uncurry) FunctorExpVisitor(catdata.fqlpp.FunctorExp.FunctorExpVisitor) Adj(catdata.fqlpp.TransExp.Adj) SetSet(catdata.fqlpp.TransExp.SetSet) AndOrNotImplies(catdata.fqlpp.TransExp.AndOrNotImplies) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Inl(catdata.fqlpp.FunctorExp.Inl) CoProd(catdata.fqlpp.TransExp.CoProd) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Path(catdata.fqlpp.cat.Signature.Path) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) CatConst(catdata.fqlpp.FunctorExp.CatConst) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) Const(catdata.fqlpp.CatExp.Const) InstConst(catdata.fqlpp.FunctorExp.InstConst) MapConst(catdata.fqlpp.FunctorExp.MapConst) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Node(catdata.fqlpp.cat.Signature.Node) Functor(catdata.fqlpp.cat.Functor) Signature(catdata.fqlpp.cat.Signature) Transform(catdata.fqlpp.cat.Transform) Edge(catdata.fqlpp.cat.Signature.Edge)

Example 5 with Category

use of catdata.fqlpp.cat.Category in project fql by CategoricalData.

the class FqlppDisplay method doFNView.

@SuppressWarnings("unchecked")
private <X, Y> JComponent doFNView(Functor fn, JPanel p, Color clr, Graph<X, Y> sgv) {
    Layout<X, Y> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<X, Y> vv = new VisualizationViewer<>(layout);
    Function<X, Paint> vertexPaint = z -> clr;
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function fff = arg0 -> Util.nice(arg0.toString());
    vv.getRenderContext().setVertexLabelTransformer(fff);
    vv.getRenderContext().setEdgeLabelTransformer(fff);
    vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }
        vv.getPickedEdgeState().clear();
        X str = ((X) e.getItem());
        Object y = fn.applyO(str);
        p.removeAll();
        if (y instanceof Category) {
            Category ttt = (Category) y;
            JPanel sss = showCat(ttt, getColor(ttt));
            p.add(sss);
        } else if (y instanceof Set) {
            Set ttt = (Set) y;
            JPanel sss = showSet(ttt, getColor(ttt));
            p.add(sss);
        } else if (y instanceof Functor) {
            Functor ttt = (Functor) y;
            JPanel sss = showFtr(ttt, getColor(ttt), null);
            p.add(sss);
        } else {
            String sss = Util.nice(y.toString());
            p.add(new CodeTextPanel(BorderFactory.createEtchedBorder(), null, sss));
        }
        p.revalidate();
    });
    vv.getPickedEdgeState().addItemListener((ItemEvent e) -> {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }
        vv.getPickedVertexState().clear();
        X str = ((X) e.getItem());
        Object y = fn.applyA(str);
        p.removeAll();
        if (y instanceof Functor) {
            Functor ttt = (Functor) y;
            JPanel sss = showFtr(ttt, getColor(ttt.source), null);
            p.add(sss);
        } else if (y instanceof Fn) {
            Fn ttt = (Fn) y;
            JPanel sss = showFn(ttt, getColor(ttt.source), getColor(ttt.target));
            p.add(sss);
        } else if (y instanceof Transform) {
            Transform ttt = (Transform) y;
            JPanel sss = showTrans(ttt, getColor(ttt.source));
            p.add(sss);
        } else {
            String sss = Util.nice(y.toString());
            p.add(new CodeTextPanel(BorderFactory.createEtchedBorder(), null, sss));
        }
        p.revalidate();
    });
    GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
    JPanel ret = new JPanel(new GridLayout(1, 1));
    ret.add(zzz);
    ret.setBorder(BorderFactory.createEtchedBorder());
    return ret;
}
Also used : Color(java.awt.Color) Edge(catdata.fqlpp.cat.Signature.Edge) Vector(java.util.Vector) Map(java.util.Map) FinCat(catdata.fqlpp.cat.FinCat) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) FunCat(catdata.fqlpp.cat.FunCat) JFrame(javax.swing.JFrame) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Pair(catdata.Pair) KeyStroke(javax.swing.KeyStroke) ItemEvent(java.awt.event.ItemEvent) Fn(catdata.fqlpp.cat.FinSet.Fn) Quad(catdata.Quad) Function(com.google.common.base.Function) Disp(catdata.ide.Disp) Category(catdata.fqlpp.cat.Category) Set(java.util.Set) Inst(catdata.fqlpp.cat.Inst) BorderFactory(javax.swing.BorderFactory) KeyEvent(java.awt.event.KeyEvent) Component(java.awt.Component) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) List(java.util.List) Paint(java.awt.Paint) Entry(java.util.Map.Entry) Triple(catdata.Triple) BasicStroke(java.awt.BasicStroke) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) InputEvent(java.awt.event.InputEvent) ListSelectionModel(javax.swing.ListSelectionModel) Const(catdata.fqlpp.CatExp.Const) CardLayout(java.awt.CardLayout) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) Node(catdata.fqlpp.cat.Signature.Node) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Functor(catdata.fqlpp.cat.Functor) HashMap(java.util.HashMap) GridLayout(java.awt.GridLayout) Signature(catdata.fqlpp.cat.Signature) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) GUI(catdata.ide.GUI) LinkedList(java.util.LinkedList) Stroke(java.awt.Stroke) JComponent(javax.swing.JComponent) Transform(catdata.fqlpp.cat.Transform) Layout(edu.uci.ics.jung.algorithms.layout.Layout) CodeTextPanel(catdata.ide.CodeTextPanel) JList(javax.swing.JList) Util(catdata.Util) ActionEvent(java.awt.event.ActionEvent) FinSet(catdata.fqlpp.cat.FinSet) JScrollPane(javax.swing.JScrollPane) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) Category(catdata.fqlpp.cat.Category) Set(java.util.Set) FinSet(catdata.fqlpp.cat.FinSet) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Function(com.google.common.base.Function) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) Fn(catdata.fqlpp.cat.FinSet.Fn) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Functor(catdata.fqlpp.cat.Functor) Transform(catdata.fqlpp.cat.Transform)

Aggregations

Category (catdata.fqlpp.cat.Category)14 Pair (catdata.Pair)11 Triple (catdata.Triple)10 FiniteCategory (catdata.fqlpp.cat.FiniteCategory)9 Const (catdata.fqlpp.CatExp.Const)8 CatConst (catdata.fqlpp.FunctorExp.CatConst)7 FinalConst (catdata.fqlpp.FunctorExp.FinalConst)7 InstConst (catdata.fqlpp.FunctorExp.InstConst)7 MapConst (catdata.fqlpp.FunctorExp.MapConst)7 SetSetConst (catdata.fqlpp.FunctorExp.SetSetConst)7 Functor (catdata.fqlpp.cat.Functor)6 Signature (catdata.fqlpp.cat.Signature)6 Edge (catdata.fqlpp.cat.Signature.Edge)6 Node (catdata.fqlpp.cat.Signature.Node)6 Chc (catdata.Chc)5 CatExpVisitor (catdata.fqlpp.CatExp.CatExpVisitor)5 Cod (catdata.fqlpp.CatExp.Cod)5 Colim (catdata.fqlpp.CatExp.Colim)5 Dom (catdata.fqlpp.CatExp.Dom)5 Exp (catdata.fqlpp.CatExp.Exp)5