use of catdata.fql.decl.Mapping in project fql by CategoricalData.
the class FinFunctor method toMapping.
/**
* Converts a functor to a mapping by converting the source and target
* categories
*
* @return the mapping, and a bunch of isomorphisms
* @throws FQLException
*/
public Triple<Mapping, Quad<Signature, Pair<Map<ObjA, String>, Map<String, ObjA>>, Pair<Map<Arr<ObjA, ArrowA>, String>, Map<String, Arr<ObjA, ArrowA>>>, Pair<Map<Attribute<ObjA>, String>, Map<String, Attribute<ObjA>>>>, Quad<Signature, Pair<Map<ObjB, String>, Map<String, ObjB>>, Pair<Map<Arr<ObjB, ArrowB>, String>, Map<String, Arr<ObjB, ArrowB>>>, Pair<Map<Attribute<ObjB>, String>, Map<String, Attribute<ObjB>>>>> toMapping(Map<String, Type> types) throws FQLException {
Quad<Signature, Pair<Map<ObjA, String>, Map<String, ObjA>>, Pair<Map<Arr<ObjA, ArrowA>, String>, Map<String, Arr<ObjA, ArrowA>>>, Pair<Map<Attribute<ObjA>, String>, Map<String, Attribute<ObjA>>>> src = srcCat.toSig(types);
Quad<Signature, Pair<Map<ObjB, String>, Map<String, ObjB>>, Pair<Map<Arr<ObjB, ArrowB>, String>, Map<String, Arr<ObjB, ArrowB>>>, Pair<Map<Attribute<ObjB>, String>, Map<String, Attribute<ObjB>>>> dst = dstCat.toSig(types);
Signature srcSig = src.first;
Signature dstSig = dst.first;
Map<Arr<ObjA, ArrowA>, String> srcM = src.third.first;
Map<ObjA, String> srcM2 = src.second.first;
Map<Attribute<ObjA>, String> srcMA = src.fourth.first;
Map<Arr<ObjB, ArrowB>, String> dstM = dst.third.first;
Map<ObjB, String> dstM2 = dst.second.first;
Map<Attribute<ObjB>, String> dstMA = dst.fourth.first;
List<Pair<String, String>> nm = new LinkedList<>();
List<Pair<String, List<String>>> em = new LinkedList<>();
for (Arr<ObjA, ArrowA> a : srcCat.arrows) {
if (srcCat.isId(a)) {
ObjA o = a.src;
ObjB u = objMapping.get(o);
nm.add(new Pair<>(srcM2.get(o), dstM2.get(u)));
} else {
Arr<ObjB, ArrowB> u = arrowMapping.get(a);
List<String> t = new LinkedList<>();
t.add(dstM2.get(u.src));
if (!dstCat.isId(u)) {
t.add(dstM.get(u));
}
em.add(new Pair<>(srcM.get(a), t));
}
}
List<Pair<String, String>> am0 = new LinkedList<>();
for (Attribute<ObjA> k : am.keySet()) {
am0.add(new Pair<>(srcMA.get(k), dstMA.get(am.get(k))));
}
Mapping m = new Mapping(/*n,*/
srcSig, dstSig, nm, am0, em);
return new Triple<>(m, src, dst);
}
use of catdata.fql.decl.Mapping in project fql by CategoricalData.
the class FqlDisplay method showQuery.
private static JPanel showQuery(FQLProgram prog, FqlEnvironment environment, Query view) {
JTabbedPane px = new JTabbedPane();
Mapping d = view.project;
Mapping p = view.join;
Mapping u = view.union;
Signature s = d.target;
Signature i1 = d.source;
Signature i2 = p.target;
Signature t = u.target;
px.add("Source", showSchema("Source", environment, prog.smap(s.toConst()), s));
px.add("Delta", showMapping(environment, prog.smap(i1.toConst()), prog.smap(s.toConst()), d));
px.add("Intermediate 1", showSchema("Int1", environment, prog.smap(i1.toConst()), i1));
px.add("Pi", showMapping(environment, prog.smap(i1.toConst()), prog.smap(i2.toConst()), p));
px.add("Intermediate 2", showSchema("Int2", environment, prog.smap(i2.toConst()), i2));
px.add("Sigma", showMapping(environment, prog.smap(i2.toConst()), prog.smap(t.toConst()), u));
px.add("Target", showSchema("Target", environment, prog.smap(t.toConst()), t));
JPanel top = new JPanel(new GridLayout(1, 1));
top.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
top.add(px);
return top;
}
use of catdata.fql.decl.Mapping 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);
}
use of catdata.fql.decl.Mapping in project fql by CategoricalData.
the class LeftKanCat method toCategory.
public static Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> toCategory(Signature sig) throws FQLException {
Signature A = sig.onlyObjects();
Instance X = A.terminal(null);
Mapping F = subset(A, sig);
LeftKan lk = new LeftKan(0, F, X);
if (!lk.compute()) {
throw new FQLException("Category computation has exceeded allowed iterations.");
}
return helper(lk, sig);
}
use of catdata.fql.decl.Mapping in project fql by CategoricalData.
the class FqlDisplay method handleInstanceFlowEdge.
private void handleInstanceFlowEdge(Object o) {
InstExp i = (InstExp) o;
Object f = i.accept(new Unit(), new InstExpVisitor<Object, Unit>() {
@Override
public MapExp visit(Unit env, Zero e) {
return null;
}
@Override
public MapExp visit(Unit env, One e) {
return null;
}
@Override
public MapExp visit(Unit env, Two e) {
throw new RuntimeException();
}
@Override
public MapExp visit(Unit env, Plus e) {
return null;
}
@Override
public MapExp visit(Unit env, Times e) {
return null;
}
@Override
public MapExp visit(Unit env, Exp e) {
throw new RuntimeException();
}
@Override
public MapExp visit(Unit env, Const e) {
return null;
}
@Override
public MapExp visit(Unit env, Delta e) {
return e.F;
}
@Override
public MapExp visit(Unit env, Sigma e) {
return e.F;
}
@Override
public MapExp visit(Unit env, Pi e) {
return e.F;
}
@Override
public MapExp visit(Unit env, FullSigma e) {
return e.F;
}
@Override
public Unit visit(Unit env, Relationalize e) {
return null;
}
@Override
public Unit visit(Unit env, External e) {
return null;
}
@Override
public Object visit(Unit env, Eval e) {
return e.q;
}
@Override
public Object visit(Unit env, FullEval e) {
return e.q;
}
@Override
public Object visit(Unit env, Kernel e) {
return null;
}
@Override
public Object visit(Unit env, Step e) {
// (Step) this should return a pair
return null;
}
});
if (f == null) {
return;
}
if (f instanceof QueryExp) {
QueryExp q = (QueryExp) f;
if (q instanceof QueryExp.Var) {
QueryExp.Var qq = (QueryExp.Var) q;
yyy.setSelectedValue(indices.get(qq.v), true);
return;
}
String k = FQLProgram.revLookup(prog.queries, q);
if (k != null) {
yyy.setSelectedValue(indices.get(k), true);
return;
}
String str = q.toString();
if (!extraInsts.contains(str)) {
Query view = q.toQuery(prog);
JPanel p = showQuery(prog, env, view);
x.add(p, str);
extraInsts.add(str);
}
yyy.clearSelection();
cl.show(x, str);
} else if (f instanceof FullQueryExp) {
FullQueryExp q = (FullQueryExp) f;
if (q instanceof FullQueryExp.Var) {
FullQueryExp.Var qq = (FullQueryExp.Var) q;
yyy.setSelectedValue(indices.get(qq.v), true);
return;
}
String k = FQLProgram.revLookup(prog.full_queries, q);
if (k != null) {
yyy.setSelectedValue(indices.get(k), true);
return;
}
String str = q.toString();
if (!extraInsts.contains(str)) {
FullQuery view = q.toFullQuery(prog);
JPanel p = showFullQuery(prog, env, view, q);
x.add(p, str);
extraInsts.add(str);
}
yyy.clearSelection();
cl.show(x, str);
} else if (f instanceof MapExp) {
MapExp q = (MapExp) f;
if (q instanceof MapExp.Var) {
MapExp.Var qq = (MapExp.Var) q;
yyy.setSelectedValue(indices.get(qq.v), true);
return;
}
String k = FQLProgram.revLookup(prog.maps, q);
if (k != null) {
yyy.setSelectedValue(indices.get(k), true);
return;
}
String str = q.toString();
if (!extraInsts.contains(str)) {
Mapping view = q.toMap(prog);
JPanel p = showMapping(env, prog.smap(view.source.toConst()), prog.smap(view.target.toConst()), view);
x.add(p, str);
extraInsts.add(str);
}
yyy.clearSelection();
cl.show(x, str);
} else {
throw new RuntimeException();
}
}
Aggregations