Search in sources :

Example 16 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class CategoryOfElements method dot.

private static JPanel dot(String name, @SuppressWarnings("unused") Instance inst, Graph<Pair<Node, Object>, Pair<Path, Integer>> sgv, Map<Pair<Node, Object>, Map<Attribute<Node>, Object>> map0) {
    String str = "";
    int i = 0;
    Map<Pair<Node, Object>, Integer> map = new HashMap<>();
    for (Pair<Node, Object> p : sgv.getVertices()) {
        String s = p.toString() + map0.get(p);
        s.replace("\"", "\\\"");
        // a [label="Foo"];
        map.put(p, i);
        str += i + " [label=\"" + s + "\"];\n";
        i++;
    }
    for (Pair<Path, Integer> p : sgv.getEdges()) {
        Pair<Node, Object> src = sgv.getSource(p);
        Pair<Node, Object> dst = sgv.getDest(p);
        int src_id = map.get(src);
        int dst_id = map.get(dst);
        str += src_id + " -> " + dst_id + " [label=\"" + p.first + "\"];\n";
    }
    str = "digraph " + name + " {\n" + str.trim() + "\n}";
    JPanel p = new JPanel(new GridLayout(1, 1));
    JTextArea area = new JTextArea(str);
    JScrollPane jsp = new JScrollPane(area);
    p.add(jsp);
    return p;
}
Also used : Path(catdata.fql.decl.Path) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) HashMap(java.util.HashMap) Node(catdata.fql.decl.Node) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) Pair(catdata.Pair)

Example 17 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class CategoryOfElements method makePanel.

public static Pair<JPanel, JPanel> makePanel(String name, Instance i, Color c) {
    try {
        JPanel ret;
        JPanel ret2;
        Pair<Graph<Pair<Node, Object>, Pair<Path, Integer>>, HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>>> g = build(i);
        ret = g.first.getVertexCount() == 0 ? new JPanel() : doView(c, i, g.first, g.second);
        ret2 = dot(name, i, g.first, g.second);
        return new Pair<>(ret, ret2);
    } catch (FQLException e) {
        JPanel p = new JPanel(new GridLayout(1, 1));
        JTextArea a = new JTextArea(e.getMessage());
        p.add(new JScrollPane(a));
        return new Pair<>(p, p);
    }
}
Also used : Path(catdata.fql.decl.Path) JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) HashMap(java.util.HashMap) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) FQLException(catdata.fql.FQLException) GridLayout(java.awt.GridLayout) Graph(edu.uci.ics.jung.graph.Graph) Pair(catdata.Pair)

Example 18 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class CategoryOfElements method doView.

private static JPanel doView(Color clr, @SuppressWarnings("unused") Instance inst, Graph<Pair<Node, Object>, Pair<Path, Integer>> sgv, Map<Pair<Node, Object>, Map<Attribute<Node>, Object>> map0) {
    JPanel cards = new JPanel(new CardLayout());
    Layout<Pair<Node, Object>, Pair<Path, Integer>> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<Pair<Node, Object>, Pair<Path, Integer>> vv = new VisualizationViewer<>(layout);
    Function<Pair<Node, Object>, Paint> vertexPaint = (Pair<Node, Object> i) -> clr;
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexLabelRenderer(new MyVertexT(cards));
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.getRenderContext().setEdgeLabelTransformer((Pair<Path, Integer> t) -> t.first.toString());
    vv.getRenderContext().setVertexLabelTransformer((Pair<Node, Object> t) -> t.second.toString());
    JPanel ret = new JPanel(new GridLayout(1, 1));
    JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    for (Pair<Node, Object> n : sgv.getVertices()) {
        Map<Attribute<Node>, Object> s = map0.get(n);
        Object[] columnNames = new Object[s.keySet().size()];
        Object[][] rowData = new Object[1][s.keySet().size()];
        int i = 0;
        for (Attribute<Node> a : s.keySet()) {
            columnNames[i] = a.name;
            rowData[0][i] = s.get(a);
            i++;
        }
        JPanel p = new JPanel(new GridLayout(1, 1));
        JTable table = new JTable(rowData, columnNames);
        JScrollPane jsp = new JScrollPane(table);
        p.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Attributes for " + n.second));
        p.add(jsp);
        cards.add(p, n.second.toString());
    }
    cards.add(new JPanel(), "blank");
    CardLayout cl = (CardLayout) (cards.getLayout());
    cl.show(cards, "blank");
    pane.add(new GraphZoomScrollPane(vv));
    pane.add(cards);
    pane.setResizeWeight(.8d);
    ret.add(pane);
    return ret;
}
Also used : JPanel(javax.swing.JPanel) Attribute(catdata.fql.decl.Attribute) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Node(catdata.fql.decl.Node) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Pair(catdata.Pair) JScrollPane(javax.swing.JScrollPane) CardLayout(java.awt.CardLayout) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Paint(java.awt.Paint) JTable(javax.swing.JTable) JSplitPane(javax.swing.JSplitPane)

Example 19 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class LeftKan method replace.

private void replace(Integer x, Integer y) {
    for (Set<Pair<Object, Integer>> a : ua.values()) {
        for (Pair<Object, Integer> s : a) {
            if (s.second.equals(y)) {
                s.second = x;
            }
        }
    }
    if (alpha != null) {
        for (Node k : utables.keySet()) {
            Map<Integer, Object> v = utables.get(k);
            v.remove(y);
        }
    }
}
Also used : Node(catdata.fql.decl.Node) Pair(catdata.Pair)

Example 20 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class LeftKan method beta2.

// beta, delta, gamma
private boolean beta2() {
    boolean ret = false;
    try {
        for (Edge e : A.edges) {
            Path g = F.appy(B, new Path(A, e));
            Set<Pair<Object, Integer>> lhs = Instance.compose(X.data.get(e.name), ua.get(e.target));
            Set<Pair<Object, Integer>> rhs = Instance.compose(ua.get(e.source), eval(g));
            // System.out.println(lhs);
            // System.out.println(rhs);
            Node n = g.target;
            ret = ret || addCoincidences(lhs, rhs, n);
        }
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
    return ret;
}
Also used : Path(catdata.fql.decl.Path) FQLException(catdata.fql.FQLException) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair)

Aggregations

Node (catdata.fql.decl.Node)51 Pair (catdata.Pair)38 HashMap (java.util.HashMap)36 Edge (catdata.fql.decl.Edge)33 LinkedList (java.util.LinkedList)26 LinkedHashMap (java.util.LinkedHashMap)25 Instance (catdata.fql.decl.Instance)22 Path (catdata.fql.decl.Path)21 Map (java.util.Map)21 FQLException (catdata.fql.FQLException)20 Attribute (catdata.fql.decl.Attribute)19 HashSet (java.util.HashSet)19 Arr (catdata.fql.cat.Arr)14 Signature (catdata.fql.decl.Signature)13 Set (java.util.Set)13 Transform (catdata.fql.decl.Transform)11 List (java.util.List)10 Triple (catdata.Triple)5 Fn (catdata.fql.Fn)4 FinCat (catdata.fql.cat.FinCat)3