Search in sources :

Example 1 with Signature

use of catdata.fqlpp.cat.Signature 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 2 with Signature

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

the class CatOps method visit.

@Override
public Transform visit(FQLPPProgram env, ApplyPath e) {
    Functor F = e.F.accept(env, this);
    CatExp c = resolve(env, e.cat);
    if (!(c instanceof Const)) {
        throw new RuntimeException("Can only take paths in constant categories.");
    }
    Const C = (Const) c;
    Signature s = new Signature(C.nodes, C.arrows, C.eqs);
    Path n = s.path(e.node, e.edges);
    return (Transform) F.applyA(n);
}
Also used : 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) Signature(catdata.fqlpp.cat.Signature) Functor(catdata.fqlpp.cat.Functor) Transform(catdata.fqlpp.cat.Transform)

Example 3 with Signature

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

the class FqlppDisplay method showTrans.

@SuppressWarnings("unchecked")
private JPanel showTrans(Transform view, Color c) {
    JTabbedPane px = new JTabbedPane();
    if (view.source.source.isInfinite()) {
        CodeTextPanel p = new CodeTextPanel(BorderFactory.createEtchedBorder(), null, "Cannot display transforms from " + view.source.source);
        px.add("Text", p);
        JPanel top = new JPanel(new GridLayout(1, 1));
        top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        top.add(px);
        return top;
    }
    Signature<Object, Object> src_sig = null;
    // Signature<Object, Object> dst_sig = null;
    String src_key = unr(env.cats, view.source.source, null);
    if (src_key == null) {
        src_key = unr(env.cats, view.target.source, null);
    }
    if (src_key != null) {
        CatExp r = CatOps.resolve(prog, prog.cats.get(src_key));
        if (r instanceof Const) {
            Const sig0 = (Const) r;
            src_sig = new Signature(sig0.nodes, sig0.arrows, sig0.eqs);
        }
    }
    if (src_sig != null && FinSet.FinSet.equals(view.target.target)) {
        // JPanel vwr = new JPanel(new GridLayout(1, 1));
        if (DefunctGlobalOptions.debug.fqlpp.trans_elements) {
            Graph g = build2Elements(src_sig, view);
            if (g.getVertexCount() == 0) {
                px.add("Elements", new JPanel());
            } else if (g.getVertexCount() > DefunctGlobalOptions.debug.fqlpp.MAX_NODES) {
                CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getVertexCount() + " nodes, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_NODES);
                px.add("Elements", xxx);
            } else if (g.getEdgeCount() > DefunctGlobalOptions.debug.fqlpp.MAX_EDGES) {
                CodeTextPanel xxx = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "Graph has " + g.getEdgeCount() + " edges, which exceeds limit of " + DefunctGlobalOptions.debug.fqlpp.MAX_EDGES);
                px.add("Elements", xxx);
            } else {
                JComponent zzz = doElements2View(c, g);
                JPanel xxx = new JPanel(new GridLayout(1, 1));
                xxx.add(zzz);
                px.add("Elements", xxx);
            }
        }
    }
    if (DefunctGlobalOptions.debug.fqlpp.trans_graph) {
        JPanel vwr = new JPanel(new GridLayout(1, 1));
        if (view.source.source.objects().isEmpty()) {
            px.add("Graph", vwr);
        } else {
            JComponent zzz = doNTView(view, vwr, c, buildFromCat(view.source.source));
            JSplitPane newthing = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
            newthing.setResizeWeight(.5d);
            newthing.add(zzz);
            newthing.add(vwr);
            JPanel xxx = new JPanel(new GridLayout(1, 1));
            xxx.add(newthing);
            px.add("Graph", xxx);
        }
    }
    if (DefunctGlobalOptions.debug.fqlpp.trans_tabular) {
        JPanel gp = new JPanel(new GridLayout(1, 1));
        Object[][] rowData = new Object[view.source.source.objects().size()][2];
        int i = 0;
        for (Object o : view.source.source.objects()) {
            rowData[i][0] = Util.nice(o.toString());
            rowData[i][1] = Util.nice(view.apply(o).toString());
            i++;
        }
        Object[] colNames = new Object[] { "Input", "Output" };
        JPanel gp1 = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), "On Objects (" + view.source.source.objects().size() + ")", rowData, colNames);
        gp.add(gp1);
        px.add("Table", gp);
    }
    if (DefunctGlobalOptions.debug.fqlpp.trans_textual) {
        CodeTextPanel gp = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", Util.nice(view.toString()));
        px.add("Text", gp);
    }
    JPanel top = new JPanel(new GridLayout(1, 1));
    top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    top.add(px);
    return top;
}
Also used : JPanel(javax.swing.JPanel) JTabbedPane(javax.swing.JTabbedPane) Const(catdata.fqlpp.CatExp.Const) JComponent(javax.swing.JComponent) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) Graph(edu.uci.ics.jung.graph.Graph) CodeTextPanel(catdata.ide.CodeTextPanel) Signature(catdata.fqlpp.cat.Signature) JSplitPane(javax.swing.JSplitPane)

