Search in sources :

Example 16 with Chc

use of catdata.Chc in project fql by CategoricalData.

the class XMapping method makeGraph.

private JComponent makeGraph() {
    if (src.allTerms().size() > 128) {
        return new JTextArea("Too large to display");
    }
    Graph<Chc<C, D>, Object> sgv = buildFromSig();
    Layout<Chc<C, D>, Object> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<Chc<C, D>, Object> vv = new VisualizationViewer<>(layout);
    vv.getRenderContext().setLabelOffset(20);
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    Function<Chc<C, D>, Paint> vertexPaint = x -> {
        if (x.left) {
            return Color.BLUE;
        }
        return Color.GREEN;
    };
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function<Chc<C, D>, String> ttt = arg0 -> {
        if (arg0.left) {
            return arg0.l.toString();
        }
        return arg0.r.toString();
    };
    Function<Object, String> hhh = arg0 -> {
        if (!(arg0 instanceof Chc)) {
            return "";
        }
        @SuppressWarnings("rawtypes") Chc xxx = (Chc) arg0;
        if (xxx.left) {
            return xxx.l.toString();
        }
        return xxx.r.toString();
    };
    vv.getRenderContext().setVertexLabelTransformer(ttt);
    vv.getRenderContext().setEdgeLabelTransformer(hhh);
    float[] dash = { 10.0f };
    Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
    Stroke bs = new BasicStroke();
    Function<Object, Stroke> edgeStrokeTransformer = (Object s) -> {
        if (!(s instanceof Chc)) {
            return edgeStroke;
        }
        return bs;
    };
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    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) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Chc(catdata.Chc) XMapConst(catdata.fpql.XExp.XMapConst) HashMap(java.util.HashMap) Block(catdata.fpql.XPoly.Block) GridLayout(java.awt.GridLayout) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Stroke(java.awt.Stroke) JComponent(javax.swing.JComponent) Layout(edu.uci.ics.jung.algorithms.layout.Layout) Function(com.google.common.base.Function) CodeTextPanel(catdata.ide.CodeTextPanel) XTransConst(catdata.fpql.XExp.XTransConst) Collection(java.util.Collection) Util(catdata.Util) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) Component(java.awt.Component) Collectors(java.util.stream.Collectors) 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) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) JTextArea(javax.swing.JTextArea) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) JTextArea(javax.swing.JTextArea) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Chc(catdata.Chc)

Example 17 with Chc

use of catdata.Chc in project fql by CategoricalData.

the class XProd method match.

public static <A, B, C> XMapping<Chc<A, B>, C> match(XMapping<A, C> l, XMapping<B, C> r) {
    if (!l.dst.equals(r.dst)) {
        throw new RuntimeException();
    }
    XCtx<Chc<A, B>> src = coprod(l.src, r.src);
    Map em = new HashMap<>();
    for (Chc<A, B> x : src.terms()) {
        if (x.left) {
            em.put(x, l.em.get(x.l));
        } else {
            em.put(x, r.em.get(x.r));
        }
    }
    for (Object x : src.allTerms()) {
        if (em.containsKey(x)) {
            continue;
        }
        List z = new LinkedList<>();
        z.add(x);
        em.put(x, z);
    }
    return new XMapping<>(src, l.dst, em, "homomorphism");
}
Also used : HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList) Chc(catdata.Chc)

Example 18 with Chc

use of catdata.Chc in project fql by CategoricalData.

the class XProd method inr.

public static <X, Y> XMapping<Y, Chc<X, Y>> inr(XCtx<X> I, XCtx<Y> J) {
    XCtx<Chc<X, Y>> IJ = coprod(I, J);
    Map<Y, List<Chc<X, Y>>> em = new HashMap<>();
    for (Y x : J.types.keySet()) {
        List<Chc<X, Y>> l = new LinkedList<>();
        l.add(Chc.inRight(x));
        em.put(x, l);
    }
    for (Y x : J.allTerms()) {
        if (em.containsKey(x)) {
            continue;
        }
        List l = new LinkedList<>();
        l.add(x);
        em.put(x, l);
    }
    return new XMapping<>(J, IJ, em, "homomorphism");
}
Also used : HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Chc(catdata.Chc)

