Search in sources :

Example 16 with Functor

use of catdata.fqlpp.cat.Functor 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)

Example 17 with Functor

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

the class SetOps method visit.

@SuppressWarnings("unchecked")
@Override
public Set<?> visit(FQLPPProgram env, SetExp.Apply e) {
    FunctorExp k = env.ftrs.get(e.f);
    if (k == null) {
        throw new RuntimeException("Missing functor: " + e.f);
    }
    Set<?> s = e.set.accept(env, this);
    Functor f = k.accept(env, new CatOps(ENV));
    if (!FinSet.FinSet.equals(f.source)) {
        throw new RuntimeException("Domain is not Set in " + e);
    }
    if (!FinSet.FinSet.equals(f.target)) {
        throw new RuntimeException("Codomain is not Set in " + e);
    }
    return (Set<?>) f.applyO(s);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) FinSet(catdata.fqlpp.cat.FinSet) Functor(catdata.fqlpp.cat.Functor)

Example 18 with Functor

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

the class CatOps method visit.

@Override
public Transform visit(FQLPPProgram env, TransExp.Apply e) {
    Functor F = e.F.accept(env, this);
    Transform I = e.I.accept(env, this);
    return (Transform) F.applyA(I);
}
Also used : Functor(catdata.fqlpp.cat.Functor) Transform(catdata.fqlpp.cat.Transform)

Example 19 with Functor

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

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, InstConst ic) {
    // new Instance(nm, em, sig);
    Pair<Category, Instance<String, String>> xxx = toInstance(env, ic);
    Functor ret = toFunctor(xxx.first, xxx.second);
    ret.instance0 = xxx.second;
    return ret;
}
Also used : FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) Instance(catdata.fqlpp.cat.Instance) Functor(catdata.fqlpp.cat.Functor)

Example 20 with Functor

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

the class CatOps method visit.

@Override
public Transform visit(FQLPPProgram env, ToMap e) {
    Functor s = e.src.accept(env, this);
    Functor t = e.dst.accept(env, this);
    CatExp scat = resolve(env, e.s);
    if (!(scat instanceof Const)) {
        throw new RuntimeException("Source category of " + e + " is not a constant.");
    }
    // CatExp.Const scon = (CatExp.Const) scat;
    CatExp tcat = resolve(env, e.t);
    if (!(tcat instanceof Const)) {
        throw new RuntimeException("Target category of " + e + " is not a constant.");
    }
    Const tcon = (Const) tcat;
    // Signature ssig = new Signature(scon.nodes, scon.arrows, scon.eqs);
    Signature<String, String> tsig = new Signature<>(tcon.nodes, tcon.arrows, tcon.eqs);
    FUNCTION o = x -> {
        Node n = (Node) x;
        // Set src = (Set) s.applyO(n);
        // Set dst = (Set) t.applyO(n);
        Pair<String, List<String>> k = e.fun.get(n.name);
        Signature<String, String>.Path fun = tsig.path(k.first, k.second);
        // new Fn(src, dst, fun);
        return fun;
    };
    return new Transform(s, t, o);
}
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) 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) Pair(catdata.Pair)

Aggregations

Functor (catdata.fqlpp.cat.Functor)30 Transform (catdata.fqlpp.cat.Transform)18 Category (catdata.fqlpp.cat.Category)14 Fn (catdata.fqlpp.cat.FinSet.Fn)14 Pair (catdata.Pair)13 Const (catdata.fqlpp.CatExp.Const)13 FinSet (catdata.fqlpp.cat.FinSet)13 Signature (catdata.fqlpp.cat.Signature)13 Node (catdata.fqlpp.cat.Signature.Node)13 Triple (catdata.Triple)12 FinCat (catdata.fqlpp.cat.FinCat)12 FunCat (catdata.fqlpp.cat.FunCat)12 Inst (catdata.fqlpp.cat.Inst)12 Edge (catdata.fqlpp.cat.Signature.Edge)12 CatConst (catdata.fqlpp.FunctorExp.CatConst)10 FinalConst (catdata.fqlpp.FunctorExp.FinalConst)10 Chc (catdata.Chc)9 CatExpVisitor (catdata.fqlpp.CatExp.CatExpVisitor)9 Cod (catdata.fqlpp.CatExp.Cod)9 Colim (catdata.fqlpp.CatExp.Colim)9