use of catdata.fql.sql.PSM in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String env, UnChi e) {
List<PSM> ret = new LinkedList<>();
Signature sig = prog.insts.get(e.a).type(prog).toSig(prog);
for (Node n : sig.nodes) {
ret.add(new InsertSQL(env + "_" + n.string, new CopyFlower(e.a + "_trans_" + n, "c0", "c1"), "c0", "c1"));
}
return ret;
}
use of catdata.fql.sql.PSM in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String dst, TT e) {
try {
List<PSM> ret = new LinkedList<>();
Signature s = prog.insts.get(e.obj).type(prog).toSig(prog);
String temp1 = next();
ret.addAll(PSMGen.makeTables(temp1, s, false));
String temp2 = next();
ret.addAll(PSMGen.makeTables(temp2, s, false));
Pair<Map<Node, List<Pair<Path, Attribute<Node>>>>, List<PSM>> xxx = Relationalizer.observations(s, temp1, e.tgt, false);
Pair<Map<Node, List<Pair<Path, Attribute<Node>>>>, List<PSM>> yyy = Relationalizer.observations(s, temp2, e.obj, false);
if (!xxx.first.equals(yyy.first)) {
throw new RuntimeException("not equal: " + xxx + " and " + yyy);
}
ret.addAll(xxx.second);
ret.addAll(yyy.second);
for (Node n : s.nodes) {
List<?> cols = xxx.first.get(n);
Map<String, String> from = new HashMap<>();
from.put("t1", e.tgt + "_" + n);
from.put("t1_obs", temp1 + "_" + n + "_" + "observables");
from.put("t2", e.obj + "_" + n);
from.put("t2_obs", temp2 + "_" + n + "_" + "observables");
List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
where.add(new Pair<>(new Pair<>("t1", "c0"), new Pair<>("t1_obs", "id")));
where.add(new Pair<>(new Pair<>("t2", "c0"), new Pair<>("t2_obs", "id")));
for (int i = 0; i < cols.size(); i++) {
where.add(new Pair<>(new Pair<>("t1_obs", "c" + i), new Pair<>("t2_obs", "c" + i)));
}
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
select.put("c0", new Pair<>("t1", "c0"));
select.put("c1", new Pair<>("t2", "c0"));
Flower f = new Flower(select, from, where);
ret.add(new InsertSQL(dst + "_" + n, f, "c0", "c1"));
}
ret.addAll(PSMGen.dropTables(temp1, s));
ret.addAll(PSMGen.dropTables(temp2, s));
return ret;
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getLocalizedMessage());
}
}
use of catdata.fql.sql.PSM in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String dst, TransExp.Const e) {
List<PSM> ret = new LinkedList<>();
Signature s = prog.insts.get(e.src).type(prog).toConst(prog).toSig(prog);
List<String> attrs = new LinkedList<>();
attrs.add("c0");
attrs.add("c1");
ret.addAll(PSMGen.makeTables("pre_" + dst, s, false));
for (Node k : s.nodes) {
Set<Map<Object, Object>> values = convert(lookup(k.string, e.objs));
if (!values.isEmpty()) {
ret.add(new InsertValues("pre_" + dst + "_" + k.string, attrs, values));
}
SQL f = PSMGen.compose(e.src + "_" + k.string + "_subst_inv", "pre_" + dst + "_" + k.string, e.dst + "_" + k.string + "_subst");
ret.add(new InsertSQL(dst + "_" + k.string, f, "c0", "c1"));
}
ret.addAll(PSMGen.dropTables("pre_" + dst, s));
return ret;
}
use of catdata.fql.sql.PSM in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String env, Chi e) {
List<PSM> ret = new LinkedList<>();
Signature sig = prog.insts.get(e.prop).type(prog).toSig(prog);
TransExp t = prog.transforms.get(e.trans);
Pair<String, String> k = t.type(prog);
ret.add(new PSMChi(sig, env, k.first, k.second, e.prop, e.trans));
return ret;
}
use of catdata.fql.sql.PSM in project fql by CategoricalData.
the class InstOps method visit.
@Override
public Pair<List<PSM>, Object> visit(String dst, Two e) {
List<PSM> ret = new LinkedList<>();
ret.add(new PropPSM(dst, e.sig.toSig(prog)));
return new Pair<>(ret, new Object());
}
Aggregations