use of catdata.Chc in project fql by CategoricalData.
the class XMapping method makeGraph.
private JComponent makeGraph() {
if (src.allTerms().size() > 128) {
return new JTextArea("Too large to display");
}
Graph<Chc<C, D>, Object> sgv = buildFromSig();
Layout<Chc<C, D>, Object> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<Chc<C, D>, Object> vv = new VisualizationViewer<>(layout);
vv.getRenderContext().setLabelOffset(20);
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
Function<Chc<C, D>, Paint> vertexPaint = x -> {
if (x.left) {
return Color.BLUE;
}
return Color.GREEN;
};
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function<Chc<C, D>, String> ttt = arg0 -> {
if (arg0.left) {
return arg0.l.toString();
}
return arg0.r.toString();
};
Function<Object, String> hhh = arg0 -> {
if (!(arg0 instanceof Chc)) {
return "";
}
@SuppressWarnings("rawtypes") Chc xxx = (Chc) arg0;
if (xxx.left) {
return xxx.l.toString();
}
return xxx.r.toString();
};
vv.getRenderContext().setVertexLabelTransformer(ttt);
vv.getRenderContext().setEdgeLabelTransformer(hhh);
float[] dash = { 10.0f };
Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
Stroke bs = new BasicStroke();
Function<Object, Stroke> edgeStrokeTransformer = (Object s) -> {
if (!(s instanceof Chc)) {
return edgeStroke;
}
return bs;
};
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
JPanel ret = new JPanel(new GridLayout(1, 1));
ret.add(zzz);
ret.setBorder(BorderFactory.createEtchedBorder());
return ret;
}
use of catdata.Chc in project fql by CategoricalData.
the class XProd method match.
public static <A, B, C> XMapping<Chc<A, B>, C> match(XMapping<A, C> l, XMapping<B, C> r) {
if (!l.dst.equals(r.dst)) {
throw new RuntimeException();
}
XCtx<Chc<A, B>> src = coprod(l.src, r.src);
Map em = new HashMap<>();
for (Chc<A, B> x : src.terms()) {
if (x.left) {
em.put(x, l.em.get(x.l));
} else {
em.put(x, r.em.get(x.r));
}
}
for (Object x : src.allTerms()) {
if (em.containsKey(x)) {
continue;
}
List z = new LinkedList<>();
z.add(x);
em.put(x, z);
}
return new XMapping<>(src, l.dst, em, "homomorphism");
}
use of catdata.Chc in project fql by CategoricalData.
the class XProd method inr.
public static <X, Y> XMapping<Y, Chc<X, Y>> inr(XCtx<X> I, XCtx<Y> J) {
XCtx<Chc<X, Y>> IJ = coprod(I, J);
Map<Y, List<Chc<X, Y>>> em = new HashMap<>();
for (Y x : J.types.keySet()) {
List<Chc<X, Y>> l = new LinkedList<>();
l.add(Chc.inRight(x));
em.put(x, l);
}
for (Y x : J.allTerms()) {
if (em.containsKey(x)) {
continue;
}
List l = new LinkedList<>();
l.add(x);
em.put(x, l);
}
return new XMapping<>(J, IJ, em, "homomorphism");
}
use of catdata.Chc in project fql by CategoricalData.
the class SqlViewer method makeUI.
private void makeUI() {
if (graph.getVertexCount() == 0) {
top = new JPanel();
return;
}
Layout<Chc<SqlType, SqlTable>, Chc<SqlColumn, SqlForeignKey>> layout = new FRLayout<>(graph);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<Chc<SqlType, SqlTable>, Chc<SqlColumn, SqlForeignKey>> vv = new VisualizationViewer<>(layout);
Function<Chc<SqlType, SqlTable>, Paint> vertexPaint = x -> x.left ? UIManager.getColor("Panel.background") : color;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function<Chc<SqlType, SqlTable>, String> vt = x -> x.left ? x.l.name : x.r.name;
Function<Chc<SqlColumn, SqlForeignKey>, String> et = x -> x.left ? x.l.name : "";
vv.getRenderContext().setVertexLabelTransformer(vt);
vv.getRenderContext().setEdgeLabelTransformer(et);
top = new GraphZoomScrollPane(vv);
if (inst == null) {
return;
}
vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedEdgeState().clear();
@SuppressWarnings("unchecked") Chc<SqlType, SqlTable> x1 = (Chc<SqlType, SqlTable>) e.getItem();
if (x1.left) {
return;
}
cards.show(bottom, x1.r.name);
});
}
use of catdata.Chc in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Functor visit(FQLPPProgram env, CatConst ic) {
CatExp e = resolve(env, ic.sig);
if (!(e instanceof Const)) {
throw new RuntimeException("Can only create functors to cat 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);
Map<Node, Category> nm = new HashMap<>();
for (Node n : sig.nodes) {
CatExp kkk = ic.nm.get(n.name);
if (kkk == null) {
throw new RuntimeException("Missing node mapping from " + n);
}
nm.put(n, kkk.accept(env, this));
}
Map<Edge, Functor> em = new HashMap<>();
for (Edge n : sig.edges) {
FunctorExp 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;
Functor fn = FinCat.FinCat.identity(nm.get(p.source));
for (Object nnn : p.path) {
Edge n = (Edge) nnn;
fn = FinCat.FinCat.compose(fn, em.get(n));
}
return fn;
};
return new Functor(cat, FinCat.FinCat, nm::get, fff);
}
Aggregations