use of catdata.fql.decl.InstExp in project fql by CategoricalData.
the class TransChecker method visit.
@Override
public Pair<String, String> visit(FQLProgram env, Prod e) {
InstExp x = env.insts.get(e.obj);
if (x == null) {
throw new RuntimeException("Missing " + e.obj + " in " + e);
}
if (!(x instanceof Times)) {
throw new RuntimeException(e.obj + " is not a times: " + x);
}
// InstExp.Times y = (InstExp.Times) x;
Pair<String, String> a = e.l.accept(env, this);
Pair<String, String> b = e.r.accept(env, this);
if (!a.first.equals(b.first)) {
throw new RuntimeException("Domain mismatch: " + e + " with " + a.first + " and " + b.first);
}
return new Pair<>(a.first, e.obj);
}
use of catdata.fql.decl.InstExp in project fql by CategoricalData.
the class TransChecker method visit.
@Override
public Pair<String, String> visit(FQLProgram env, TransCurry e) {
InstExp inst = env.insts.get(e.inst);
if (inst == null) {
throw new RuntimeException("Missing instance: " + e.inst);
}
if (!(inst instanceof Exp)) {
throw new RuntimeException("Instance is not an exponential");
}
Exp i = (Exp) inst;
if (seen.contains(e.trans)) {
throw new RuntimeException("Circular transform " + e);
}
seen.add(e.trans);
Pair<String, String> k = env.transforms.get(e.trans).accept(env, this);
InstExp ab = env.insts.get(k.first);
if (!(ab instanceof Times)) {
throw new RuntimeException("Source is not a product");
}
Times t = (Times) ab;
if (!i.a.equals(k.second)) {
throw new RuntimeException("Bases do not match");
}
if (!i.b.equals(t.b)) {
throw new RuntimeException("Exponents do not match");
}
return new Pair<>(t.a, e.inst);
}
use of catdata.fql.decl.InstExp in project fql by CategoricalData.
the class TransChecker method visit.
@Override
public Pair<String, String> visit(FQLProgram env, Squash e) {
InstExp s = env.insts.get(e.src);
if (!(s instanceof InstExp.Relationalize)) {
throw new RuntimeException("Not a relationalize: " + e);
}
InstExp.Relationalize xxx = (InstExp.Relationalize) s;
return new Pair<>(xxx.I, e.src);
}
use of catdata.fql.decl.InstExp in project fql by CategoricalData.
the class TransChecker method visit.
@Override
public Pair<String, String> visit(FQLProgram env, Snd e) {
InstExp x = env.insts.get(e.obj);
if (x == null) {
throw new RuntimeException("Missing " + e.obj + " in " + e);
}
if (!(x instanceof Times)) {
throw new RuntimeException(e.obj + " is not a times: " + x);
}
Times y = (Times) x;
return new Pair<>(e.obj, y.b);
}
use of catdata.fql.decl.InstExp in project fql by CategoricalData.
the class FQLParser method toInstConst.
@SuppressWarnings("rawtypes")
private static InstExp toInstConst(Object decl) {
Tuple3 y = (Tuple3) decl;
Tuple3 x = (Tuple3) y.a;
// List<Pair<String, List<Pair<Object, Object>>>> data = new
// LinkedList<>();
Tuple3 nodes = (Tuple3) x.a;
Tuple3 arrows = (Tuple3) x.c;
Tuple3 attrs = (Tuple3) x.b;
List nodes0 = (List) nodes.b;
List arrows0 = (List) arrows.b;
// List<Object> seen = new LinkedList<>();
List<Pair<String, List<Pair<Object, Object>>>> nodesX = new LinkedList<>();
for (Object o : nodes0) {
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
List m = (List) u.c;
List<Pair<Object, Object>> l = new LinkedList<>();
for (Object h : m) {
l.add(new Pair<>(h, h));
}
// if (seen.contains(n)) {
// throw new RuntimeException("duplicate field: " + o);
// }
// seen.add(n);
nodesX.add(new Pair<>(n, l));
}
// RuntimeException toThrow = null;
List<Pair<String, List<Pair<Object, Object>>>> attrsX = new LinkedList<>();
if (attrs.b.toString().equals("ASWRITTEN")) {
for (Pair<String, List<Pair<Object, Object>>> k : nodesX) {
attrsX.add(new Pair<>(k.first + "_att", k.second));
}
} else {
List attrs0 = (List) attrs.b;
for (Object o : attrs0) {
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
List m = (List) u.c;
List<Pair<Object, Object>> l = new LinkedList<>();
for (Object h : m) {
Tuple3 k = (Tuple3) h;
l.add(new Pair<>(k.a, k.c));
}
// if (seen.contains(n)) {
// toThrow = new RuntimeException("duplicate field: " + n );
// throw toThrow;
// }
// seen.add(n);
attrsX.add(new Pair<>(n, l));
}
}
List<Pair<String, List<Pair<Object, Object>>>> arrowsX = new LinkedList<>();
for (Object o : arrows0) {
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
List m = (List) u.c;
List<Pair<Object, Object>> l = new LinkedList<>();
for (Object h : m) {
Tuple3 k = (Tuple3) h;
l.add(new Pair<>(k.a, k.c));
}
// if (seen.contains(n)) {
// throw new RuntimeException("duplicate field: " + o);
// }
// seen.add(n);
arrowsX.add(new Pair<>(n, l));
}
InstExp.Const ret = new InstExp.Const(nodesX, attrsX, arrowsX, toSchema(y.c));
return ret;
}
Aggregations