use of catdata.fql.Fn in project fql by CategoricalData.
the class Relationalizer method terminal.
public static Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> terminal(FQLProgram prog, SigExp.Const sig0) {
Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> jjj = cache.get(new Pair<>(prog, sig0));
if (jjj != null) {
// so do not have to recompute when doing omega operations
return jjj;
}
try {
Signature sig = sig0.toSig(prog);
Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> start = sig.toCategory2();
// FinCat<Node, Path> cat = start.first;
Fn<Path, Arr<Node, Path>> map = start.second;
Map<Node, List<Pair<Arr<Node, Path>, Attribute<Node>>>> obs = sig.obs();
Map<Node, List<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m = sig.obsbar();
List<Pair<String, List<Pair<Object, Object>>>> nodes = new LinkedList<>();
List<Pair<String, List<Pair<Object, Object>>>> attrs = new LinkedList<>();
List<Pair<String, List<Pair<Object, Object>>>> arrows = new LinkedList<>();
// Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m1 = new HashMap<>();
Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>> m2 = new HashMap<>();
int i = 0;
for (Node n : sig.nodes) {
Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> map1 = new HashMap<>();
Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object> map2 = new HashMap<>();
List<Pair<Object, Object>> set = new LinkedList<>();
m1.put(n, map1);
m2.put(n, map2);
for (LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> i2 : m.get(n)) {
Object o = Integer.toString(++i);
map1.put(o, i2);
map2.put(i2, o);
set.add(new Pair<>(o, o));
}
nodes.add(new Pair<>(n.string, set));
}
for (Attribute<Node> a : sig.attrs) {
List<Pair<Object, Object>> set = new LinkedList<>();
for (Pair<Object, Object> k : PropPSM.lookup(nodes, a.source.string)) {
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = m1.get(a.source).get(k.first);
set.add(new Pair<>(k.first, new_id.get(new Pair<>(map.of(new Path(sig, a.source)), a))));
}
attrs.add(new Pair<>(a.name, set));
}
for (Edge a : sig.edges) {
List<Pair<Object, Object>> set = new LinkedList<>();
for (Pair<Object, Object> k : PropPSM.lookup(nodes, a.source.string)) {
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = m1.get(a.source).get(k.first);
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = PropPSM.truncate2(sig, new_id, new Arr<>(new Path(sig, a), a.source, a.target), obs.get(a.target));
// LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = PropPSM.truncate(sig, new_id, a, m.get(a.target));
Object o = m2.get(a.target).get(new_id0);
set.add(new Pair<>(k.first, o));
}
arrows.add(new Pair<>(a.name, set));
}
// Instance ret0 = new Instance(sig, data);
Const retX = new Const(nodes, attrs, arrows, sig.toConst());
Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> ret = new Triple<>(retX, m1, m2);
cache.put(new Pair<>(prog, sig0), ret);
return ret;
} catch (FQLException fe) {
throw new RuntimeException(fe.getLocalizedMessage());
}
}
use of catdata.fql.Fn 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.Fn in project fql by CategoricalData.
the class SigOps method prod.
private static Pair<Quad<SigExp.Const, Const, Const, Fn<Triple<SigExp.Const, Const, Const>, Const>>, Quad<Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>, Map<Pair<String, String>, String>>> prod(SigExp.Const a, SigExp.Const b) {
int node_count = 0;
Map<Pair<String, String>, String> node_map = new LinkedHashMap<>();
// fst
List<Pair<String, String>> a_objs = new LinkedList<>();
// snd
List<Pair<String, String>> b_objs = new LinkedList<>();
for (String n : a.nodes) {
for (String m : b.nodes) {
node_map.put(new Pair<>(n, m), "node" + node_count);
a_objs.add(new Pair<>("node" + node_count, n));
b_objs.add(new Pair<>("node" + node_count, m));
node_count++;
}
}
List<String> nodes = new LinkedList<>();
nodes.addAll(node_map.values());
int attr_count = 0;
Map<Pair<String, String>, String> attr_map = new LinkedHashMap<>();
// fst
List<Pair<String, String>> a_attrs = new LinkedList<>();
// snd
List<Pair<String, String>> b_attrs = new LinkedList<>();
List<Triple<String, String, String>> attrs = new LinkedList<>();
for (Triple<String, String, String> n : a.attrs) {
for (Triple<String, String, String> m : b.attrs) {
if (!n.third.equals(m.third)) {
continue;
}
String k = node_map.get(new Pair<>(n.second, m.second));
attrs.add(new Triple<>("attr" + attr_count, k, n.third));
attr_map.put(new Pair<>(n.first, m.first), "attr" + attr_count);
a_attrs.add(new Pair<>("attr" + attr_count, n.first));
b_attrs.add(new Pair<>("attr" + attr_count, m.first));
attr_count++;
}
}
int edge_count = 0;
Map<Pair<String, String>, String> edge_map_1 = new LinkedHashMap<>();
Map<Pair<String, String>, String> edge_map_2 = new LinkedHashMap<>();
// fst
List<Pair<String, List<String>>> a_edges = new LinkedList<>();
// snd
List<Pair<String, List<String>>> b_edges = new LinkedList<>();
List<Triple<String, String, String>> edges = new LinkedList<>();
for (Triple<String, String, String> n : a.arrows) {
for (String m : b.nodes) {
String k1 = node_map.get(new Pair<>(n.second, m));
String k2 = node_map.get(new Pair<>(n.third, m));
edges.add(new Triple<>("edge" + edge_count, k1, k2));
edge_map_1.put(new Pair<>(n.first, m), "edge" + edge_count);
List<String> al = new LinkedList<>();
al.add(n.second);
al.add(n.first);
a_edges.add(new Pair<>("edge" + edge_count, al));
List<String> bl = new LinkedList<>();
bl.add(m);
b_edges.add(new Pair<>("edge" + edge_count, bl));
edge_count++;
}
}
for (Triple<String, String, String> n : b.arrows) {
for (String m : a.nodes) {
String k1 = node_map.get(new Pair<>(m, n.second));
String k2 = node_map.get(new Pair<>(m, n.third));
edges.add(new Triple<>("edge" + edge_count, k1, k2));
edge_map_2.put(new Pair<>(n.first, m), "edge" + edge_count);
List<String> al = new LinkedList<>();
al.add(n.second);
al.add(n.first);
b_edges.add(new Pair<>("edge" + edge_count, al));
List<String> bl = new LinkedList<>();
bl.add(m);
a_edges.add(new Pair<>("edge" + edge_count, bl));
edge_count++;
}
}
List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
for (Triple<String, String, String> n : a.arrows) {
for (Triple<String, String, String> m : b.arrows) {
List<String> lhs = new LinkedList<>();
List<String> rhs = new LinkedList<>();
String src = node_map.get(new Pair<>(n.second, m.second));
String lhs1 = edge_map_1.get(new Pair<>(n.first, m.second));
String lhs2 = edge_map_2.get(new Pair<>(m.first, n.third));
lhs.add(src);
lhs.add(lhs1);
lhs.add(lhs2);
String rhs1 = edge_map_2.get(new Pair<>(m.first, n.second));
String rhs2 = edge_map_1.get(new Pair<>(n.first, m.third));
rhs.add(src);
rhs.add(rhs1);
rhs.add(rhs2);
eqs.add(new Pair<>(lhs, rhs));
}
}
for (Pair<List<String>, List<String>> eqA : a.eqs) {
for (String srcB : b.nodes) {
List<String> lhsA = new LinkedList<>(eqA.first);
List<String> rhsA = new LinkedList<>(eqA.second);
String srcA = lhsA.remove(0);
rhsA.remove(0);
String src = node_map.get(new Pair<>(srcA, srcB));
List<String> lhs = new LinkedList<>();
List<String> rhs = new LinkedList<>();
lhs.add(src);
rhs.add(src);
for (String k : lhsA) {
lhs.add(edge_map_1.get(new Pair<>(k, srcB)));
}
for (String k : rhsA) {
rhs.add(edge_map_1.get(new Pair<>(k, srcB)));
}
eqs.add(new Pair<>(lhs, rhs));
}
}
for (Pair<List<String>, List<String>> eqA : b.eqs) {
for (String srcB : a.nodes) {
List<String> lhsA = new LinkedList<>(eqA.first);
List<String> rhsA = new LinkedList<>(eqA.second);
String srcA = lhsA.remove(0);
rhsA.remove(0);
String src = node_map.get(new Pair<>(srcB, srcA));
List<String> lhs = new LinkedList<>();
List<String> rhs = new LinkedList<>();
lhs.add(src);
rhs.add(src);
for (String k : lhsA) {
lhs.add(edge_map_2.get(new Pair<>(k, srcB)));
}
for (String k : rhsA) {
rhs.add(edge_map_2.get(new Pair<>(k, srcB)));
}
eqs.add(new Pair<>(lhs, rhs));
}
}
SigExp.Const sig = new SigExp.Const(nodes, attrs, edges, eqs);
Const fst = new Const(a_objs, a_attrs, a_edges, sig, a);
Const snd = new Const(b_objs, b_attrs, b_edges, sig, b);
Fn<Triple<SigExp.Const, Const, Const>, Const> pair = x -> {
SigExp.Const c = x.first;
Const f = x.second;
Const g = x.third;
if (!f.src.equals(g.src)) {
throw new RuntimeException("Sources don't agree: " + f.src + " and " + g.src);
}
if (!f.dst.equals(a)) {
throw new RuntimeException("Target of " + f + " is not " + a);
}
if (!g.dst.equals(b)) {
throw new RuntimeException("Target of " + g + "is not " + b);
}
List<Pair<String, String>> objs = new LinkedList<>();
for (String obj_c : c.nodes) {
objs.add(new Pair<>(obj_c, node_map.get(new Pair<>(lookup(obj_c, f.objs), lookup(obj_c, g.objs)))));
}
List<Pair<String, String>> attrs1 = new LinkedList<>();
for (Triple<String, String, String> attr_c : c.attrs) {
attrs1.add(new Pair<>(attr_c.first, attr_map.get(new Pair<>(lookup(attr_c.first, f.attrs), lookup(attr_c.first, g.attrs)))));
}
List<Pair<String, List<String>>> arrows = new LinkedList<>();
for (Triple<String, String, String> edge_c : c.arrows) {
List<String> fc = lookup(edge_c.first, f.arrows);
List<String> gc = lookup(edge_c.first, g.arrows);
List<String> ret = new LinkedList<>();
String fcN = fc.get(0);
String gcN = gc.get(0);
String node_start = node_map.get(new Pair<>(fcN, gcN));
ret.add(node_start);
for (int i = 1; i < fc.size(); i++) {
String fcE = fc.get(i);
Pair<String, String> p = new Pair<>(fcE, gcN);
String v = edge_map_1.get(p);
ret.add(v);
}
node_start = lookup(edge_c.third, f.objs);
for (int i = 1; i < gc.size(); i++) {
String gcE = gc.get(i);
Pair<String, String> p = new Pair<>(gcE, node_start);
String v = edge_map_2.get(p);
ret.add(v);
}
arrows.add(new Pair<>(edge_c.first, ret));
}
Const ret = new Const(objs, attrs1, arrows, c, sig);
return ret;
};
return new Pair<>(new Quad<>(sig, fst, snd, pair), new Quad<>(node_map, attr_map, edge_map_1, edge_map_2));
}
use of catdata.fql.Fn in project fql by CategoricalData.
the class PSMGen method pi.
public static Pair<List<PSM>, Map<String, Triple<Node, Node, Arr<Node, Path>>[]>> pi(Mapping F0, String src, String dst) throws FQLException {
tempTables = 0;
Signature D0 = F0.target;
Signature C0 = F0.source;
Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> kkk = D0.toCategory2();
FinCat<Node, Path> D = kkk.first;
FinCat<Node, Path> C = C0.toCategory2().first;
FinFunctor<Node, Path, Node, Path> F = F0.toFunctor2().first;
List<PSM> ret = new LinkedList<>();
Map<String, Triple<Node, Node, Arr<Node, Path>>[]> colmap = new HashMap<>();
Map<String, Attribute<Node>[]> amap = new HashMap<>();
List<Node> doNotDrop = new LinkedList<>();
for (Node d0 : D.objects) {
CommaCat<Node, Path, Node, Path, Node, Path> B = doComma(D, C, F, d0, D0);
Map<Triple<Node, Node, Arr<Node, Path>>, String> xxx1 = new HashMap<>();
Map<Pair<Arr<Node, Path>, Arr<Node, Path>>, String> xxx2 = new HashMap<>();
List<PSM> xxx3 = deltaX(src, xxx1, xxx2, B.projB);
ret.addAll(xxx3);
Triple<Flower, Triple<Node, Node, Arr<Node, Path>>[], Attribute<Node>[]> xxx = lim(src, C0, D, B, xxx1, xxx2);
// comma cat is empty, need unit for product
if (xxx == null) {
doNotDrop.add(d0);
Map<String, String> attrs2 = new HashMap<>();
attrs2.put("guid", PSM.VARCHAR());
ret.add(new CreateTable(dst + "_" + d0.string + "_limit", attrs2, false));
ret.add(new InsertEmptyKeygen(dst + "_" + d0.string + "_limit"));
ret.add(new InsertSQL(dst + "_" + d0.string, new SquishFlower(dst + "_" + d0.string + "_limit"), "c0", "c1"));
@SuppressWarnings("unchecked") Triple<Node, Node, Arr<Node, Path>>[] cols = new Triple[0];
colmap.put(d0.string, cols);
continue;
}
Triple<Node, Node, Arr<Node, Path>>[] cols = xxx.second;
Flower r = xxx.first;
for (Attribute<Node> a : D0.attrsFor(d0)) {
List<Attribute<Node>> ls = new LinkedList<>();
for (Attribute<Node> aa : C0.attrs) {
if (F.am.get(aa).equals(a)) {
ls.add(aa);
}
}
for (int jj = 1; jj < ls.size(); jj++) {
int xxx02 = cnamelkp(xxx.third, ls.get(0));
int xxx04 = cnamelkp(xxx.third, ls.get(jj));
r.where.add(new Pair<>(new Pair<>("t" + (xxx02 + xxx.second.length), "c1"), new Pair<>("t" + (xxx04 + xxx.second.length), "c1")));
}
}
colmap.put(d0.string, cols);
amap.put(d0.string, xxx.third);
Map<String, String> attrs1 = new HashMap<>();
for (int i = 0; i < xxx.second.length; i++) {
attrs1.put("c" + i, PSM.VARCHAR());
}
for (int j = 0; j < xxx.third.length; j++) {
attrs1.put("c" + (xxx.second.length + j), xxx.third[j].target.psm());
}
Map<String, String> attrs2 = new HashMap<>(attrs1);
attrs2.put("guid", PSM.VARCHAR());
List<String> attcs = new LinkedList<>(attrs1.keySet());
ret.add(new CreateTable(dst + "_" + d0.string + "_limnoguid", attrs1, false));
ret.add(new InsertSQL2(dst + "_" + d0.string + "_limnoguid", r, new LinkedList<>(r.select.keySet())));
ret.add(new CreateTable(dst + "_" + d0.string + "_limit", attrs2, false));
ret.add(new InsertKeygen(dst + "_" + d0.string + "_limit", "guid", dst + "_" + d0.string + "_limnoguid", attcs));
// craeted by createTables
// ret.add(new CreateTable(dst + "_" + d0.string, twocol_attrs));
ret.add(new InsertSQL(dst + "_" + d0.string, new SquishFlower(dst + "_" + d0.string + "_limit"), "c0", "c1"));
}
for (Edge s : F0.target.edges) {
Node dA = s.source;
Node dB = s.target;
String q2 = dB.string;
String q1 = dA.string;
Triple<Node, Node, Arr<Node, Path>>[] q2cols = colmap.get(q2);
Triple<Node, Node, Arr<Node, Path>>[] q1cols = colmap.get(q1);
if (q2cols == null) {
throw new RuntimeException("Cannot find " + q2 + " in " + colmap);
}
List<Pair<Pair<String, String>, Pair<String, String>>> where = subset(D, kkk.second.of(new Path(D0, s)), dst, q2cols, q1cols, q2, q1);
Map<String, String> from = new HashMap<>();
from.put(dst + "_" + q1 + "_limit_1", dst + "_" + q1 + "_limit");
from.put(dst + "_" + q2 + "_limit_2", dst + "_" + q2 + "_limit");
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
select.put("c0", new Pair<>(dst + "_" + q1 + "_limit_1", "guid"));
select.put("c1", new Pair<>(dst + "_" + q2 + "_limit_2", "guid"));
Flower f = new Flower(select, from, where);
ret.add(new InsertSQL(dst + "_" + s.name, f, "c0", "c1"));
}
for (Attribute<Node> a : F0.target.attrs) {
int i = colmap.get(a.source.string).length;
Attribute<Node>[] y = amap.get(a.source.string);
if (y == null) {
throw new FQLException("Attribute mapping not surjective " + a.source.string);
}
boolean found = false;
int u = 0;
// int j = -1;
List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
Map<String, String> from = new HashMap<>();
List<Integer> xxx = new LinkedList<>();
for (Attribute<Node> b : y) {
if (!F0.am.get(b).equals(a)) {
u++;
continue;
}
found = true;
xxx.add(u);
u++;
}
if (!found) {
throw new FQLException("Attribute mapping not found " + a);
}
from.put(dst + "_" + a.source + "_limit", dst + "_" + a.source + "_limit");
select.put("c0", new Pair<>(dst + "_" + a.source + "_limit", "guid"));
for (int jj = 1; jj < xxx.size(); jj++) {
where.add(new Pair<>(new Pair<>(dst + "_" + a.source + "_limit", "c" + (xxx.get(0) + i)), new Pair<>(dst + "_" + a.source + "_limit", "c" + (xxx.get(jj) + i))));
}
select.put("c1", new Pair<>(dst + "_" + a.source + "_limit", "c" + (xxx.get(0) + i)));
Flower f = new Flower(select, from, where);
ret.add(new InsertSQL(dst + "_" + a.name, f, "c0", "c1"));
// project guid and u+i
}
for (Node d0 : D.objects) {
if (doNotDrop.contains(d0)) {
continue;
}
ret.add(new DropTable(dst + "_" + d0.string + "_limnoguid"));
}
for (int ii = 0; ii < tempTables; ii++) {
ret.add(new DropTable("temp" + ii));
}
return new Pair<>(ret, colmap);
}
use of catdata.fql.Fn in project fql by CategoricalData.
the class PropPSM method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
IntRef ref = new IntRef(interp.guid);
Signature sigX = new Signature(sig.nodes, sig.edges, new LinkedList<>(), sig.eqs);
Map<Node, List<Pair<Arr<Node, Path>, Attribute<Node>>>> obs = sig.obs();
Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> ooo = sig.toCategory2();
Fn<Path, Arr<Node, Path>> fn = ooo.second;
Pair<Pair<Map<Node, Triple<Instance, Map<Object, Path>, Map<Path, Object>>>, Map<Edge, Transform>>, Pair<Instance, Map<Node, Pair<Map<Object, Instance>, Map<Instance, Object>>>>> xxx = sigX.omega(ref);
interp.prop1.put(pre, xxx.first);
interp.prop2.put(pre, xxx.second);
Instance old = xxx.second.first;
Map<Node, List<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m = sig.obsbar();
Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
Map<Node, Map<Object, Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>> m1 = new HashMap<>();
Map<Node, Map<Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Object>> m2 = new HashMap<>();
for (Node n : sig.nodes) {
Map<Object, Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> map1 = new HashMap<>();
Map<Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Object> map2 = new HashMap<>();
Set<Pair<Object, Object>> set = new HashSet<>();
m1.put(n, map1);
m2.put(n, map2);
for (Pair<Object, Object> i1 : old.data.get(n.string)) {
for (LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> i2 : m.get(n)) {
Object o = Integer.toString(++ref.i);
map1.put(o, new Pair<>(i1.first, i2));
map2.put(new Pair<>(i1.first, i2), o);
set.add(new Pair<>(o, o));
}
}
data.put(n.string, set);
}
for (Attribute<Node> a : sig.attrs) {
Set<Pair<Object, Object>> set = new HashSet<>();
for (Pair<Object, Object> k : data.get(a.source.string)) {
Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> kk = m1.get(a.source).get(k.first);
// Object old_id = kk.first;
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = kk.second;
set.add(new Pair<>(k.first, new_id.get(new Pair<>(new Arr<>(new Path(sig, a.source), a.source, a.source), a))));
}
data.put(a.name, set);
}
for (Edge a : sig.edges) {
Set<Pair<Object, Object>> set = new HashSet<>();
for (Pair<Object, Object> k : data.get(a.source.string)) {
Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> kk = m1.get(a.source).get(k.first);
Object old_id = kk.first;
Object old_id0 = lookup(old.data.get(a.name), old_id);
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = kk.second;
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = truncate2(sig, new_id, fn.of(new Path(sig, a)), obs.get(a.target));
Object o = m2.get(a.target).get(new Pair<>(old_id0, new_id0));
set.add(new Pair<>(k.first, o));
}
data.put(a.name, set);
}
interp.prop3.put(pre, m1);
interp.prop4.put(pre, m2);
Instance ne = new Instance(sig, data);
PSMGen.shred(pre, ne, state);
interp.guid = ref.i;
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
Aggregations