Search in sources :

Example 6 with Transform

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

the class CatOps method visit.

@Override
public Transform visit(FQLPPProgram env, CoProd e) {
    Transform l = e.l.accept(env, this);
    Transform r = e.r.accept(env, this);
    if (!l.target.equals(r.target)) {
        throw new RuntimeException("Target functors do not match");
    }
    if (!l.target.source.equals(r.target.source)) {
        throw new RuntimeException("Categories do not match");
    }
    if (l.source.target.equals(FinSet.FinSet)) {
        return Inst.get(l.target.source).match(l, r);
    } else if (l.source.target.equals(FinCat.FinCat)) {
        return FunCat.get(l.target.source).match(l, r);
    } else {
        throw new RuntimeException("Report this error to Ryan");
    }
}
Also used : Transform(catdata.fqlpp.cat.Transform)

Example 7 with Transform

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

the class SetOps method visit.

@SuppressWarnings("unchecked")
@Override
public Fn visit(FQLPPProgram env, ApplyTrans e) {
    TransExp k = env.trans.get(e.f);
    if (k == null) {
        throw new RuntimeException("Missing transform: " + e.f);
    }
    Transform f = k.accept(env, new CatOps(ENV));
    if (!FinSet.FinSet.equals(f.source.source)) {
        throw new RuntimeException("Domain is not Set in " + e);
    }
    if (!FinSet.FinSet.equals(f.target.target)) {
        throw new RuntimeException("Codomain is not Set in " + e);
    }
    Set<?> s = e.set.accept(env, this);
    return (Fn) f.apply(s);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) Transform(catdata.fqlpp.cat.Transform)

Example 8 with Transform

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

the class FqlppDisplay method doNTView.

@SuppressWarnings("unchecked")
private <X, Y> JComponent doNTView(Transform fn, JPanel p, Color clr, Graph<X, Y> sgv) {
    // Layout<X, Y> layout = new FRLayout<>(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 www = arg0 -> Util.nice(arg0.toString());
    vv.getRenderContext().setVertexLabelTransformer(www);
    vv.getRenderContext().setEdgeLabelTransformer(www);
    vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
        if (e.getStateChange() != ItemEvent.SELECTED) {
            return;
        }
        vv.getPickedEdgeState().clear();
        X str = ((X) e.getItem());
        Object y = fn.apply(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) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) 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) Function(com.google.common.base.Function) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Transform(catdata.fqlpp.cat.Transform)

Example 9 with Transform

use of catdata.fqlpp.cat.Transform 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 10 with Transform

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

Aggregations

Transform (catdata.fqlpp.cat.Transform)20 Functor (catdata.fqlpp.cat.Functor)15 Fn (catdata.fqlpp.cat.FinSet.Fn)11 Const (catdata.fqlpp.CatExp.Const)10 Category (catdata.fqlpp.cat.Category)10 Signature (catdata.fqlpp.cat.Signature)10 Node (catdata.fqlpp.cat.Signature.Node)10 Pair (catdata.Pair)9 Triple (catdata.Triple)9 FinCat (catdata.fqlpp.cat.FinCat)9 FinSet (catdata.fqlpp.cat.FinSet)9 FunCat (catdata.fqlpp.cat.FunCat)9 Inst (catdata.fqlpp.cat.Inst)9 Edge (catdata.fqlpp.cat.Signature.Edge)9 CatConst (catdata.fqlpp.FunctorExp.CatConst)8 FinalConst (catdata.fqlpp.FunctorExp.FinalConst)8 Chc (catdata.Chc)7 CatExpVisitor (catdata.fqlpp.CatExp.CatExpVisitor)7 Cod (catdata.fqlpp.CatExp.Cod)7 Colim (catdata.fqlpp.CatExp.Colim)7