use of catdata.aql.fdm.LiteralTransform in project fql by CategoricalData.
the class TransExpRaw method eval.
@Override
public synchronized Transform<Ty, En, Sym, Fk, Att, Gen, Sk, Gen, Sk, String, String, String, String> eval(AqlEnv env) {
Instance<Ty, En, Sym, Fk, Att, Gen, Sk, String, String> src0 = src.eval(env);
Instance<Ty, En, Sym, Fk, Att, Gen, Sk, String, String> dst0 = dst.eval(env);
// Collage<String, String, String, String, String, Void, Void> scol = new Collage<>(src0);
Collage<Ty, En, Sym, Fk, Att, Gen, Sk> dcol = new Collage<>(dst0.collage());
Map<Gen, Term<Void, En, Void, Fk, Void, Gen, Void>> gens0 = new HashMap<>();
Map<Sk, Term<Ty, En, Sym, Fk, Att, Gen, Sk>> sks0 = new HashMap<>();
for (String k : imports) {
@SuppressWarnings("unchecked") Transform<Ty, En, Sym, Fk, Att, Gen, Sk, Gen, Sk, String, String, String, String> v = env.defs.trans.get(k);
Util.putAllSafely(gens0, v.gens().map);
Util.putAllSafely(sks0, v.sks().map);
}
for (Pair<String, RawTerm> gen : gens) {
try {
RawTerm term = gen.second;
Map<String, Chc<Ty, En>> ctx = new HashMap<>();
Chc<Ty, En> required;
if (src0.gens().containsKey(new Gen(gen.first)) && src0.sks().containsKey(new Sk(gen.first))) {
throw new RuntimeException(gen.first + " is ambiguous");
} else if (src0.gens().containsKey(new Gen(gen.first))) {
required = Chc.inRight(src0.gens().get(new Gen(gen.first)));
} else if (src0.sks().containsKey(new Sk(gen.first))) {
required = Chc.inLeft(src0.sks().get(new Sk(gen.first)));
} else {
throw new RuntimeException(gen.first + " is not a source generator/labelled null");
}
Term<Ty, En, Sym, Fk, Att, Gen, Sk> term0 = RawTerm.infer1x(ctx, term, null, required, dcol, "", src0.schema().typeSide.js).second;
if (required.left) {
Util.putSafely(sks0, new Sk(gen.first), term0.convert());
} else {
Util.putSafely(gens0, new Gen(gen.first), term0.convert());
}
} catch (RuntimeException ex) {
ex.printStackTrace();
throw new LocException(find("generators", gen), "In transform for " + gen.first + ", " + ex.getMessage());
}
}
AqlOptions ops = new AqlOptions(options, null, env.defaults);
LiteralTransform<Ty, En, Sym, Fk, Att, Gen, Sk, Gen, Sk, String, String, String, String> ret = new LiteralTransform<Ty, En, Sym, Fk, Att, Gen, Sk, Gen, Sk, String, String, String, String>(gens0, sks0, src0, dst0, (Boolean) ops.getOrDefault(AqlOption.dont_validate_unsafe));
return ret;
}
use of catdata.aql.fdm.LiteralTransform in project fql by CategoricalData.
the class Constraints method step.
// TODO aql needs to be over all eds
public <Gen, Sk, X, Y> Instance<Ty, En, Sym, Fk, Att, ?, ?, ?, ?> step(Instance<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> I, AqlOptions options) {
Collection<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>> T = triggers(I, options);
if (T.isEmpty()) {
return null;
}
DMG<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Void> shape = new DMG<>(T, new HashMap<>());
Ctx<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>>> nodesA = new Ctx<>();
Ctx<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>>> nodesE = new Ctx<>();
Map<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Term<Void, En, Void, Fk, Void, Gen, Void>> aaa = new HashMap<>();
Map<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Term<Void, En, Void, Fk, Void, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Void>> xxx = new HashMap<>();
for (Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>> t : T) {
Query<Ty, En, Sym, Fk, Att, WHICH, Unit, Void> Q = t.first.Q;
Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> A = Q.ens.get(WHICH.FRONT);
Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> E = Q.ens.get(WHICH.BACK);
Transform<Ty, En, Sym, Fk, Att, Var, Var, Var, Var, ID, Chc<Var, Pair<ID, Att>>, ID, Chc<Var, Pair<ID, Att>>> AE = Q.fks.get(new Unit());
nodesA.put(t, A);
nodesE.put(t, E);
for (Var v : AE.src().gens().keySet()) {
// revisit after colimit fixed
xxx.put(new Pair<>(t, v), Term.Gen(new Pair<>(t, v)));
aaa.put(new Pair<>(t, v), I.algebra().repr(t.second.get(v)));
}
/*for (Void v : AE.src().sks().keySet()) {
yyy.put(v, Util.abort(v)); // revisit after colimit fixed
bbb.put(v, Util.abort(v));
}*/
}
ColimitInstance<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Void, Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> A0 = new ColimitInstance<>(schema, shape, nodesA, new Ctx<>(), options);
ColimitInstance<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Void, Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> E0 = new ColimitInstance<>(schema, shape, nodesE, new Ctx<>(), options);
LiteralTransform<Ty, En, Sym, Fk, Att, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, ID, Chc<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<ID, Att>>, ID, Chc<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<ID, Att>>> A0E0 = new LiteralTransform<>(xxx, new HashMap<>(), A0, E0, false);
LiteralTransform<Ty, En, Sym, Fk, Att, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Gen, Sk, ID, Chc<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<ID, Att>>, X, Y> A0I = new LiteralTransform<>(aaa, new HashMap<>(), A0, I, false);
return pushout(A0E0, A0I, options);
// TODO aql disable checking for speed
}
use of catdata.aql.fdm.LiteralTransform in project fql by CategoricalData.
the class TransExpImport method eval.
@Override
public Transform<Ty, En, Sym, Fk, Att, Gen1, Sk1, Gen2, Sk2, X1, Y1, X2, Y2> eval(AqlEnv env) {
Instance<Ty, En, Sym, Fk, Att, Gen1, Sk1, X1, Y1> src0 = src.eval(env);
Instance<Ty, En, Sym, Fk, Att, Gen2, Sk2, X2, Y2> dst0 = dst.eval(env);
if (!src0.schema().equals(dst0.schema())) {
throw new RuntimeException("Schema of instance source is " + src0 + " but schema of target instance is " + dst0);
}
Schema<Ty, En, Sym, Fk, Att> sch = src0.schema();
for (String o : map.keySet()) {
if (!sch.ens.contains(new En(o))) {
throw new RuntimeException("there is an import for " + o + ", which is not an entity in the schema ");
}
}
gens = new Ctx<>();
sks = new Ctx<>();
op = new AqlOptions(options, null, env.defaults);
dontValidateEqs = (Boolean) op.getOrDefault(AqlOption.dont_validate_unsafe);
boolean autoMapNulls = (Boolean) op.getOrDefault(AqlOption.map_nulls_arbitrarily_unsafe);
for (Sk1 sk : src0.sks().keySet()) {
Ty ty = src0.sks().get(sk);
Set<Sk2> xxx = Util.revS(dst0.sks().map).get(ty);
if (xxx.isEmpty()) {
throw new RuntimeException("Cannot map null " + sk + " to target instance because target instance has no nulls at type " + ty);
}
if (xxx.size() > 1) {
if (autoMapNulls) {
Sk2 sk2 = Util.get0X(xxx);
sks.put(sk, Term.Sk(sk2));
} else {
throw new RuntimeException("Cannot automatically map null " + sk + " to target instance because target instance has " + xxx.size() + " nulls at type " + ty + ". Possible solution: add options map_nulls_arbitrarily_unsafe = true");
}
} else {
Sk2 sk2 = Util.get0(xxx);
sks.put(sk, Term.Sk(sk2));
}
}
try {
Handle h = start(sch);
for (En en : sch.ens) {
if (map.containsKey(en.str)) {
processEn(en, sch, h, map.get(en.str));
}
}
stop(h);
} catch (Exception exn) {
// .getMessage() + "\n\n" + getHelpStr());
throw new RuntimeException(exn);
}
return new LiteralTransform<>(gens.map, sks.map, src0, dst0, dontValidateEqs);
}
Aggregations