use of catdata.fql.decl.Path in project fql by CategoricalData.
the class PSMAnd method implies.
private Instance implies(Signature sig0, Pair<Map<Node, Triple<Instance, Map<Object, Path>, Map<Path, Object>>>, Map<Edge, Transform>> H1, Triple<Instance, Map<Object, Path>, Map<Path, Object>> Hc, Instance A, Instance B) throws FQLException {
Map<String, Set<Pair<Object, Object>>> notA_data = new HashMap<>();
for (Node d : sig.nodes) {
Set<Pair<Object, Object>> dd = new HashSet<>();
xxx: for (Object f : Hc.first.getNode(d)) {
Path ff = Hc.second.get(f);
for (Node d0 : sig.nodes) {
for (Arr<Node, Path> g : sig.toCategory2().first.hom(d, d0)) {
Arr<Node, Path> fg = sig.toCategory2().first.compose(sig.toCategory2().second.of(ff), g);
Object xxx = H1.first.get(d0).third.get(fg.arr);
if (xxx == null) {
throw new RuntimeException();
}
if (!A.getNode(d0).contains(xxx) || B.getNode(d0).contains(xxx)) {
} else {
continue xxx;
}
}
}
dd.add(new Pair<>(f, f));
}
notA_data.put(d.string, dd);
}
for (Edge h : sig.edges) {
Set<Pair<Object, Object>> dd = new HashSet<>();
for (Object f : notA_data.get(h.source.string)) {
Path ff = Hc.second.get(f);
Arr<Node, Path> fg = sig.toCategory2().first.compose(sig.toCategory2().second.of(ff), sig.toCategory2().second.of(new Path(sig, h)));
Object xxx = Hc.third.get(fg.arr);
dd.add(new Pair<>(f, xxx));
}
notA_data.put(h.name, dd);
}
Instance notA = new Instance(sig0, notA_data);
return notA;
}
use of catdata.fql.decl.Path in project fql by CategoricalData.
the class PSMBool method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
Signature sig0 = new Signature(sig.nodes, sig.edges, new LinkedList<>(), sig.eqs);
Instance unitI = new Instance(sig, PSMGen.gather(unit, sig, state));
Instance propI = new Instance(sig, PSMGen.gather(prop, sig, state));
Map<Node, Map<Object, Object>> subst_inv = new HashMap<>();
for (Node n : sig.nodes) {
Map<Object, Object> m = new HashMap<>();
Set<Map<Object, Object>> g = state.get(unit + "_" + n + "_subst_inv");
for (Map<Object, Object> j : g) {
m.put(j.get("c0"), j.get("c1"));
}
subst_inv.put(n, m);
}
List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
for (Node n : sig.nodes) {
List<Pair<Object, Object>> set = new LinkedList<>();
for (Pair<Object, Object> k : unitI.data.get(n.string)) {
Object k0 = subst_inv.get(n).get(k.first);
if (k0 == null) {
throw new RuntimeException();
}
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> v = m1.get(n).get(k0);
Instance tofind = bool ? interp.prop1.get(prop).first.get(n).first : new Instance(sig0);
Object found = interp.prop2.get(prop).second.get(n).second.get(tofind);
Object r = interp.prop4.get(prop).get(n).get(new Pair<>(found, v));
set.add(new Pair<>(k.first, r));
}
data.add(new Pair<>(n.string, set));
}
Transform ret = new Transform(unitI, propI, data);
PSMGen.shred(pre, ret, state);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
use of catdata.fql.decl.Path in project fql by CategoricalData.
the class PSMChi method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
Instance I = new Instance(sig, PSMGen.gather(a, sig, state));
Instance Jfull = new Instance(fullSig, PSMGen.gather(b, fullSig, state));
Instance J = new Instance(sig, PSMGen.gather(b, sig, state));
Instance Pfull = new Instance(fullSig, PSMGen.gather(prop, fullSig, state));
Instance P = interp.prop2.get(prop).first;
Transform t = new Transform(I, J, PSMGen.gather(f, sig, state));
List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
for (Node c : sig.nodes) {
List<Pair<Object, Object>> l = new LinkedList<>();
Instance Hc = interp.prop1.get(prop).first.get(c).first;
for (Pair<Object, Object> x : J.data.get(c.string)) {
List<Pair<String, List<Pair<Object, Object>>>> z = new LinkedList<>();
for (Node d : sig.nodes) {
List<Pair<Object, Object>> y = new LinkedList<>();
for (Pair<Object, Object> ff : Hc.data.get(d.string)) {
// c->d
Path f = interp.prop1.get(prop).first.get(c).second.get(ff.first);
Object xd = lookup(J.evaluate(f), x.first);
y.add(new Pair<>(ff.first, xd));
}
z.add(new Pair<>(d.string, y));
}
Transform xx = new Transform(Hc, J, z);
Map<String, Set<Pair<Object, Object>>> q = new HashMap<>();
for (Node d : sig.nodes) {
Set<Pair<Object, Object>> g = new HashSet<>();
for (Pair<Object, Object> y : Hc.data.get(d.string)) {
if (proj2(t.data.get(d.string)).contains(lookup(xx.data.get(d.string), y.first))) {
g.add(y);
}
}
q.put(d.string, g);
}
for (Edge e : sig.edges) {
Set<Pair<Object, Object>> set = new HashSet<>();
for (Pair<Object, Object> j : Hc.data.get(e.name)) {
if (proj1(q.get(e.source.string)).contains(j.first) && proj2(q.get(e.target.string)).contains(j.second)) {
set.add(j);
}
}
q.put(e.name, set);
}
// also do edges
Instance pb = new Instance(sig, q);
Object fnl = interp.prop2.get(prop).second.get(c).second.get(pb);
l.add(new Pair<>(x.first, fnl));
}
data.add(new Pair<>(c.string, l));
}
Transform ret = new Transform(J, P, data);
List<Pair<String, List<Pair<Object, Object>>>> dataFull = new LinkedList<>();
for (Node n : sig.nodes) {
List<Pair<Object, Object>> set = new LinkedList<>();
for (Pair<Object, Object> k : ret.data.get(n.string)) {
Object lhs = k.second;
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> rhs = Jfull.flag(n, k.first);
Object xxx = interp.prop4.get(prop).get(n).get(new Pair<>(lhs, rhs));
set.add(new Pair<>(k.first, xxx));
}
dataFull.add(new Pair<>(n.string, set));
}
Transform ret0 = new Transform(Jfull, Pfull, dataFull);
PSMGen.shred(pre, ret0, state);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getLocalizedMessage());
}
}
use of catdata.fql.decl.Path in project fql by CategoricalData.
the class PSMCurry method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
Instance IJ = new Instance(sig, PSMGen.gather(trans_src, sig, state));
Instance K = new Instance(sig, PSMGen.gather(trans_dst, sig, state));
Transform t = new Transform(IJ, K, PSMGen.gather(trans, sig, state));
Instance I = new Instance(sig, PSMGen.gather(inst_src, sig, state));
Instance J = new Instance(sig, PSMGen.gather(exp, sig, state));
Instance JK = new Instance(sig, PSMGen.gather(inst_dst, sig, state));
Transform trans_src0_fst = new Transform(IJ, I, PSMGen.gather(trans_src + "_fst", sig, state));
Transform trans_src0_snd = new Transform(IJ, J, PSMGen.gather(trans_src + "_snd", sig, state));
Map<Node, List<Pair<Arr<Node, Path>, Attribute<Node>>>> obs = I.thesig.obs();
List<Pair<String, List<Pair<Object, Object>>>> l = new LinkedList<>();
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>>> kkk = interp.exps2.get(inst_dst);
for (Node c : sig.nodes) {
List<Pair<Object, Object>> s = new LinkedList<>();
for (Pair<Object, Object> xx : I.data.get(c.string)) {
Object x = xx.first;
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> w = I.flag(c, x);
Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>> HcJ = kkk.second.get(new Pair<>(c, w));
// construct transform depending on x, lookup in kkk.second
List<Pair<String, List<Pair<Object, Object>>>> tx = new LinkedList<>();
for (Node d : sig.nodes) {
List<Pair<Object, Object>> tx0 = new LinkedList<>();
for (Arr<Node, Path> f : sig.toCategory2().first.hom(c, d)) {
for (Pair<Object, Object> y : J.data.get(d.string)) {
// only if y(p.a) = w(p.a)
if (!PropPSM.truncate2(I.thesig, w, f, obs.get(d)).equals(J.flag(d, y.first))) {
continue;
}
Object Ifx = lookup(I.evaluate(f.arr), x);
// Object Ifx = lookup(HcJ.first.evaluate(f.arr), x);
Object u = find(d, trans_src0_fst, trans_src0_snd, Ifx, y.first);
Object v = lookup(t.data.get(d.string), u);
Object iii = HcJ.third.get(d).get(new Pair<>(f, y.first));
tx0.add(new Pair<>(iii, v));
}
}
// I*J -> K
tx.add(new Pair<>(d.string, tx0));
}
Transform xxx = new Transform(HcJ.first, K, tx);
Object yyy = kkk.fourth.get(c).get(new Pair<>(w, xxx));
s.add(new Pair<>(x, yyy));
}
l.add(new Pair<>(c.string, s));
}
Transform zzz = new Transform(I, JK, l);
PSMGen.shred(ret, zzz, state);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
use of catdata.fql.decl.Path in project fql by CategoricalData.
the class LeftKanSigma method deAttr.
private static Mapping deAttr(Mapping f) throws FQLException {
Mapping ret = f.clone();
deAttr(ret.source);
deAttr(ret.target);
for (Attribute<Node> k : ret.am.keySet()) {
Attribute<Node> v = ret.am.get(k);
Node src = new Node(k.name);
Node dst = new Node(v.name);
Edge srcE = new Edge(k.name + "_edge", k.source, src);
Edge dstE = new Edge(v.name + "_edge", v.source, dst);
ret.nm.put(src, dst);
ret.em.put(srcE, new Path(ret.target, dstE));
}
ret.am.clear();
return ret;
}
Aggregations