use of catdata.fpql.XExp.XSuperED.SuperFOED in project fql by CategoricalData.
the class XParser method fromSuperSoed.
/*
J = soed {
exists f:A->B, g:C->D;
forall a:A, a.f = p.q, a.g = p.f;
forall b:B, p = q;
} : X -> Y on I
*/
private static XSuperED fromSuperSoed(Object ooo) {
org.jparsec.functors.Pair ooo1 = (org.jparsec.functors.Pair) ooo;
Tuple4 a = (Tuple4) ooo1.a;
// List<Triple<String, List<String>, String>> es = new LinkedList<>();
List<SuperFOED> as = new LinkedList<>();
Map<String, List<String>> dom = new HashMap<>();
Map<String, String> cod = new HashMap<>();
List<Tuple5> es0 = (List<Tuple5>) a.b;
for (Tuple5 t : es0) {
if (dom.keySet().contains(t.a)) {
throw new RuntimeException("Duplicate function name " + t.a);
}
dom.put((String) t.a, (List<String>) t.c);
cod.put((String) t.a, (String) t.e);
}
List<Tuple4> as0 = (List<Tuple4>) a.d;
for (Tuple4 t : as0) {
List<Tuple3> aas = (List<Tuple3>) t.b;
Map<String, String> aa = new HashMap<>();
for (Tuple3 xxx : aas) {
if (aa.containsKey(xxx.a)) {
throw new RuntimeException("Duplicate var " + xxx.a);
}
aa.put((String) xxx.a, (String) xxx.c);
}
Tuple3 td = (Tuple3) t.d;
List<Tuple3> lhss = (List<Tuple3>) td.a;
List<Tuple3> rhss = (List<Tuple3>) td.c;
List<Pair<Triple<String, List<List<String>>, List<String>>, Triple<String, List<List<String>>, List<String>>>> cc = new LinkedList<>();
List<Pair<Triple<String, List<List<String>>, List<String>>, Triple<String, List<List<String>>, List<String>>>> bb = new LinkedList<>();
for (Tuple3 o : lhss) {
bb.add(new Pair<>(fromBulb(o.a), fromBulb(o.c)));
}
for (Tuple3 o : rhss) {
cc.add(new Pair<>(fromBulb(o.a), fromBulb(o.c)));
}
as.add(new SuperFOED(aa, bb, cc));
}
Tuple4 b = (Tuple4) ooo1.b;
String src = (String) b.b;
String dst = (String) b.c;
String i = (String) b.d;
// es, as, src, dst, i);
XSuperED ret = new XSuperED(dom, cod, as, src, dst, i);
return ret;
}
use of catdata.fpql.XExp.XSuperED.SuperFOED in project fql by CategoricalData.
the class XChaser method step.
@SuppressWarnings("unused")
private static <C> Triple<Map<String, Set<List<Triple<C, C, List<C>>>>>, Map<Pair<String, List<Triple<C, C, List<C>>>>, Object>, Set> step(XSuperED ED, XCtx<C> S, XCtx T, XCtx<C> I, Map<String, Set<List<Triple<C, C, List<C>>>>> dom, Map<Pair<String, List<Triple<C, C, List<C>>>>, Object> gens, Set eqs) {
for (SuperFOED ed : ED.as) {
List<LinkedHashMap<C, Triple<C, C, List<C>>>> vals = allVals((Map<C, C>) ed.a, I);
for (LinkedHashMap<C, Triple<C, C, List<C>>> val : vals) {
// lhs_substed = substLhs(ed.lhs, val);
for (Pair<Triple<String, List<List<String>>, List<String>>, Triple<String, List<List<String>>, List<String>>> rhs : ed.rhs) {
Pair<Triple<String, List<List<String>>, List<String>>, Triple<String, List<List<String>>, List<String>>> rhs_substed = new Pair<>(substLhs0(rhs.first, val), substLhs0(rhs.second, val));
if (triggers(ed.lhs, rhs, val, I, gens, dom)) {
if (rhs.first.first != null) {
Set<List<Triple<C, C, List<C>>>> set = dom.get(rhs.first.first);
List<List<C>> toadd = (List<List<C>>) ((Object) rhs_substed.first.second);
List<Triple<C, C, List<C>>> toadd2 = toadd.stream().map(x -> new Triple<>(I.type(x).first, I.type(x).second, x)).collect(Collectors.toList());
// to trigger, the rhs wasn't already there
set.add(toadd2);
gens.put(new Pair<>(rhs.first.first, toadd2), new Pair<>(rhs.first.first, toadd2));
}
if (rhs.second.first != null) {
Set<List<Triple<C, C, List<C>>>> set = dom.get(rhs.second.first);
List<List<C>> toadd = (List<List<C>>) ((Object) rhs_substed.second.second);
List<Triple<C, C, List<C>>> toadd2 = toadd.stream().map(x -> new Triple<>(I.type(x).first, I.type(x).second, x)).collect(Collectors.toList());
// to trigger, the rhs wasn't already there
set.add(toadd2);
gens.put(new Pair<>(rhs.second.first, toadd2), new Pair<>(rhs.second.first, toadd2));
}
eqs.add(new Pair(massage(rhs_substed.first, I), massage(rhs_substed.second, I)));
// if (rhs.first.first != null && rhs.second.first != null) {
// }
// : equate in gens map
} else {
}
}
}
}
return new Triple<>(dom, gens, eqs);
}
use of catdata.fpql.XExp.XSuperED.SuperFOED in project fql by CategoricalData.
the class XChaser method validate.
public static void validate(XSuperED phi, XCtx<String> S, XCtx<String> T) {
if (!phi.cod.keySet().equals(phi.dom.keySet())) {
throw new RuntimeException("function symbols cod/dom not equal");
}
for (String f : phi.cod.keySet()) {
List<String> ss = phi.dom.get(f);
String t = phi.cod.get(f);
for (String s : ss) {
if (!S.ids.contains(s)) {
throw new RuntimeException("Not a source entity: " + s);
}
}
if (!T.allIds().contains(t) && !t.equals("DOM")) {
throw new RuntimeException("Not a target entity: " + t);
}
}
for (SuperFOED psi : phi.as) {
for (String v : psi.a.keySet()) {
String ty = psi.a.get(v);
if (!S.ids.contains(ty)) {
throw new RuntimeException("Not a source entity: " + ty);
}
}
for (Pair<Triple<String, List<List<String>>, List<String>>, Triple<String, List<List<String>>, List<String>>> eq : psi.lhs) {
Pair<String, String> lt = check(phi, psi, eq.first, S, T);
Pair<String, String> rt = check(phi, psi, eq.second, S, T);
if (!lt.equals(rt)) {
throw new RuntimeException("Not equal types: " + lt + " and " + rt);
}
if (!lt.first.equals("_1")) {
throw new RuntimeException("Does not start at 1: " + eq.first);
}
noEdgesFrom(T.terms(), eq.first);
noEdgesFrom(T.terms(), eq.second);
}
for (Pair<Triple<String, List<List<String>>, List<String>>, Triple<String, List<List<String>>, List<String>>> eq : psi.rhs) {
Pair<String, String> lt = check(phi, psi, eq.first, S, T);
Pair<String, String> rt = check(phi, psi, eq.second, S, T);
if (!lt.equals(rt)) {
throw new RuntimeException("Not equal types: " + lt + " and " + rt);
}
if (!lt.first.equals("_1")) {
throw new RuntimeException("Does not start at 1: " + eq.first);
}
if (S.ids.contains(lt.second)) {
throw new RuntimeException("RHS of -> contains an equality of source entity " + lt);
}
}
}
}
Aggregations