Search in sources :

Example 11 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class FullSigmaCounit method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    Set<Map<Object, Object>> lineage = state.get(i3 + "_lineage");
    for (Node n : F.target.nodes) {
        Set<Map<Object, Object>> i3i = state.get(i3 + "_" + n);
        Set<Map<Object, Object>> m = new HashSet<>();
        for (Map<Object, Object> row : i3i) {
            Object id = row.get("c0").toString();
            for (Map<Object, Object> v : lineage) {
                Object id0 = v.get("c0").toString();
                if (id.equals(id0)) {
                    String node = v.get("c1").toString();
                    String idX = v.get("c2").toString();
                    String[] cols = v.get("c3").toString().split("\\s+");
                    Set<Map<Object, Object>> subst_inv = state.get(i2 + "_" + node + "_subst_inv");
                    for (Map<Object, Object> y : subst_inv) {
                        if (y.get("c0").toString().equals(idX)) {
                            String ret = y.get("c1").toString();
                            for (String col : cols) {
                                if (col.trim().isEmpty()) {
                                    continue;
                                }
                                Set<Map<Object, Object>> u = state.get(i1 + "_" + col);
                                for (Map<Object, Object> e : u) {
                                    if (e.get("c0").toString().equals(ret)) {
                                        ret = e.get("c1").toString();
                                    }
                                }
                            }
                            Map<Object, Object> rowX = new HashMap<>();
                            rowX.put("c0", id);
                            rowX.put("c1", ret);
                            m.add(rowX);
                        }
                    }
                }
            }
        }
        state.put(trans + "_" + n, m);
    }
    for (Attribute<Node> n : F.target.attrs) {
        state.put(trans + "_" + n.name, new HashSet<>());
    }
    for (Edge n : F.target.edges) {
        state.put(trans + "_" + n.name, new HashSet<>());
    }
}
Also used : HashMap(java.util.HashMap) Node(catdata.fql.decl.Node) Map(java.util.Map) HashMap(java.util.HashMap) Edge(catdata.fql.decl.Edge) HashSet(java.util.HashSet)

