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;
}
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);
}
}
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;
}
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);
}
}
}
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;
}
Aggregations