Search in sources :

Example 21 with CodeTextPanel

use of catdata.ide.CodeTextPanel in project fql by CategoricalData.

the class XMapping method makeTables2.

private Component makeTables2() {
    try {
        // Object[src.cat().arrows().size()][2];
        List<Object[]> rowData = new LinkedList<>();
        Object[] colNames = new Object[] { "src", "dst" };
        // int i = 0;
        for (Triple<C, C, List<C>> k : src.cat().arrows()) {
            List<C> a = new LinkedList<>(k.third);
            a.add(0, k.first);
            List<D> applied = apply(a);
            Pair<D, D> t = dst.type(applied);
            if (a.equals(applied)) {
                continue;
            }
            for (Triple<D, D, List<D>> cand : dst.cat().hom(t.first, t.second)) {
                if (dst.getKB().equiv(cand.third, applied)) {
                    List<C> z = new LinkedList<>(k.third);
                    z.add(0, k.first);
                    Object[] row = new Object[2];
                    row[0] = Util.sep(z, ".");
                    List<D> y = new LinkedList<>(cand.third);
                    y.add(0, cand.first);
                    row[1] = Util.sep(y, ".");
                    rowData.add(row);
                }
            }
        // i++;
        }
        return GuiUtil.makeTable(BorderFactory.createEtchedBorder(), "", rowData.toArray(new Object[0][0]), colNames);
    } catch (Exception e) {
        e.printStackTrace();
        return new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "ERROR:\n\n" + e.getMessage());
    }
}
Also used : LinkedList(java.util.LinkedList) CodeTextPanel(catdata.ide.CodeTextPanel) LinkedList(java.util.LinkedList) List(java.util.List)

Example 22 with CodeTextPanel

use of catdata.ide.CodeTextPanel in project fql by CategoricalData.

the class Signature method makeNormalizer.

private JPanel makeNormalizer() {
    JPanel ret = new JPanel(new BorderLayout());
    JPanel p = new JPanel(new GridLayout(2, 1));
    CodeTextPanel p1 = new CodeTextPanel("Input path", "");
    CodeTextPanel p2 = new CodeTextPanel("Normalized path", "");
    p.add(p1);
    p.add(p2);
    JButton b = new JButton("Normalize");
    b.addActionListener((ActionEvent e) -> {
        String s = p1.getText();
        try {
            Path path = Path.parsePath(this, s);
            Path ap = cached.second.of(path).arr;
            p2.setText(ap.toString());
        } catch (FQLException ex) {
            p2.setText(ex.toString());
        }
    });
    ret.add(p, BorderLayout.CENTER);
    ret.add(b, BorderLayout.PAGE_END);
    return ret;
}
Also used : JPanel(javax.swing.JPanel) FQLException(catdata.fql.FQLException) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) CodeTextPanel(catdata.ide.CodeTextPanel) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton)

Example 23 with CodeTextPanel

use of catdata.ide.CodeTextPanel in project fql by CategoricalData.

the class XCtx method makeTables.

