use of catdata.fqlpp.FunctorExp.InstConst in project fql by CategoricalData.
the class PPParser method toInstConst.
// @SuppressWarnings("rawtypes")
private static FunctorExp toInstConst(Object decl) {
Tuple3 y = (Tuple3) decl;
org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
Tuple3 nodes = (Tuple3) x.a;
Tuple3 arrows = (Tuple3) x.b;
List nodes0 = (List) nodes.b;
List arrows0 = (List) arrows.b;
Map<String, SetExp> nodesX = new HashMap<>();
for (Object o : nodes0) {
if (nodesX.containsKey(o)) {
throw new RuntimeException("Duplicate object: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
SetExp l = toSet(u.c);
nodesX.put(n, l);
}
Map<String, Chc<FnExp, SetExp>> arrowsX = new HashMap<>();
for (Object o : arrows0) {
if (arrowsX.containsKey(o)) {
throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
try {
FnExp l = toFn(u.c);
arrowsX.put(n, Chc.inLeft(l));
} catch (Exception eee) {
SetExp l = toSet(u.c);
arrowsX.put(n, Chc.inRight(l));
}
}
InstConst ret = new InstConst(toCat(y.c), nodesX, arrowsX);
return ret;
}
use of catdata.fqlpp.FunctorExp.InstConst in project fql by CategoricalData.
the class CatOps method toInstance.
private Pair<Category, Instance<String, String>> toInstance(FQLPPProgram env, InstConst ic) {
CatExp e = resolve(env, ic.sig);
if (!(e instanceof Const)) {
throw new RuntimeException("Can only create instances for finitely-presented categories.");
}
Const c = (Const) e;
Category src = c.accept(env, this);
Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);
Map<Node, Set> nm = new HashMap<>();
for (String n0 : ic.nm.keySet()) {
Node n = sig.getNode(n0);
SetExp kkk = ic.nm.get(n.name);
if (kkk == null) {
throw new RuntimeException("Missing node mapping from " + n);
}
nm.put(n, kkk.accept(env, new SetOps(ENV)));
}
Map<Edge, Map> em = new HashMap<>();
for (String n0 : ic.em.keySet()) {
Edge n = sig.getEdge(n0);
Chc<FnExp, SetExp> chc = ic.em.get(n.name);
if (chc == null) {
throw new RuntimeException("Missing edge mapping from " + n);
}
if (chc.left) {
FnExp kkk = chc.l;
em.put(n, kkk.accept(env, new SetOps(ENV)).toMap());
} else {
SetExp sss = chc.r;
Set vvv = sss.accept(env, new SetOps(ENV));
Map<Object, Object> uuu = new HashMap<>();
for (Object o : vvv) {
if (!(o instanceof Pair)) {
throw new RuntimeException("Not a pair: " + o);
}
Pair oo = (Pair) o;
if (uuu.containsKey(oo.first)) {
throw new RuntimeException("Duplicate domain entry: " + o + " in " + ic);
}
uuu.put(oo.first, oo.second);
}
FnExp kkk = new FnExp.Const(uuu::get, ic.nm.get(n.source.name), ic.nm.get(n.target.name));
em.put(n, kkk.accept(env, new SetOps(ENV)).toMap());
}
}
return new Pair<>(src, new Instance(nm, em, sig));
}
Aggregations