Example 19 with Chc

use of catdata.Chc in project fql by CategoricalData.

the class SqlViewer method makeUI.

private void makeUI() {
    if (graph.getVertexCount() == 0) {
        top = new JPanel();
        return;
    }
    Layout<Chc<SqlType, SqlTable>, Chc<SqlColumn, SqlForeignKey>> layout = new FRLayout<>(graph);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<Chc<SqlType, SqlTable>, Chc<SqlColumn, SqlForeignKey>> vv = new VisualizationViewer<>(layout);
    Function<Chc<SqlType, SqlTable>, Paint> vertexPaint = x -> x.left ? UIManager.getColor("Panel.background") : color;
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function<Chc<SqlType, SqlTable>, String> vt = x -> x.left ? x.l.name : x.r.name;
    Function<Chc<SqlColumn, SqlForeignKey>, String> et = x -> x.left ? x.l.name : "";
    vv.getRenderContext().setVertexLabelTransformer(vt);
    vv.getRenderContext().setEdgeLabelTransformer(et);
    top = new GraphZoomScrollPane(vv);
    if (inst == null) {
        return;
    }
    vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }
        vv.getPickedEdgeState().clear();
        @SuppressWarnings("unchecked") Chc<SqlType, SqlTable> x1 = (Chc<SqlType, SqlTable>) e.getItem();
        if (x1.left) {
            return;
        }
        cards.show(bottom, x1.r.name);
    });
}
Also used : Color(java.awt.Color) UIManager(javax.swing.UIManager) CardLayout(java.awt.CardLayout) JSplitPane(javax.swing.JSplitPane) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Chc(catdata.Chc) GridLayout(java.awt.GridLayout) Map(java.util.Map) Graph(edu.uci.ics.jung.graph.Graph) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) ItemEvent(java.awt.event.ItemEvent) Layout(edu.uci.ics.jung.algorithms.layout.Layout) Function(com.google.common.base.Function) BorderFactory(javax.swing.BorderFactory) Collectors(java.util.stream.Collectors) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) List(java.util.List) Paint(java.awt.Paint) Optional(java.util.Optional) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Chc(catdata.Chc)

Example 20 with Chc

use of catdata.Chc in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, CatConst ic) {
    CatExp e = resolve(env, ic.sig);
    if (!(e instanceof Const)) {
        throw new RuntimeException("Can only create functors to cat 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);
    Map<Node, Category> nm = new HashMap<>();
    for (Node n : sig.nodes) {
        CatExp kkk = ic.nm.get(n.name);
        if (kkk == null) {
            throw new RuntimeException("Missing node mapping from " + n);
        }
        nm.put(n, kkk.accept(env, this));
    }
    Map<Edge, Functor> em = new HashMap<>();
    for (Edge n : sig.edges) {
        FunctorExp 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;
        Functor fn = FinCat.FinCat.identity(nm.get(p.source));
        for (Object nnn : p.path) {
            Edge n = (Edge) nnn;
            fn = FinCat.FinCat.compose(fn, em.get(n));
        }
        return fn;
    };
    return new Functor(cat, FinCat.FinCat, 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) Edge(catdata.fqlpp.cat.Signature.Edge)

Aggregations

Chc (catdata.Chc)40 Pair (catdata.Pair)27 Triple (catdata.Triple)25 HashMap (java.util.HashMap)22 List (java.util.List)22 HashSet (java.util.HashSet)20 LinkedList (java.util.LinkedList)20 Ctx (catdata.Ctx)19 En (catdata.aql.exp.SchExpRaw.En)18 Ty (catdata.aql.exp.TyExpRaw.Ty)18 Sym (catdata.aql.exp.TyExpRaw.Sym)17 Att (catdata.aql.exp.SchExpRaw.Att)16 Fk (catdata.aql.exp.SchExpRaw.Fk)16 Map (java.util.Map)14 Gen (catdata.aql.exp.InstExpRaw.Gen)13 Sk (catdata.aql.exp.InstExpRaw.Sk)12 Collage (catdata.aql.Collage)11 RawTerm (catdata.aql.RawTerm)11 Util (catdata.Util)10 Term (catdata.aql.Term)10