use of catdata.fql.decl.Path in project fql by CategoricalData.
the class PSMEval method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
Quad<Instance, Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>>, Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>>, Map<Node, Map<Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>, Object>>> xxx = interp.exps2.get(AB);
Instance Jw = xxx.first;
Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>> map = xxx.second;
Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>> map2 = xxx.third;
FinCat<Node, Path> cat = Jw.thesig.toCategory2().first;
Instance abb = new Instance(sig, PSMGen.gather(ABB, sig, state));
// Instance ab = new Instance(sig, PSMGen.gather(AB, sig, state));
// //already have in interp
Instance a = new Instance(sig, PSMGen.gather(A, sig, state));
Instance b = new Instance(sig, PSMGen.gather(B, sig, state));
Transform fst = new Transform(abb, Jw, PSMGen.gather(ABB + "_fst", sig, state));
Transform snd = new Transform(abb, b, PSMGen.gather(ABB + "_snd", sig, state));
List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
for (Node n : sig.nodes) {
List<Pair<Object, Object>> d = new LinkedList<>();
Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>> m2 = map2.get(n);
for (Pair<Object, Object> id : abb.data.get(n.string)) {
Object id_ab = lookup(fst.data.get(n.string), id.first);
Object x = lookup(snd.data.get(n.string), id.first);
Transform t = m2.get(id_ab).second;
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> w = m2.get(id_ab).first;
Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>> m = map.get(new Pair<>(n, w));
Object y = m.third.get(n).get(new Pair<>(cat.id(n), x));
Object f = lookup(t.data.get(n.string), y);
d.add(new Pair<>(id.first, f));
}
data.add(new Pair<>(n.string, d));
}
Transform curry = new Transform(abb, a, data);
PSMGen.shred(pre, curry, state);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
use of catdata.fql.decl.Path 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.Path 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.Path 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;
}
use of catdata.fql.decl.Path in project fql by CategoricalData.
the class Inst method stuff.
// base^exp
public static FinCat<Mapping, Map<Node, Path>> stuff(Signature base, Signature exp) throws FQLException {
Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> xxx = base.toCategory2();
FinCat<Node, Path> base0 = xxx.first;
Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> yyy = exp.toCategory2();
FinCat<Node, Path> exp0 = yyy.first;
List<LinkedHashMap<Node, Node>> nms = homomorphs(exp.nodes, base.nodes);
List<Mapping> mappings = new LinkedList<>();
for (LinkedHashMap<Node, Node> nm : nms) {
LinkedHashMap<Attribute<Node>, List<Attribute<Node>>> ams = new LinkedHashMap<>();
for (Attribute<Node> a : exp.attrs) {
ams.put(a, base.attrsFor(nm.get(a.source)));
}
LinkedHashMap<Edge, List<Path>> ems = new LinkedHashMap<>();
for (Edge e : exp.edges) {
Set<Arr<Node, Path>> s = base0.hom(nm.get(e.source), nm.get(e.target));
List<Path> p = new LinkedList<>();
for (Arr<Node, Path> sx : s) {
p.add(sx.arr);
}
ems.put(e, p);
}
List<LinkedHashMap<Attribute<Node>, Attribute<Node>>> ams0 = homomorphs(ams);
List<LinkedHashMap<Edge, Path>> ems0 = homomorphs(ems);
for (LinkedHashMap<Attribute<Node>, Attribute<Node>> am : ams0) {
for (LinkedHashMap<Edge, Path> em : ems0) {
try {
Mapping m = new Mapping(true, exp, base, nm, em, am);
mappings.add(m);
} catch (Exception e) {
}
}
}
}
List<Arr<Mapping, Map<Node, Path>>> arrows = new LinkedList<>();
for (Mapping s : mappings) {
for (Mapping t : mappings) {
Map<Node, List<Path>> map = new HashMap<>();
for (Node n : exp.nodes) {
List<Path> p = new LinkedList<>();
for (Arr<Node, Path> k : base0.hom(s.nm.get(n), t.nm.get(n))) {
p.add(k.arr);
}
map.put(n, p);
}
List<LinkedHashMap<Node, Path>> map0 = homomorphs(map);
outer: for (Map<Node, Path> k : map0) {
for (Node x : k.keySet()) {
for (Node y : k.keySet()) {
for (Arr<Node, Path> f : exp0.hom(x, y)) {
Path lhs = Path.append(base, k.get(x), t.appy(base, f.arr));
Path rhs = Path.append(base, s.appy(base, f.arr), k.get(y));
if (!xxx.second.of(lhs).equals(xxx.second.of(rhs))) {
continue outer;
}
}
}
}
arrows.add(new Arr<>(k, s, t));
}
}
}
Map<Mapping, Arr<Mapping, Map<Node, Path>>> identities = new HashMap<>();
for (Mapping m : mappings) {
Map<Node, Path> map = new HashMap<>();
for (Node n : m.source.nodes) {
map.put(n, new Path(m.target, m.nm.get(n)));
}
Arr<Mapping, Map<Node, Path>> uuu = new Arr<>(map, m, m);
identities.put(m, new Arr<>(map, m, m));
if (!arrows.contains(uuu)) {
arrows.add(uuu);
}
}
Map<Pair<Arr<Mapping, Map<Node, Path>>, Arr<Mapping, Map<Node, Path>>>, Arr<Mapping, Map<Node, Path>>> composition = new HashMap<>();
for (Arr<Mapping, Map<Node, Path>> a1 : arrows) {
for (Arr<Mapping, Map<Node, Path>> a2 : arrows) {
if (!a1.dst.equals(a2.src)) {
continue;
}
Map<Node, Path> m = new HashMap<>();
for (Node n : exp.nodes) {
m.put(n, xxx.second.of(Path.append(base, a1.arr.get(n), a2.arr.get(n))).arr);
}
composition.put(new Pair<>(a1, a2), new Arr<>(m, a1.src, a2.dst));
}
}
return new FinCat<>(mappings, arrows, composition, identities);
}
Aggregations