Search in sources :

Example 6 with Const

use of catdata.fqlpp.CatExp.Const 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)

Example 7 with Const

use of catdata.fqlpp.CatExp.Const in project fql by CategoricalData.

the class FqlppDisplay method showFtr.

@SuppressWarnings("unchecked")
private JPanel showFtr(Functor view, Color c, @SuppressWarnings("unused") FunctorExp e) {
    JTabbedPane px = new JTabbedPane();
    if (view.source.isInfinite()) {
        CodeTextPanel p = new CodeTextPanel(BorderFactory.createEtchedBorder(), null, "Cannot display functors from " + view.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<String, String> src_sig = null;
    Signature<String, String> dst_sig = null;
    String src_key = unr(env.cats, view.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);
        }
    }
    String dst_key = unr(env.cats, view.target, null);
    if (dst_key != null) {
        CatExp r = CatOps.resolve(prog, prog.cats.get(dst_key));
        if (r instanceof Const) {
            Const sig0 = (Const) r;
            dst_sig = new Signature<>(sig0.nodes, sig0.arrows, sig0.eqs);
        }
    }
    if (src_sig != null && FinSet.FinSet.equals(view.target)) {
        if (DefunctGlobalOptions.debug.fqlpp.ftr_instance) {
            JPanel vwr = new JPanel(new GridLayout(1, 1));
            if (view.source.objects().isEmpty()) {
                px.add("Instance", vwr);
            } else {
                JComponent zzz = doFNView2(view, vwr, c, buildFromSig(src_sig), src_sig);
                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("Instance", xxx);
            }
        }
        if (DefunctGlobalOptions.debug.fqlpp.ftr_joined) {
            // cast needed for javac for some reason
            px.add("Joined", (Component) makeJoined(src_sig, view).first);
        }
        if (DefunctGlobalOptions.debug.fqlpp.ftr_elements) {
            Graph g = buildElements(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 {
                px.add("Elements", doElementsView(c, g));
            }
        }
    }
    if (src_sig != null && dst_sig != null && !view.source.isInfinite() && !view.target.isInfinite()) {
        // JPanel vwr = new JPanel(new GridLayout(1, 1));
        if (DefunctGlobalOptions.debug.fqlpp.ftr_mapping) {
            Graph g = buildMapping(src_sig, dst_sig, view);
            if (g.getVertexCount() == 0) {
                px.add("Mapping", 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("Mapping", 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("Mapping", xxx);
            } else {
                JComponent zzz = doMappingView(c, getColor(view.target), g);
                JPanel xxx = new JPanel(new GridLayout(1, 1));
                xxx.add(zzz);
                px.add("Mapping", xxx);
            }
        }
    }
    if (DefunctGlobalOptions.debug.fqlpp.ftr_graph) {
        JPanel vwr = new JPanel(new GridLayout(1, 1));
        Graph g = buildFromCat(view.source);
        if (view.source.objects().isEmpty()) {
            px.add("Graph", vwr);
        } 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("Graph", 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("Graph", xxx);
        } else {
            JComponent zzz = doFNView(view, vwr, c, g);
            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.ftr_tabular) {
        List<JComponent> gp = new LinkedList<>();
        // JPanel gp = new JPanel(new GridLayout(2, 1));
        Object[][] rowData = new Object[view.source.objects().size()][2];
        int i = 0;
        for (Object o : view.source.objects()) {
            rowData[i][0] = Util.nice(o.toString());
            rowData[i][1] = Util.nice(view.applyO(o).toString());
            i++;
        }
        Object[] colNames = new Object[] { "Input", "Output" };
        JPanel gp1 = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), "On Objects (" + view.source.objects().size() + ")", rowData, colNames);
        Object[][] rowData2 = new Object[view.source.arrows().size()][6];
        i = 0;
        for (Object o : view.source.arrows()) {
            rowData2[i][0] = Util.nice(o.toString());
            rowData2[i][1] = Util.nice(view.source.source(o).toString());
            rowData2[i][2] = Util.nice(view.source.target(o).toString());
            rowData2[i][3] = Util.nice(view.applyA(o).toString());
            rowData2[i][4] = Util.nice(view.target.source(view.applyA(o)).toString());
            rowData2[i][5] = Util.nice(view.target.target(view.applyA(o)).toString());
            i++;
        }
        Object[] colNames2 = new Object[] { "Input", "Source", "Target", "Output", "Source", "Target" };
        JPanel gp2 = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), "On Arrows (" + view.source.arrows().size() + ")", rowData2, colNames2);
        gp.add(gp1);
        gp.add(gp2);
        px.add("Table", GuiUtil.makeGrid(gp));
    }
    if (DefunctGlobalOptions.debug.fqlpp.ftr_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) LinkedList(java.util.LinkedList) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) Graph(edu.uci.ics.jung.graph.Graph) CodeTextPanel(catdata.ide.CodeTextPanel) JSplitPane(javax.swing.JSplitPane)