Example 4 with Signature

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

the class FqlppDisplay method doFNView2.

@SuppressWarnings("unchecked")
private static <X, Y> JComponent doFNView2(Functor fn, JPanel p, Color clr, Graph<X, Y> sgv, Signature sig) {
    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 ttt = arg0 -> Util.nice(arg0.toString());
    vv.getRenderContext().setVertexLabelTransformer(ttt);
    vv.getRenderContext().setEdgeLabelTransformer(ttt);
    // javac again
    Map<Object, JPanel> map = (Map<Object, JPanel>) makeJoined(sig, fn).second;
    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();
        p.add(map.get(str));
        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();
        p.add(map.get(str));
        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) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Function(com.google.common.base.Function) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with Signature

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

the class KBViewer method translate.

private static String translate(String s) {
    Object o = PPParser.catConst().from(PPParser.TOKENIZER, PPParser.IGNORED).parse(s);
    Const c = PPParser.toCatConst(o);
    Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);
    List<Pair<List<String>, List<String>>> rules = new LinkedList<>();
    for (Signature<String, String>.Eq eq : sig.eqs) {
        rules.add(new Pair<>(eq.lhs.path.stream().map(x -> x.name).collect(Collectors.toList()), eq.rhs.path.stream().map(x -> x.name).collect(Collectors.toList())));
    }
    Thue<String> kb = new Thue<>(rules, 16);
    kb.complete();
    return kb.toString();
}
Also used : Const(catdata.fqlpp.CatExp.Const) JSplitPane(javax.swing.JSplitPane) JDialog(javax.swing.JDialog) SwingConstants(javax.swing.SwingConstants) GridLayout(java.awt.GridLayout) Signature(catdata.fqlpp.cat.Signature) BorderLayout(java.awt.BorderLayout) LinkedList(java.util.LinkedList) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) Pair(catdata.Pair) Thue(catdata.provers.Thue) ScrollPaneConstants(javax.swing.ScrollPaneConstants) JButton(javax.swing.JButton) CodeTextPanel(catdata.ide.CodeTextPanel) BorderFactory(javax.swing.BorderFactory) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) JScrollPane(javax.swing.JScrollPane) Dimension(java.awt.Dimension) List(java.util.List) JLabel(javax.swing.JLabel) Example(catdata.ide.Example) JTextArea(javax.swing.JTextArea) JPanel(javax.swing.JPanel) Thue(catdata.provers.Thue) Const(catdata.fqlpp.CatExp.Const) LinkedList(java.util.LinkedList) Signature(catdata.fqlpp.cat.Signature) Pair(catdata.Pair)

Aggregations

Signature (catdata.fqlpp.cat.Signature)10 Const (catdata.fqlpp.CatExp.Const)9 Pair (catdata.Pair)7 Edge (catdata.fqlpp.cat.Signature.Edge)7 Node (catdata.fqlpp.cat.Signature.Node)7 CatConst (catdata.fqlpp.FunctorExp.CatConst)6 FinalConst (catdata.fqlpp.FunctorExp.FinalConst)6 InstConst (catdata.fqlpp.FunctorExp.InstConst)6 MapConst (catdata.fqlpp.FunctorExp.MapConst)6 SetSetConst (catdata.fqlpp.FunctorExp.SetSetConst)6 Category (catdata.fqlpp.cat.Category)6 FinSet (catdata.fqlpp.cat.FinSet)6 Triple (catdata.Triple)5 ApplyPath (catdata.fqlpp.TransExp.ApplyPath)5 Path (catdata.fqlpp.cat.Signature.Path)5 FiniteCategory (catdata.fqlpp.cat.FiniteCategory)4 Chc (catdata.Chc)3 CatExpVisitor (catdata.fqlpp.CatExp.CatExpVisitor)3 SetSet (catdata.fqlpp.TransExp.SetSet)3 ToMap (catdata.fqlpp.TransExp.ToMap)3