// private Map<C, String> xgrid;
// public JComponent getGrid(C c) {
// if (xgrid != null) {
// return xgrid.get(c);
// }
// if (DEBUG.debug.x_tables) {
// //			makeTables(x -> cat().arrows(), new HashSet<>());
// return getGrid(c);
// }
// return new JPanel();
// }
// have this suppress pair IDs when possible
@SuppressWarnings({ "unchecked", "rawtypes" })
private JComponent makeTables(Function<Unit, Collection<Triple<C, C, List<C>>>> fn, Set<C> ignore) {
    cl = new CardLayout();
    // xgrid = new HashMap<>();
    clx = new JPanel();
    clx.setLayout(cl);
    clx.add(new JPanel(), "0");
    cl.show(clx, "0");
    // xgrid.put((C)"_1", "0");
    int www = 1;
    try {
        // Category<C, Triple<C, C, List<C>>> cat = cat();
        List<JComponent> grid = new LinkedList<>();
        Collection<Triple<C, C, List<C>>> cat = fn.apply(new Unit());
        // Map<C, Set<List<C>>> entities = new HashMap<>();
        Map entities = new HashMap<>();
        Map<C, Set<C>> m = new HashMap<>();
        for (C c : allIds()) {
            entities.put(c, new HashSet<>());
            m.put(c, new HashSet<>());
        }
        for (Triple<C, C, List<C>> k : cat) {
            if (k.first.equals("_1")) {
                // uncomment causes exception
                Set set = (Set<List<C>>) entities.get(k.second);
                // set.add(k);
                set.add(k.third);
            }
        }
        for (C c : allTerms()) {
            Pair<C, C> t = type(c);
            Set<C> set = m.get(t.first);
            set.add(c);
        }
        List<C> keys = new LinkedList<>(m.keySet());
        keys.sort((Object o1, Object o2) -> ((Comparable) o1).compareTo(o2));
        for (C c : keys) {
            if (c.equals("_1")) {
                continue;
            }
            if (ignore.contains(c)) {
                continue;
            }
            Pair<C, C> t = type(c);
            Set<List<C>> src = (Set<List<C>>) entities.get(t.first);
            List<C> cols = new LinkedList<>(m.get(c));
            cols = cols.stream().filter(x -> !x.toString().startsWith("!")).collect(Collectors.toList());
            Object[][] rowData = new Object[src.size()][cols.size()];
            int idx = cols.indexOf(c);
            if (idx != -1) {
                C old = cols.get(0);
                cols.set(0, c);
                cols.set(idx, old);
                if (cols.size() > 1) {
                    List<C> colsX = new LinkedList<>(cols.subList(1, cols.size()));
                    colsX.sort(null);
                    colsX.add(0, c);
                    cols = colsX;
                }
            }
            List<String> colNames3 = cols.stream().map(x -> type(x).second.equals(x) ? x.toString() : x + " (" + type(x).second + ")").collect(Collectors.toList());
            Object[] colNames = colNames3.toArray();
            int row = 0;
            for (List<C> l : src) {
                rowData[row][0] = l;
                int cl = 0;
                for (C col : cols) {
                    List<C> r = new LinkedList<>(l);
                    r.add(col);
                    for (Triple<C, C, List<C>> cand : cat) {
                        if (!cand.first.equals("_1")) {
                            continue;
                        }
                        if (!cand.second.equals(type(col).second)) {
                            continue;
                        }
                        if (kb.equiv(cand.third, r)) {
                            rowData[row][cl] = abbrPrint(cand.third);
                            break;
                        }
                    }
                    cl++;
                }
                row++;
            }
            JPanel table = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), c + " (" + src.size() + ") rows", rowData, colNames);
            JPanel table2 = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), c + " (" + src.size() + ") rows", rowData, colNames);
            // xgrid.put(c, Integer.toString(www));
            clx.add(new JScrollPane(table2), Integer.toString(www));
            www++;
            grid.add(table);
        }
        return GuiUtil.makeGrid(grid);
    } catch (Exception e) {
        e.printStackTrace();
        return new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "ERROR\n\n" + e.getMessage());
    }
}
Also used : Color(java.awt.Color) CardLayout(java.awt.CardLayout) JSplitPane(javax.swing.JSplitPane) JTextField(javax.swing.JTextField) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) HashMap(java.util.HashMap) Function(java.util.function.Function) GridLayout(java.awt.GridLayout) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) XInst(catdata.fpql.XExp.XInst) 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) Thue(catdata.provers.Thue) JComponent(javax.swing.JComponent) ItemEvent(java.awt.event.ItemEvent) Layout(edu.uci.ics.jung.algorithms.layout.Layout) JButton(javax.swing.JButton) CodeTextPanel(catdata.ide.CodeTextPanel) Iterator(java.util.Iterator) Collection(java.util.Collection) Util(catdata.Util) Category(catdata.fqlpp.cat.Category) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) Unit(catdata.Unit) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) JScrollPane(javax.swing.JScrollPane) 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) XSchema(catdata.fpql.XExp.XSchema) 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) JPanel(javax.swing.JPanel) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Unit(catdata.Unit) CodeTextPanel(catdata.ide.CodeTextPanel) LinkedList(java.util.LinkedList) List(java.util.List) JScrollPane(javax.swing.JScrollPane) CardLayout(java.awt.CardLayout) JComponent(javax.swing.JComponent) Paint(java.awt.Paint) LinkedList(java.util.LinkedList) Triple(catdata.Triple) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 24 with CodeTextPanel

use of catdata.ide.CodeTextPanel in project fql by CategoricalData.

the class XCtx method display.

