use of catdata.fql.FQLException 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.FQLException in project fql by CategoricalData.
the class ExpPSM method exec.
@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
try {
Instance Ix = new Instance(sig, PSMGen.gather(I, sig, state));
Instance Jx = new Instance(sig, PSMGen.gather(J, sig, state));
IntRef idx = new IntRef(interp.guid);
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>>> ret = Instance.exp2(idx, Ix, Jx);
interp.guid = idx.i;
interp.exps2.put(pre, ret);
PSMGen.shred(pre, ret.first, state);
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getLocalizedMessage());
}
}
use of catdata.fql.FQLException 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.FQLException 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.FQLException in project fql by CategoricalData.
the class CategoryOfElements method makePanel.
public static Pair<JPanel, JPanel> makePanel(String name, Instance i, Color c) {
try {
JPanel ret;
JPanel ret2;
Pair<Graph<Pair<Node, Object>, Pair<Path, Integer>>, HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>>> g = build(i);
ret = g.first.getVertexCount() == 0 ? new JPanel() : doView(c, i, g.first, g.second);
ret2 = dot(name, i, g.first, g.second);
return new Pair<>(ret, ret2);
} catch (FQLException e) {
JPanel p = new JPanel(new GridLayout(1, 1));
JTextArea a = new JTextArea(e.getMessage());
p.add(new JScrollPane(a));
return new Pair<>(p, p);
}
}
Aggregations