use of catdata.fpql.XExp.XPair in project fql by CategoricalData.
the class XParser method toExp.
private static XExp toExp(Object c) {
if (c instanceof String) {
return new Var((String) c);
}
try {
return fromPoly((Tuple4) c);
} catch (Exception e) {
}
try {
return fromSoed(c);
} catch (Exception e) {
}
try {
return toCatConst(c);
} catch (Exception e) {
}
try {
if (c.toString().contains("variables")) {
return toInstConst(c);
}
} catch (Exception e) {
}
try {
return toMapping(c);
} catch (Exception e) {
}
try {
return toTrans(c);
} catch (Exception e) {
}
if (c instanceof Tuple5) {
Tuple5 p = (Tuple5) c;
if (p.c.toString().equals("+")) {
return new XCoprod(toExp(p.b), toExp(p.d));
}
if (p.c.toString().equals("*")) {
return new XTimes(toExp(p.b), toExp(p.d));
}
if (p.c.toString().equals(";")) {
return new Compose(toExp(p.b), toExp(p.d));
}
if (p.a.toString().equals("return") && p.b.toString().equals("sigma")) {
return new XUnit("sigma", toExp(p.d), toExp(p.e));
}
if (p.a.toString().equals("coreturn") && p.b.toString().equals("sigma")) {
return new XCounit("sigma", toExp(p.d), toExp(p.e));
}
if (p.a.toString().equals("return") && p.b.toString().equals("delta")) {
return new XUnit("pi", toExp(p.d), toExp(p.e));
}
if (p.a.toString().equals("coreturn") && p.b.toString().equals("delta")) {
return new XCounit("pi", toExp(p.d), toExp(p.e));
}
return new XFn((String) p.b, (String) p.d, (String) p.e);
}
if (c instanceof Tuple4) {
Tuple4 p = (Tuple4) c;
return new XEq((List<String>) p.b, (List<String>) p.d);
}
if (c instanceof Tuple3) {
Tuple3 p = (Tuple3) c;
if (p.a.toString().equals("flower")) {
XExp I = toExp(p.c);
Tuple3 q = (Tuple3) p.b;
// list of tuple3 of (path, string)
List s = (List) ((org.jparsec.functors.Pair) q.a).b;
// list of tuple3 of (string, string)
List f = (List) ((org.jparsec.functors.Pair) q.b).b;
// list of tuple3 of (path, path)
List w = (List) ((org.jparsec.functors.Pair) q.c).b;
Map<Object, List<Object>> select = new HashMap<>();
Map<Object, Object> from = new HashMap<>();
List<Pair<List<Object>, List<Object>>> where = new LinkedList<>();
Set<String> seen = new HashSet<>();
for (Object o : w) {
Tuple3 t = (Tuple3) o;
List lhs = (List) t.a;
List rhs = (List) t.c;
where.add(new Pair<>(rhs, lhs));
}
for (Object o : s) {
Tuple3 t = (Tuple3) o;
List lhs = (List) t.a;
String rhs = t.c.toString();
if (seen.contains(rhs)) {
throw new RuntimeException("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
}
seen.add(rhs);
select.put(rhs, lhs);
}
for (Object o : f) {
Tuple3 t = (Tuple3) o;
String lhs = t.a.toString();
String rhs = t.c.toString();
if (seen.contains(rhs)) {
throw new RuntimeException("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
}
seen.add(rhs);
from.put(rhs, lhs);
}
return new Flower(select, from, where, I);
}
if (p.a.toString().equals("FLOWER")) {
XExp I = toExp(p.c);
Tuple3 q = (Tuple3) p.b;
// list of tuple3 of (path, string)
List s = (List) ((org.jparsec.functors.Pair) q.a).b;
// list of tuple3 of (string, string)
List f = (List) ((org.jparsec.functors.Pair) q.b).b;
// list of tuple3 of (path, path)
Object w = ((org.jparsec.functors.Pair) q.c).b;
Map<Object, List<Object>> select = new HashMap<>();
Map<Object, Object> from = new HashMap<>();
// List<Pair<List<String>, List<String>>> where = new LinkedList<>();
Set<String> seen = new HashSet<>();
for (Object o : s) {
Tuple3 t = (Tuple3) o;
List lhs = (List) t.a;
String rhs = t.c.toString();
if (seen.contains(rhs)) {
throw new RuntimeException("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
}
seen.add(rhs);
select.put(rhs, lhs);
}
for (Object o : f) {
Tuple3 t = (Tuple3) o;
String lhs = t.a.toString();
String rhs = t.c.toString();
if (seen.contains(rhs)) {
throw new RuntimeException("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
}
seen.add(rhs);
from.put(rhs, lhs);
}
return new FLOWER2(select, from, toWhere(w), I);
}
if (p.a.toString().equals("pushout")) {
return new XPushout(toExp(p.b), toExp(p.c));
}
if (p.a.toString().equals("hom")) {
return new XToQuery(toExp(p.b), toExp(p.c));
}
if (p.a.toString().equals("sigma")) {
return new XSigma(toExp(p.b), toExp(p.c));
}
if (p.a.toString().equals("delta")) {
return new XDelta(toExp(p.b), toExp(p.c));
}
if (p.a.toString().equals("pi")) {
return new XPi(toExp(p.b), toExp(p.c));
}
if (p.a.toString().equals("inl")) {
return new XInj(toExp(p.b), toExp(p.c), true);
}
if (p.a.toString().equals("inr")) {
return new XInj(toExp(p.b), toExp(p.c), false);
}
if (p.a.toString().equals("case")) {
return new XMatch(toExp(p.b), toExp(p.c));
}
if (p.a.toString().equals("fst")) {
return new XProj(toExp(p.b), toExp(p.c), true);
}
if (p.a.toString().equals("snd")) {
return new XProj(toExp(p.b), toExp(p.c), false);
}
if (p.a.toString().equals("pair")) {
return new XPair(toExp(p.b), toExp(p.c));
}
if (p.a.toString().equals("apply")) {
return new Apply(toExp(p.b), toExp(p.c));
}
if (p.a.toString().equals("coapply")) {
return new XCoApply(toExp(p.b), toExp(p.c));
}
return new XConst((String) p.b, (String) p.c);
}
if (c instanceof org.jparsec.functors.Pair) {
org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) c;
if (p.a.toString().equals("idpoly")) {
return new XIdPoly(toExp(p.b));
}
if (p.a.toString().equals("uberpi")) {
return new XUberPi(toExp(p.b));
}
if (p.a.toString().equals("labels")) {
return new XLabel(toExp(p.b));
}
if (p.a.toString().equals("grothlabels")) {
return new XGrothLabels(toExp(p.b));
}
if (p.a.toString().equals("relationalize")) {
return new XRel(toExp(p.b));
}
if (p.a.toString().equals("void")) {
return new XVoid(toExp(p.b));
}
if (p.a.toString().equals("ff")) {
return new XFF(toExp(p.b));
}
if (p.a.toString().equals("unit")) {
return new XOne(toExp(p.b));
}
if (p.a.toString().equals("tt")) {
return new XTT(toExp(p.b));
}
if (p.a.toString().equals("id")) {
return new Id(false, toExp(p.b));
}
if (p.a.toString().equals("ID")) {
return new Id(true, toExp(p.b));
} else // if (p.a.toString().equals("query")) {
// Tuple3 t = (Tuple3) p.b;
// return new XExp.XQueryExp(toExp(t.a), toExp(t.b), toExp(t.c));
// }
{
try {
return fromSuperSoed(c);
} catch (Exception e) {
e.printStackTrace();
}
return new XTy((String) p.b);
}
}
throw new RuntimeException("x: " + c.getClass() + " " + c);
}
use of catdata.fpql.XExp.XPair in project fql by CategoricalData.
the class XChecker method visit.
@Override
public Pair<XExp, XExp> visit(Map<String, XExp> env, XPair e) {
Pair<XExp, XExp> l = e.l.accept(env, this);
Pair<XExp, XExp> r = e.r.accept(env, this);
if (!l.first.equals(r.first)) {
throw new RuntimeException("sources of " + e + " not equal: " + l.second + " and " + r.second);
}
return new Pair<>(r.first, new XTimes(l.second, r.second));
}
Aggregations