use of catdata.Triple in project fql by CategoricalData.
the class XParser method program.
public static XProgram program(String s) {
List<Triple<String, Integer, XExp>> ret = new LinkedList<>();
List decls = (List) program.parse(s);
for (Object d : decls) {
org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) d;
Tuple3 decl = (Tuple3) pr.b;
if (decl.a instanceof List) {
List l = (List) decl.a;
for (Object o : l) {
toProgHelper(pr.a.toString(), s, ret, new Tuple3(o, decl.b, decl.c));
}
} else {
toProgHelper(pr.a.toString(), s, ret, decl);
}
}
return new XProgram(ret);
}
use of catdata.Triple in project fql by CategoricalData.
the class XParser method fromBulb.
private static Triple<String, List<List<String>>, List<String>> fromBulb(Object o) {
try {
Tuple3 t = (Tuple3) o;
Tuple3 a = (Tuple3) t.a;
Tuple3 b = (Tuple3) a.c;
return new Triple<>((String) a.b, (List<List<String>>) b.b, (List<String>) t.c);
} catch (Exception ee) {
}
try {
Tuple3 a = (Tuple3) o;
Tuple3 b = (Tuple3) a.c;
return new Triple<>((String) a.b, (List<List<String>>) b.b, null);
} catch (Exception ee) {
}
return new Triple<>(null, null, (List<String>) o);
}
use of catdata.Triple in project fql by CategoricalData.
the class XParser method fromSoed.
/*
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 XSOED fromSoed(Object ooo) {
org.jparsec.functors.Pair ooo1 = (org.jparsec.functors.Pair) ooo;
Tuple4 a = (Tuple4) ooo1.a;
List<Triple<String, String, String>> es = new LinkedList<>();
List<FOED> as = new LinkedList<>();
List<Tuple5> es0 = (List<Tuple5>) a.b;
for (Tuple5 t : es0) {
es.add(new Triple(t.a, t.c, t.e));
}
List<Tuple4> as0 = (List<Tuple4>) a.d;
for (Tuple4 t : as0) {
List<Tuple3> eqs = (List<Tuple3>) t.d;
List<Pair<List<String>, List<String>>> eqs0 = new LinkedList<>();
for (Tuple3 x : eqs) {
eqs0.add(new Pair(x.a, x.c));
}
as.add(new FOED((String) t.b, (String) t.c, eqs0));
}
Tuple4 b = (Tuple4) ooo1.b;
String src = (String) b.b;
String dst = (String) b.c;
String i = (String) b.d;
XSOED ret = new XSOED(es, as, src, dst, i);
return ret;
}
use of catdata.Triple in project fql by CategoricalData.
the class XProd method snd.
public static <X> XMapping snd(XCtx<X> I, XCtx<X> J) {
XCtx<Pair<Triple<X, X, List<X>>, Triple<X, X, List<X>>>> IJ = prod(I, J);
Map em = new HashMap<>();
for (Pair<Triple<X, X, List<X>>, Triple<X, X, List<X>>> x : IJ.types.keySet()) {
List l = new LinkedList<>();
l.add(x.second.first);
l.addAll(x.second.third);
em.put(x, l);
}
for (Object x : IJ.allTerms()) {
if (em.containsKey(x)) {
continue;
}
List l = new LinkedList<>();
l.add(x);
em.put(x, l);
}
return new XMapping<>(IJ, J, em, "homomorphism");
}
use of catdata.Triple in project fql by CategoricalData.
the class XProd method pair.
public static <A> XMapping<A, ?> pair(XMapping<A, A> l, XMapping<A, A> r) {
if (!l.src.equals(r.src)) {
throw new RuntimeException();
}
XCtx<Pair<Triple<A, A, List<A>>, Triple<A, A, List<A>>>> dst = prod(l.dst, r.dst);
Map em = new HashMap<>();
for (A x : l.src.terms()) {
List<A> x1 = l.em.get(x);
Triple t1 = l.dst.find_fast(new Triple<>((A) "_1", l.dst.type(x1).second, x1));
List<A> x2 = r.em.get(x);
Triple t2 = r.dst.find_fast(new Triple<>((A) "_1", r.dst.type(x2).second, x2));
List xl = new LinkedList();
xl.add(new Pair<>(t1, t2));
em.put(x, xl);
}
for (Object x : l.src.allTerms()) {
if (em.containsKey(x)) {
continue;
}
List z = new LinkedList<>();
z.add(x);
em.put(x, z);
}
return new XMapping(l.src, dst, em, "homomorphism");
}
Aggregations