use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class FqlppDisplay method doFNView2.
@SuppressWarnings("unchecked")
private static <X, Y> JComponent doFNView2(Functor fn, JPanel p, Color clr, Graph<X, Y> sgv, Signature sig) {
Layout<X, Y> layout = new FRLayout<>(sgv);
layout.setSize(new Dimension(600, 400));
VisualizationViewer<X, Y> vv = new VisualizationViewer<>(layout);
Function<X, Paint> vertexPaint = z -> clr;
DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
gm.setMode(Mode.TRANSFORMING);
vv.setGraphMouse(gm);
gm.setMode(Mode.PICKING);
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
Function ttt = arg0 -> Util.nice(arg0.toString());
vv.getRenderContext().setVertexLabelTransformer(ttt);
vv.getRenderContext().setEdgeLabelTransformer(ttt);
// javac again
Map<Object, JPanel> map = (Map<Object, JPanel>) makeJoined(sig, fn).second;
vv.getPickedVertexState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedEdgeState().clear();
X str = ((X) e.getItem());
// Object y = fn.applyO(str);
p.removeAll();
p.add(map.get(str));
p.revalidate();
});
vv.getPickedEdgeState().addItemListener((ItemEvent e) -> {
if (e.getStateChange() != ItemEvent.SELECTED) {
return;
}
vv.getPickedVertexState().clear();
X str = ((X) e.getItem());
// Object y = fn.applyA(str);
p.removeAll();
p.add(map.get(str));
p.revalidate();
});
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.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class FinSet method hom.
@SuppressWarnings({ "unchecked" })
@Override
public Set hom(Set A, Set B) {
Pair<Set, Set> p = new Pair<>(A, B);
Set retX = cached.get(p);
if (retX != null) {
return retX;
}
Set<Fn> ret = new HashSet<>();
List<LinkedHashMap<Set, Set>> k = homomorphs(new LinkedList<>(A), new LinkedList<>(B));
for (LinkedHashMap<Set, Set> v : k) {
ret.add(new Fn(A, B, v::get));
}
cached.put(p, ret);
return ret;
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class Functor method toInstanceX.
@SuppressWarnings({ "rawtypes", "unchecked" })
private Instance<O1, A1> toInstanceX(Signature<O1, A1> src) {
if (source.isInfinite() || !target.equals(FinSet.FinSet)) {
throw new RuntimeException("Cannot create mapping from " + this);
}
// Signature<O1,A1> src = source.toSig();
Map<Signature<O1, A1>.Node, Set<Object>> nm = new HashMap<>();
Map<Signature<O1, A1>.Edge, Map<Object, Object>> em = new HashMap<>();
for (O1 o : source.objects()) {
nm.put(src.new Node(o), (Set) applyO(o));
}
for (Signature<O1, A1>.Edge a : src.edges) {
Fn f = (Fn) applyA(a.name);
em.put(a, Util.reify(f::apply, f.source));
}
return new Instance<>(nm, em, src);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class Inst method kernel.
public Transform<O, A, Set, Fn> kernel(Transform<O, A, Set, Fn> L) {
Functor<O, A, Set, Fn> J = L.source;
Map<O, Set> nm = new HashMap<>();
Map<A, Fn> em = new HashMap<>();
Map<O, Fn> t = new HashMap<>();
for (O d : J.source.objects()) {
Set s = new HashSet<>();
for (Object x : J.applyO(d)) {
if (L.apply(d).apply(x).equals(tru().apply(d).apply(new Unit()))) {
s.add(x);
}
}
nm.put(d, s);
t.put(d, new Fn<>(s, J.applyO(d), x -> x));
}
for (A f : J.source.arrows()) {
em.put(f, new Fn<>(nm.get(J.source.source(f)), nm.get(J.source.target(f)), x -> J.applyA(f).apply(x)));
}
Functor<O, A, Set, Fn> I = new Functor<>(cat, FinSet.FinSet, nm::get, em::get);
return new Transform<>(I, J, t::get);
}
use of catdata.fqlpp.cat.FinSet.Fn in project fql by CategoricalData.
the class Inst method split.
private Pair<Functor<O, A, Set, Fn>, Functor<O, A, Set, Fn>> split(Functor<O, A, Set, Fn> I) {
Map<O, Set> nm1 = new HashMap<>();
Map<A, Fn> em1 = new HashMap<>();
Map<O, Set> nm2 = new HashMap<>();
Map<A, Fn> em2 = new HashMap<>();
for (O o : I.source.objects()) {
Set s1 = new HashSet();
Set s2 = new HashSet();
for (Object x : I.applyO(o)) {
Pair p = (Pair) x;
s1.add(p.first);
s2.add(p.second);
}
nm1.put(o, s1);
nm2.put(o, s2);
}
for (A a : I.source.arrows()) {
Map s1 = new HashMap();
Map s2 = new HashMap();
for (Object o : I.applyO(I.source.source(a))) {
Pair q = (Pair) o;
Pair p = (Pair) I.applyA(a).apply(o);
s1.put(q.first, p.first);
s2.put(q.second, p.second);
}
Fn f1 = new Fn(nm1.get(I.source.source(a)), nm1.get(I.source.target(a)), s1::get);
Fn f2 = new Fn(nm2.get(I.source.source(a)), nm2.get(I.source.target(a)), s2::get);
em1.put(a, f1);
em2.put(a, f2);
}
Functor<O, A, Set, Fn> fst = new Functor<>(cat, FinSet.FinSet, nm1::get, em1::get);
Functor<O, A, Set, Fn> snd = new Functor<>(cat, FinSet.FinSet, nm2::get, em2::get);
return new Pair<>(fst, snd);
}
Aggregations