Search in sources :

Example 11 with PSM

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;
}
Also used : InsertSQL(catdata.fql.sql.InsertSQL) CopyFlower(catdata.fql.sql.CopyFlower) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 12 with PSM

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());
    }
}
Also used : CopyFlower(catdata.fql.sql.CopyFlower) Flower(catdata.fql.sql.Flower) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) InsertSQL(catdata.fql.sql.InsertSQL) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair)

Example 13 with PSM

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;
}
Also used : InsertSQL(catdata.fql.sql.InsertSQL) InsertValues(catdata.fql.sql.InsertValues) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) SQL(catdata.fql.sql.SQL) InsertSQL(catdata.fql.sql.InsertSQL)

Example 14 with PSM

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;
}
Also used : PSMChi(catdata.fql.sql.PSMChi) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList)

Example 15 with PSM

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());
}
Also used : PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) PropPSM(catdata.fql.sql.PropPSM) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Aggregations

ExpPSM (catdata.fql.sql.ExpPSM)37 PSM (catdata.fql.sql.PSM)37 PropPSM (catdata.fql.sql.PropPSM)37 LinkedList (java.util.LinkedList)36 InsertSQL (catdata.fql.sql.InsertSQL)18 CopyFlower (catdata.fql.sql.CopyFlower)14 Pair (catdata.Pair)12 HashMap (java.util.HashMap)12 LinkedHashMap (java.util.LinkedHashMap)12 Flower (catdata.fql.sql.Flower)9 Times (catdata.fql.decl.InstExp.Times)8 Map (java.util.Map)7 FQLException (catdata.fql.FQLException)6 Arr (catdata.fql.cat.Arr)6 Triple (catdata.Triple)5 Delta (catdata.fql.decl.InstExp.Delta)5 PSMAnd (catdata.fql.sql.PSMAnd)5 SimpleCreateTable (catdata.fql.sql.SimpleCreateTable)5 Exp (catdata.fql.decl.InstExp.Exp)4 FullSigma (catdata.fql.decl.InstExp.FullSigma)4