@Override
@SuppressWarnings({ "unchecked", "ConstantConditions" })
public JComponent display() {
    init();
    JTabbedPane ret = new JTabbedPane();
    if (DefunctGlobalOptions.debug.fpql.x_text) {
        String kb_text = "types:\n  " + Util.sep(allIds(), ",\n  ");
        List<String> tms = allTerms().stream().map(x -> x + " : " + type(x).first + " -> " + type(x).second).collect(Collectors.toList());
        kb_text = kb_text.trim();
        kb_text += "\n\nterms:\n  " + Util.sep(tms, ",\n  ");
        List<String> xx = allEqs().stream().map(x -> Util.sep(x.first, ".") + " = " + Util.sep(x.second, ".")).collect(Collectors.toList());
        kb_text = kb_text.trim();
        kb_text += "\n\nequations:\n  " + Util.sep(xx, ",\n  ");
        kb_text = kb_text.trim();
        try {
            kb.complete();
            kb_text += "\n\nKnuth-Bendix Completion:\n" + kb;
        } catch (Exception e) {
            e.printStackTrace();
            kb_text = "\n\nERROR in Knuth-Bendix\n\n" + e.getMessage();
        }
        JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        JPanel bot = new JPanel(new GridLayout(1, 3));
        JTextField fff = new JTextField();
        JButton but = new JButton("Reduce");
        JTextField ggg = new JTextField();
        bot.add(fff);
        bot.add(but);
        bot.add(ggg);
        pane.setResizeWeight(1);
        but.addActionListener(x -> {
            String s = fff.getText();
            List<C> l = XParser.path(s);
            try {
                ggg.setText(Util.sep(getKB().normalize("", l), "."));
            } catch (Exception ex) {
                ex.printStackTrace();
                ggg.setText(ex.getMessage());
            }
        });
        JComponent kbc = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", kb_text);
        pane.add(kbc);
        pane.add(bot);
        ret.addTab("Text", pane);
    }
    String cat = null;
    if (DefunctGlobalOptions.debug.fpql.x_cat) {
        try {
            cat = cat().toString();
        } catch (Exception e) {
            e.printStackTrace();
            cat = "ERROR\n\n" + e.getMessage();
        }
        JComponent ctp = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", cat);
        ret.addTab("Category", ctp);
    }
    if (schema != null) {
        if (DefunctGlobalOptions.debug.fpql.x_tables) {
            // if category tab blew up, so should this
            JComponent tables = cat != null && cat.startsWith("ERROR") ? new CodeTextPanel(BorderFactory.createEtchedBorder(), "", cat) : makeTables(x -> cat().arrows(), new HashSet<>());
            ret.addTab("Full Tables", tables);
        }
        if (DefunctGlobalOptions.debug.fpql.x_adom) {
            ret.addTab("Adom Tables", makeTables(z -> foo(), global.ids));
        }
    }
    if (DefunctGlobalOptions.debug.fpql.x_graph) {
        ret.addTab("Graph", makeGraph(schema != null));
    }
    if (DefunctGlobalOptions.debug.fpql.x_graph && (schema != null)) {
        ret.addTab("Elements", elements());
    }
    if (DefunctGlobalOptions.debug.fpql.x_json) {
        String tj = toJSON();
        if (tj != null) {
            ret.addTab("JSON", new CodeTextPanel(BorderFactory.createEtchedBorder(), "", tj));
        }
    }
    return ret;
}
Also used : Color(java.awt.Color) CardLayout(java.awt.CardLayout) JSplitPane(javax.swing.JSplitPane) JTextField(javax.swing.JTextField) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) HashMap(java.util.HashMap) Function(java.util.function.Function) GridLayout(java.awt.GridLayout) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) XInst(catdata.fpql.XExp.XInst) 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) Thue(catdata.provers.Thue) JComponent(javax.swing.JComponent) ItemEvent(java.awt.event.ItemEvent) Layout(edu.uci.ics.jung.algorithms.layout.Layout) JButton(javax.swing.JButton) CodeTextPanel(catdata.ide.CodeTextPanel) Iterator(java.util.Iterator) Collection(java.util.Collection) Util(catdata.Util) Category(catdata.fqlpp.cat.Category) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) Unit(catdata.Unit) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) JScrollPane(javax.swing.JScrollPane) 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) XSchema(catdata.fpql.XExp.XSchema) 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) JPanel(javax.swing.JPanel) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) JTextField(javax.swing.JTextField) GridLayout(java.awt.GridLayout) CodeTextPanel(catdata.ide.CodeTextPanel) JSplitPane(javax.swing.JSplitPane) HashSet(java.util.HashSet)

Example 25 with CodeTextPanel

use of catdata.ide.CodeTextPanel in project fql by CategoricalData.

the class XPoly method display.

@Override
public JComponent display() {
    JTabbedPane ret = new JTabbedPane();
    ret.addTab("Text", new CodeTextPanel(BorderFactory.createEtchedBorder(), "", toString()));
    ret.addTab("Hat", new CodeTextPanel(BorderFactory.createEtchedBorder(), "", hat().toString()));
    ret.addTab("GrothO", new CodeTextPanel(BorderFactory.createEtchedBorder(), "", grotho().toString()));
    ret.addTab("Tilde", new CodeTextPanel(BorderFactory.createEtchedBorder(), "", tilde().toString()));
    return ret;
}
Also used : CodeTextPanel(catdata.ide.CodeTextPanel) JTabbedPane(javax.swing.JTabbedPane)

Aggregations

CodeTextPanel (catdata.ide.CodeTextPanel)31 JTabbedPane (javax.swing.JTabbedPane)19 JPanel (javax.swing.JPanel)18 GridLayout (java.awt.GridLayout)17 LinkedList (java.util.LinkedList)11 JComponent (javax.swing.JComponent)11 Paint (java.awt.Paint)10 List (java.util.List)9 Graph (edu.uci.ics.jung.graph.Graph)7 HashMap (java.util.HashMap)7 JSplitPane (javax.swing.JSplitPane)7 Pair (catdata.Pair)6 Unit (catdata.Unit)5 Const (catdata.fqlpp.CatExp.Const)5 Map (java.util.Map)5 Set (java.util.Set)5 JButton (javax.swing.JButton)5 JScrollPane (javax.swing.JScrollPane)5 Triple (catdata.Triple)4 Util (catdata.Util)4