Example 12 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class FullSigma method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    Signature C = f.source;
    Signature D = f.target;
    List<Pair<String, List<Pair<Object, Object>>>> I0 = PSMGen.gather(inst, C, state);
    try {
        Instance I = new Instance(C, I0);
        interp.sigmas.put(pre, interp.guid);
        Quad<Instance, Map<Node, Map<Object, Integer>>, Map<Node, Map<Integer, Object>>, Map<Object, List<Pair<String, Object>>>> xxx = LeftKanSigma.fullSigmaWithAttrs(interp, f, I, null, null, null);
        interp.sigmas2.put(pre, interp.guid);
        Instance J = xxx.first;
        Map<Node, Map<Object, Integer>> yyy = xxx.second;
        for (Node n : C.nodes) {
            state.put(pre + "_" + n.string + "_e", conv2(yyy.get(n)));
        }
        for (Node n : D.nodes) {
            state.put(pre + "_" + n.string, conv(J.data.get(n.string)));
        }
        for (Edge n : D.edges) {
            state.put(pre + "_" + n.name, conv(J.data.get(n.name)));
        }
        for (Attribute<Node> n : D.attrs) {
            state.put(pre + "_" + n.name, conv(J.data.get(n.name)));
        }
        Set<Map<Object, Object>> l = new HashSet<>();
        for (Object k : xxx.fourth.keySet()) {
            List<Pair<String, Object>> v = xxx.fourth.get(k);
            if (v.isEmpty()) {
                continue;
            }
            Map<Object, Object> m = new HashMap<>();
            m.put("c0", k);
            boolean first = true;
            String rest = "";
            for (Pair<String, Object> p : v) {
                if (first) {
                    first = false;
                    m.put("c1", p.first);
                    m.put("c2", p.second);
                } else {
                    rest += p.first;
                }
            }
            m.put("c3", rest);
            l.add(m);
        }
        state.put(pre + "_lineage", l);
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException("Error in instance " + pre + ": " + e.getLocalizedMessage());
    }
}
Also used : Instance(catdata.fql.decl.Instance) HashMap(java.util.HashMap) Node(catdata.fql.decl.Node) Signature(catdata.fql.decl.Signature) HashMap(java.util.HashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 13 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class PSMAnd method union.

private static Instance union(Instance a, Instance b) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
    for (Node n : a.thesig.nodes) {
        Set<Pair<Object, Object>> set = new HashSet<>();
        set.addAll(a.data.get(n.string));
        set.addAll(b.data.get(n.string));
        data.put(n.string, set);
    }
    for (Edge n : a.thesig.edges) {
        Set<Pair<Object, Object>> set = new HashSet<>();
        set.addAll(a.data.get(n.name));
        set.addAll(b.data.get(n.name));
        data.put(n.name, set);
    }
    return new Instance(a.thesig, data);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 14 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class PSMEval method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        Quad<Instance, Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>>, Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>>, Map<Node, Map<Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>, Object>>> xxx = interp.exps2.get(AB);
        Instance Jw = xxx.first;
        Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>> map = xxx.second;
        Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>> map2 = xxx.third;
        FinCat<Node, Path> cat = Jw.thesig.toCategory2().first;
        Instance abb = new Instance(sig, PSMGen.gather(ABB, sig, state));
        // Instance ab = new Instance(sig, PSMGen.gather(AB, sig, state));
        // //already have in interp
        Instance a = new Instance(sig, PSMGen.gather(A, sig, state));
        Instance b = new Instance(sig, PSMGen.gather(B, sig, state));
        Transform fst = new Transform(abb, Jw, PSMGen.gather(ABB + "_fst", sig, state));
        Transform snd = new Transform(abb, b, PSMGen.gather(ABB + "_snd", sig, state));
        List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
        for (Node n : sig.nodes) {
            List<Pair<Object, Object>> d = new LinkedList<>();
            Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>> m2 = map2.get(n);
            for (Pair<Object, Object> id : abb.data.get(n.string)) {
                Object id_ab = lookup(fst.data.get(n.string), id.first);
                Object x = lookup(snd.data.get(n.string), id.first);
                Transform t = m2.get(id_ab).second;
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> w = m2.get(id_ab).first;
                Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>> m = map.get(new Pair<>(n, w));
                Object y = m.third.get(n).get(new Pair<>(cat.id(n), x));
                Object f = lookup(t.data.get(n.string), y);
                d.add(new Pair<>(id.first, f));
            }
            data.add(new Pair<>(n.string, d));
        }
        Transform curry = new Transform(abb, a, data);
        PSMGen.shred(pre, curry, state);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Instance(catdata.fql.decl.Instance) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Pair(catdata.Pair) Path(catdata.fql.decl.Path) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Transform(catdata.fql.decl.Transform) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 15 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class JDBCBridge method maybeExecInstance.

private static List<PSM> maybeExecInstance(InstOps ops, FQLProgram prog, Statement Stmt, String k, InstExp v, PSMInterp interp, Map<String, Set<Map<Object, Object>>> ret) throws SQLException {
    List<PSM> psm = new LinkedList<>();
    psm.addAll(PSMGen.makeTables(k, v.type(prog).toSig(prog), false));
    switch(DefunctGlobalOptions.debug.fql.sqlKind) {
        case NATIVE:
            psm.addAll(v.accept(k, ops).first);
            interp.interpX(psm, ret);
            break;
        case H2:
        case JDBC:
        default:
            if (v instanceof InstExp.FullSigma) {
                List<PSM> xxx = v.accept(k, ops).first;
                if (xxx.size() != 1) {
                    throw new RuntimeException();
                }
                FullSigma yyy = (FullSigma) xxx.get(0);
                int theguid = getGuid(Stmt);
                interp.guid = theguid;
                yyy.exec(interp, ret);
                Stmt.execute("SET @guid = " + interp.guid);
                psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), ((InstExp.FullSigma) v).F.toMap(prog).source));
            } else if (v instanceof Exp) {
                List<PSM> xxx = v.accept(k, ops).first;
                if (xxx.size() != 1) {
                    throw new RuntimeException();
                }
                ExpPSM yyy = (ExpPSM) xxx.get(0);
                int theguid = getGuid(Stmt);
                interp.guid = theguid;
                yyy.exec(interp, ret);
                Stmt.execute("SET @guid = " + interp.guid);
                psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), null));
            } else if (v instanceof Two) {
                List<PSM> xxx = v.accept(k, ops).first;
                if (xxx.size() != 1) {
                    throw new RuntimeException();
                }
                PropPSM yyy = (PropPSM) xxx.get(0);
                int theguid = getGuid(Stmt);
                interp.guid = theguid;
                yyy.exec(interp, ret);
                Stmt.execute("SET @guid = " + interp.guid);
                psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), null));
            } else if (v instanceof Kernel) {
                List<PSM> xxx = v.accept(k, ops).first;
                if (xxx.size() != 1) {
                    throw new RuntimeException();
                }
                PSMUnChi yyy = (PSMUnChi) xxx.get(0);
                int theguid = getGuid(Stmt);
                interp.guid = theguid;
                yyy.exec(interp, ret);
                Stmt.execute("SET @guid = " + interp.guid);
                psm.addAll(makeInserts(k, ret, v.type(prog).toSig(prog), null));
                Signature ooo = v.type(prog).toSig(prog);
                for (Node n : ooo.nodes) {
                    psm.add(new SimpleCreateTable(k + "_trans_" + n.string, PSM.VARCHAR(), false));
                }
                for (Edge n : ooo.edges) {
                    psm.add(new SimpleCreateTable(k + "_trans_" + n.name, PSM.VARCHAR(), false));
                }
                for (Attribute<Node> n : ooo.attrs) {
                    psm.add(new SimpleCreateTable(k + "_trans_" + n.name, n.target.psm(), false));
                }
                psm.addAll(makeInserts(k + "_trans", ret, v.type(prog).toSig(prog), null));
            } else if (v instanceof External && DefunctGlobalOptions.debug.fql.sqlKind == SQLKIND.H2) {
            } else {
                psm.addAll(v.accept(k, ops).first);
            }
            for (PSM sql : psm) {
                Stmt.execute(sql.toPSM());
            }
            if (!(v instanceof InstExp.FullSigma) && !(v instanceof Exp) && !(v instanceof Two) && !(v instanceof Kernel)) {
                gatherInstance(prog, ret, Stmt, k, v);
            }
            if (v instanceof Delta) {
                gatherSubstInv(prog, ret, Stmt, k, v);
            } else if (v instanceof Times) {
                gatherTransform(prog, ret, Stmt, k + "_fst", v.type(prog).toConst(prog));
                gatherTransform(prog, ret, Stmt, k + "_snd", v.type(prog).toConst(prog));
            } else if (v instanceof One) {
                gatherSubstInv2(prog, ret, Stmt, k, v);
            }
            break;
    }
    return psm;
}
Also used : ExpPSM(catdata.fql.sql.ExpPSM) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) One(catdata.fql.decl.InstExp.One) PSMUnChi(catdata.fql.sql.PSMUnChi) PSM(catdata.fql.sql.PSM) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PropPSM(catdata.fql.sql.PropPSM) Two(catdata.fql.decl.InstExp.Two) LinkedList(java.util.LinkedList) InstExp(catdata.fql.decl.InstExp) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) Delta(catdata.fql.decl.InstExp.Delta) Signature(catdata.fql.decl.Signature) Times(catdata.fql.decl.InstExp.Times) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.sql.FullSigma) LinkedList(java.util.LinkedList) List(java.util.List) Exp(catdata.fql.decl.InstExp.Exp) InstExp(catdata.fql.decl.InstExp) TransExp(catdata.fql.decl.TransExp) Kernel(catdata.fql.decl.InstExp.Kernel) Edge(catdata.fql.decl.Edge)

Aggregations

Node (catdata.fql.decl.Node)51 Pair (catdata.Pair)38 HashMap (java.util.HashMap)36 Edge (catdata.fql.decl.Edge)33 LinkedList (java.util.LinkedList)26 LinkedHashMap (java.util.LinkedHashMap)25 Instance (catdata.fql.decl.Instance)22 Path (catdata.fql.decl.Path)21 Map (java.util.Map)21 FQLException (catdata.fql.FQLException)20 Attribute (catdata.fql.decl.Attribute)19 HashSet (java.util.HashSet)19 Arr (catdata.fql.cat.Arr)14 Signature (catdata.fql.decl.Signature)13 Set (java.util.Set)13 Transform (catdata.fql.decl.Transform)11 List (java.util.List)10 Triple (catdata.Triple)5 Fn (catdata.fql.Fn)4 FinCat (catdata.fql.cat.FinCat)3