use of catdata.fql.decl.Instance in project fql by CategoricalData.
the class PSMAnd method union.
private static Instance union(Instance a, Instance b) throws FQLException {
Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
for (Node n : a.thesig.nodes) {
Set<Pair<Object, Object>> set = new HashSet<>();
set.addAll(a.data.get(n.string));
set.addAll(b.data.get(n.string));
data.put(n.string, set);
}
for (Edge n : a.thesig.edges) {
Set<Pair<Object, Object>> set = new HashSet<>();
set.addAll(a.data.get(n.name));
set.addAll(b.data.get(n.name));
data.put(n.name, set);
}
return new Instance(a.thesig, data);
}
use of catdata.fql.decl.Instance in project fql by CategoricalData.
the class PSMEval method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
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>>> xxx = interp.exps2.get(AB);
Instance Jw = xxx.first;
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 = xxx.second;
Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>> map2 = xxx.third;
FinCat<Node, Path> cat = Jw.thesig.toCategory2().first;
Instance abb = new Instance(sig, PSMGen.gather(ABB, sig, state));
// Instance ab = new Instance(sig, PSMGen.gather(AB, sig, state));
// //already have in interp
Instance a = new Instance(sig, PSMGen.gather(A, sig, state));
Instance b = new Instance(sig, PSMGen.gather(B, sig, state));
Transform fst = new Transform(abb, Jw, PSMGen.gather(ABB + "_fst", sig, state));
Transform snd = new Transform(abb, b, PSMGen.gather(ABB + "_snd", sig, state));
List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
for (Node n : sig.nodes) {
List<Pair<Object, Object>> d = new LinkedList<>();
Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>> m2 = map2.get(n);
for (Pair<Object, Object> id : abb.data.get(n.string)) {
Object id_ab = lookup(fst.data.get(n.string), id.first);
Object x = lookup(snd.data.get(n.string), id.first);
Transform t = m2.get(id_ab).second;
LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> w = m2.get(id_ab).first;
Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>> m = map.get(new Pair<>(n, w));
Object y = m.third.get(n).get(new Pair<>(cat.id(n), x));
Object f = lookup(t.data.get(n.string), y);
d.add(new Pair<>(id.first, f));
}
data.add(new Pair<>(n.string, d));
}
Transform curry = new Transform(abb, a, data);
PSMGen.shred(pre, curry, state);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
use of catdata.fql.decl.Instance in project fql by CategoricalData.
the class TransChecker method visit.
@SuppressWarnings("unused")
@Override
public Pair<String, String> visit(FQLProgram env, Const e) {
InstExp src = env.insts.get(e.src);
if (src == null) {
throw new RuntimeException("Missing instance " + e.src);
}
InstExp dst = env.insts.get(e.dst);
if (dst == null) {
throw new RuntimeException("Missing instance " + e.src);
}
if (!(src instanceof InstExp.Const)) {
throw new RuntimeException(e.src + " is not a constant.");
}
if (!(dst instanceof InstExp.Const)) {
throw new RuntimeException(e.dst + " is not a constant.");
}
InstExp.Const src0 = (InstExp.Const) src;
InstExp.Const dst0 = (InstExp.Const) dst;
SigExp srct = src0.type(env);
SigExp dstt = dst0.type(env);
if (!srct.equals(dstt)) {
throw new RuntimeException("Instances not of same type on " + e + " are " + srct + " and " + dstt);
}
Signature sig = srct.toSig(env);
List<Pair<String, List<Pair<Object, Object>>>> bbb = e.objs;
try {
new Transform(new Instance(sig, src0.data), new Instance(sig, dst0.data), bbb);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getLocalizedMessage());
}
return new Pair<>(e.src, e.dst);
}
use of catdata.fql.decl.Instance in project fql by CategoricalData.
the class LeftKanSigma method reAttr.
private static Instance reAttr(Map<Node, Map<Object, Integer>> D, Signature thesig, Instance i, Map<Attribute<Node>, Map<Object, Object>> map0) throws FQLException {
Map<String, Set<Pair<Object, Object>>> d = new HashMap<>();
for (Node k : i.thesig.nodes) {
d.put(k.string, i.data.get(k.string));
}
for (Edge k : thesig.edges) {
d.put(k.name, i.data.get(k.name));
}
Map<Object, Object> map = new HashMap<>();
for (Attribute<Node> k : map0.keySet()) {
Map<Object, Object> v = map0.get(k);
for (Object k0 : v.keySet()) {
Object v0 = v.get(k0);
if (map.containsKey(k0)) {
throw new RuntimeException();
}
map.put(k0, v0);
}
}
for (Attribute<Node> k : thesig.attrs) {
Set<Pair<Object, Object>> t = new HashSet<>();
for (Pair<Object, Object> v : i.data.get(k.name + "_edge")) {
Object v1 = getFrom(k, D, map, /* ().get(k) */
v.second.toString());
t.add(new Pair<>(v.first, v1));
}
d.put(k.name, t);
}
return new Instance(thesig, d);
}
use of catdata.fql.decl.Instance in project fql by CategoricalData.
the class LeftKanSigma method deAttr.
private static Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> deAttr(PSMInterp inter, Instance i, Signature sig) throws FQLException {
Map<String, Set<Pair<Object, Object>>> d = new HashMap<>();
Map<Attribute<Node>, Map<Object, Object>> ret = new HashMap<>();
for (Node k : i.thesig.nodes) {
d.put(k.string, i.data.get(k.string));
}
for (Edge k : i.thesig.edges) {
d.put(k.name, i.data.get(k.name));
}
for (Attribute<Node> k : i.thesig.attrs) {
Map<Object, Object> ret0 = new HashMap<>();
Set<Pair<Object, Object>> tn = new HashSet<>();
Set<Pair<Object, Object>> te = new HashSet<>();
for (Pair<Object, Object> v : i.data.get(k.name)) {
Object x = revLookup(ret0, v.second);
if (x == null) {
x = ++inter.guid;
ret0.put(x.toString(), v.second);
}
tn.add(new Pair<>(x.toString(), x.toString()));
te.add(new Pair<>(v.first, x.toString()));
}
ret.put(k, ret0);
d.put(k.name, tn);
d.put(k.name + "_edge", te);
}
return new Pair<>(new Instance(sig, d), ret);
}
Aggregations