use of catdata.fqlpp.cat.Signature.Node in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ToMap e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
CatExp scat = resolve(env, e.s);
if (!(scat instanceof Const)) {
throw new RuntimeException("Source category of " + e + " is not a constant.");
}
// CatExp.Const scon = (CatExp.Const) scat;
CatExp tcat = resolve(env, e.t);
if (!(tcat instanceof Const)) {
throw new RuntimeException("Target category of " + e + " is not a constant.");
}
Const tcon = (Const) tcat;
// Signature ssig = new Signature(scon.nodes, scon.arrows, scon.eqs);
Signature<String, String> tsig = new Signature<>(tcon.nodes, tcon.arrows, tcon.eqs);
FUNCTION o = x -> {
Node n = (Node) x;
// Set src = (Set) s.applyO(n);
// Set dst = (Set) t.applyO(n);
Pair<String, List<String>> k = e.fun.get(n.name);
Signature<String, String>.Path fun = tsig.path(k.first, k.second);
// new Fn(src, dst, fun);
return fun;
};
return new Transform(s, t, o);
}
use of catdata.fqlpp.cat.Signature.Node 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));
}
use of catdata.fqlpp.cat.Signature.Node in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Functor visit(FQLPPProgram env, Apply e) {
Functor ret1 = null;
Exception ret1_e = null;
Functor ret2 = null;
Exception ret2_e = null;
Functor F = e.F.accept(env, this);
try {
Functor I = e.I.accept(env, this);
ret1 = (Functor) F.applyO(I);
} catch (Exception ex) {
ret1_e = ex;
}
try {
Var I = (Var) e.I;
Node n = F.source.toSig().new Node(I.v);
ret2 = (Functor) F.applyO(n);
} catch (Exception ex) {
ret2_e = ex;
}
if (ret1 != null && ret2 != null) {
throw new RuntimeException("Ambiguous: " + e.I + " is an object in two different categories.");
}
if (ret1 != null) {
return ret1;
}
if (ret2 != null) {
return ret2;
}
if (ret1_e != null) {
// TODO !!!
ret1_e.printStackTrace();
}
if (ret2_e != null) {
ret2_e.printStackTrace();
}
throw new RuntimeException("Cannot apply:\n\nmost probable cause: " + ret1_e + "\n\nless probable cause: " + ret2_e);
}
use of catdata.fqlpp.cat.Signature.Node in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, PeterApply e) {
Transform t = e.t.accept(env, this);
Node n = t.source.source.toSig().new Node(e.node);
return (Transform) t.apply(n);
}
use of catdata.fqlpp.cat.Signature.Node in project fql by CategoricalData.
the class CatOps method visit.
@Override
public Transform visit(FQLPPProgram env, ToInst e) {
Functor s = e.src.accept(env, this);
Functor t = e.dst.accept(env, this);
FUNCTION o = x -> {
Node n = (Node) x;
// Set src = (Set) s.applyO(n);
// Set dst = (Set) t.applyO(n);
Transform fun = e.fun.get(n.name).accept(env, this);
// new Fn(src, dst, fun);
return fun;
};
return new Transform(s, t, o);
}
Aggregations