Example 8 with Const

use of catdata.fqlpp.CatExp.Const in project fql by CategoricalData.

the class FqlppDisplay method showCat.

private JPanel showCat(Category<?, ?> view, Color c) {
    JTabbedPane px = new JTabbedPane();
    Signature<String, String> sig = null;
    String key = unr(env.cats, view, null);
    if (key != null) {
        CatExp r = CatOps.resolve(prog, prog.cats.get(key));
        if (r instanceof Const) {
            Const sig0 = (Const) r;
            sig = new Signature<>(sig0.nodes, sig0.arrows, sig0.eqs);
        }
    }
    if (sig != null && !view.isInfinite()) {
        if (DefunctGlobalOptions.debug.fqlpp.cat_schema) {
            Graph g = buildFromSig(sig);
            if (g.getVertexCount() == 0) {
                px.add("Schema", 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("Schema", 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("Schema", xxx);
            } else {
                px.add("Schema", doSchemaView(c, g));
            }
        }
    }
    if (DefunctGlobalOptions.debug.fqlpp.cat_graph && !view.isInfinite()) {
        JComponent gp = makeCatViewer(view, c);
        px.add("Graph", gp);
    }
    if (DefunctGlobalOptions.debug.fqlpp.cat_tabular && !view.isInfinite()) {
        JPanel gp = catTable(view);
        px.add("Table", gp);
    }
    if (DefunctGlobalOptions.debug.fqlpp.cat_textual) {
        CodeTextPanel gp = new CodeTextPanel(BorderFactory.createEtchedBorder(), null, 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) GridLayout(java.awt.GridLayout) Graph(edu.uci.ics.jung.graph.Graph) CodeTextPanel(catdata.ide.CodeTextPanel) JTabbedPane(javax.swing.JTabbedPane) Const(catdata.fqlpp.CatExp.Const) JComponent(javax.swing.JComponent)

Example 9 with Const

use of catdata.fqlpp.CatExp.Const in project fql by CategoricalData.

the class PreProcessor method visit.

@Override
public CatExp visit(FQLPPProgram env, Union e) {
    CatExp l = e.l.accept(env, this);
    CatExp r = e.r.accept(env, this);
    CatExp lx = CatOps.resolve(env, l);
    CatExp rx = CatOps.resolve(env, r);
    if (!(lx instanceof Const)) {
        throw new RuntimeException("Not a const: " + lx);
    }
    if (!(rx instanceof Const)) {
        throw new RuntimeException("Not a const: " + rx);
    }
    Const ly = (Const) lx;
    Const ry = (Const) rx;
    Set<Pair<Pair<String, List<String>>, Pair<String, List<String>>>> eqs = new HashSet<>();
    Set<Triple<String, String, String>> arrows = new HashSet<>();
    Set<String> nodes = new HashSet<>();
    nodes.addAll(ly.nodes);
    nodes.addAll(ry.nodes);
    arrows.addAll(ly.arrows);
    arrows.addAll(ry.arrows);
    eqs.addAll(ly.eqs);
    eqs.addAll(ry.eqs);
    return new Const(nodes, arrows, eqs);
}
Also used : Triple(catdata.Triple) Const(catdata.fqlpp.CatExp.Const) List(java.util.List) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 10 with Const

use of catdata.fqlpp.CatExp.Const 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

Const (catdata.fqlpp.CatExp.Const)13 CatConst (catdata.fqlpp.FunctorExp.CatConst)8 MapConst (catdata.fqlpp.FunctorExp.MapConst)8 Signature (catdata.fqlpp.cat.Signature)8 FinalConst (catdata.fqlpp.FunctorExp.FinalConst)7 InstConst (catdata.fqlpp.FunctorExp.InstConst)7 SetSetConst (catdata.fqlpp.FunctorExp.SetSetConst)7 Pair (catdata.Pair)6 Triple (catdata.Triple)5 ApplyPath (catdata.fqlpp.TransExp.ApplyPath)5 Path (catdata.fqlpp.cat.Signature.Path)5 Category (catdata.fqlpp.cat.Category)4 FiniteCategory (catdata.fqlpp.cat.FiniteCategory)4 Edge (catdata.fqlpp.cat.Signature.Edge)4 Node (catdata.fqlpp.cat.Signature.Node)4 Chc (catdata.Chc)3 CatExpVisitor (catdata.fqlpp.CatExp.CatExpVisitor)3 Cod (catdata.fqlpp.CatExp.Cod)3 Colim (catdata.fqlpp.CatExp.Colim)3 Dom (catdata.fqlpp.CatExp.Dom)3