Search in sources :

Example 21 with Edge

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

the class PSMGen method pi.

public static Pair<List<PSM>, Map<String, Triple<Node, Node, Arr<Node, Path>>[]>> pi(Mapping F0, String src, String dst) throws FQLException {
    tempTables = 0;
    Signature D0 = F0.target;
    Signature C0 = F0.source;
    Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> kkk = D0.toCategory2();
    FinCat<Node, Path> D = kkk.first;
    FinCat<Node, Path> C = C0.toCategory2().first;
    FinFunctor<Node, Path, Node, Path> F = F0.toFunctor2().first;
    List<PSM> ret = new LinkedList<>();
    Map<String, Triple<Node, Node, Arr<Node, Path>>[]> colmap = new HashMap<>();
    Map<String, Attribute<Node>[]> amap = new HashMap<>();
    List<Node> doNotDrop = new LinkedList<>();
    for (Node d0 : D.objects) {
        CommaCat<Node, Path, Node, Path, Node, Path> B = doComma(D, C, F, d0, D0);
        Map<Triple<Node, Node, Arr<Node, Path>>, String> xxx1 = new HashMap<>();
        Map<Pair<Arr<Node, Path>, Arr<Node, Path>>, String> xxx2 = new HashMap<>();
        List<PSM> xxx3 = deltaX(src, xxx1, xxx2, B.projB);
        ret.addAll(xxx3);
        Triple<Flower, Triple<Node, Node, Arr<Node, Path>>[], Attribute<Node>[]> xxx = lim(src, C0, D, B, xxx1, xxx2);
        // comma cat is empty, need unit for product
        if (xxx == null) {
            doNotDrop.add(d0);
            Map<String, String> attrs2 = new HashMap<>();
            attrs2.put("guid", PSM.VARCHAR());
            ret.add(new CreateTable(dst + "_" + d0.string + "_limit", attrs2, false));
            ret.add(new InsertEmptyKeygen(dst + "_" + d0.string + "_limit"));
            ret.add(new InsertSQL(dst + "_" + d0.string, new SquishFlower(dst + "_" + d0.string + "_limit"), "c0", "c1"));
            @SuppressWarnings("unchecked") Triple<Node, Node, Arr<Node, Path>>[] cols = new Triple[0];
            colmap.put(d0.string, cols);
            continue;
        }
        Triple<Node, Node, Arr<Node, Path>>[] cols = xxx.second;
        Flower r = xxx.first;
        for (Attribute<Node> a : D0.attrsFor(d0)) {
            List<Attribute<Node>> ls = new LinkedList<>();
            for (Attribute<Node> aa : C0.attrs) {
                if (F.am.get(aa).equals(a)) {
                    ls.add(aa);
                }
            }
            for (int jj = 1; jj < ls.size(); jj++) {
                int xxx02 = cnamelkp(xxx.third, ls.get(0));
                int xxx04 = cnamelkp(xxx.third, ls.get(jj));
                r.where.add(new Pair<>(new Pair<>("t" + (xxx02 + xxx.second.length), "c1"), new Pair<>("t" + (xxx04 + xxx.second.length), "c1")));
            }
        }
        colmap.put(d0.string, cols);
        amap.put(d0.string, xxx.third);
        Map<String, String> attrs1 = new HashMap<>();
        for (int i = 0; i < xxx.second.length; i++) {
            attrs1.put("c" + i, PSM.VARCHAR());
        }
        for (int j = 0; j < xxx.third.length; j++) {
            attrs1.put("c" + (xxx.second.length + j), xxx.third[j].target.psm());
        }
        Map<String, String> attrs2 = new HashMap<>(attrs1);
        attrs2.put("guid", PSM.VARCHAR());
        List<String> attcs = new LinkedList<>(attrs1.keySet());
        ret.add(new CreateTable(dst + "_" + d0.string + "_limnoguid", attrs1, false));
        ret.add(new InsertSQL2(dst + "_" + d0.string + "_limnoguid", r, new LinkedList<>(r.select.keySet())));
        ret.add(new CreateTable(dst + "_" + d0.string + "_limit", attrs2, false));
        ret.add(new InsertKeygen(dst + "_" + d0.string + "_limit", "guid", dst + "_" + d0.string + "_limnoguid", attcs));
        // craeted by createTables
        // ret.add(new CreateTable(dst + "_" + d0.string, twocol_attrs));
        ret.add(new InsertSQL(dst + "_" + d0.string, new SquishFlower(dst + "_" + d0.string + "_limit"), "c0", "c1"));
    }
    for (Edge s : F0.target.edges) {
        Node dA = s.source;
        Node dB = s.target;
        String q2 = dB.string;
        String q1 = dA.string;
        Triple<Node, Node, Arr<Node, Path>>[] q2cols = colmap.get(q2);
        Triple<Node, Node, Arr<Node, Path>>[] q1cols = colmap.get(q1);
        if (q2cols == null) {
            throw new RuntimeException("Cannot find " + q2 + " in " + colmap);
        }
        List<Pair<Pair<String, String>, Pair<String, String>>> where = subset(D, kkk.second.of(new Path(D0, s)), dst, q2cols, q1cols, q2, q1);
        Map<String, String> from = new HashMap<>();
        from.put(dst + "_" + q1 + "_limit_1", dst + "_" + q1 + "_limit");
        from.put(dst + "_" + q2 + "_limit_2", dst + "_" + q2 + "_limit");
        LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
        select.put("c0", new Pair<>(dst + "_" + q1 + "_limit_1", "guid"));
        select.put("c1", new Pair<>(dst + "_" + q2 + "_limit_2", "guid"));
        Flower f = new Flower(select, from, where);
        ret.add(new InsertSQL(dst + "_" + s.name, f, "c0", "c1"));
    }
    for (Attribute<Node> a : F0.target.attrs) {
        int i = colmap.get(a.source.string).length;
        Attribute<Node>[] y = amap.get(a.source.string);
        if (y == null) {
            throw new FQLException("Attribute mapping not surjective " + a.source.string);
        }
        boolean found = false;
        int u = 0;
        // int j = -1;
        List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
        LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
        Map<String, String> from = new HashMap<>();
        List<Integer> xxx = new LinkedList<>();
        for (Attribute<Node> b : y) {
            if (!F0.am.get(b).equals(a)) {
                u++;
                continue;
            }
            found = true;
            xxx.add(u);
            u++;
        }
        if (!found) {
            throw new FQLException("Attribute mapping not found " + a);
        }
        from.put(dst + "_" + a.source + "_limit", dst + "_" + a.source + "_limit");
        select.put("c0", new Pair<>(dst + "_" + a.source + "_limit", "guid"));
        for (int jj = 1; jj < xxx.size(); jj++) {
            where.add(new Pair<>(new Pair<>(dst + "_" + a.source + "_limit", "c" + (xxx.get(0) + i)), new Pair<>(dst + "_" + a.source + "_limit", "c" + (xxx.get(jj) + i))));
        }
        select.put("c1", new Pair<>(dst + "_" + a.source + "_limit", "c" + (xxx.get(0) + i)));
        Flower f = new Flower(select, from, where);
        ret.add(new InsertSQL(dst + "_" + a.name, f, "c0", "c1"));
    // project guid and u+i
    }
    for (Node d0 : D.objects) {
        if (doNotDrop.contains(d0)) {
            continue;
        }
        ret.add(new DropTable(dst + "_" + d0.string + "_limnoguid"));
    }
    for (int ii = 0; ii < tempTables; ii++) {
        ret.add(new DropTable("temp" + ii));
    }
    return new Pair<>(ret, colmap);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FinCat(catdata.fql.cat.FinCat) Node(catdata.fql.decl.Node) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Arr(catdata.fql.cat.Arr) Attribute(catdata.fql.decl.Attribute) Pair(catdata.Pair) Path(catdata.fql.decl.Path) Fn(catdata.fql.Fn) Signature(catdata.fql.decl.Signature) Edge(catdata.fql.decl.Edge)

Example 22 with Edge

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

the class PSMGen method compose.

public static Flower compose(String pre, Path p) {
    LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
    Map<String, String> from = new HashMap<>();
    List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
    from.put("t0", pre + "_" + p.source.string);
    int i = 1;
    for (Edge e : p.path) {
        from.put("t" + i, pre + "_" + e.name);
        where.add(new Pair<>(new Pair<>("t" + (i - 1), "c1"), new Pair<>("t" + i, "c0")));
        i++;
    }
    select.put("c0", new Pair<>("t0", "c0"));
    select.put("c1", new Pair<>("t" + (i - 1), "c1"));
    return new Flower(select, from, where);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Edge(catdata.fql.decl.Edge) LinkedList(java.util.LinkedList) Pair(catdata.Pair) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with Edge

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

the class PSMGen method gather.

public static List<Pair<String, List<Pair<Object, Object>>>> gather(String pre, Signature sig, Map<String, Set<Map<Object, Object>>> state) {
    List<Pair<String, List<Pair<Object, Object>>>> ret = new LinkedList<>();
    for (Node n : sig.nodes) {
        Set<Map<Object, Object>> v = state.get(pre + "_" + n.string);
        if (v == null) {
            throw new RuntimeException("Missing: " + pre + "_" + n.string + " in " + state.keySet());
        }
        ret.add(new Pair<>(n.string, gather0(v)));
    }
    for (Edge e : sig.edges) {
        Set<Map<Object, Object>> v = state.get(pre + "_" + e.name);
        ret.add(new Pair<>(e.name, gather0(v)));
    }
    for (Attribute<Node> a : sig.attrs) {
        Set<Map<Object, Object>> v = state.get(pre + "_" + a.name);
        ret.add(new Pair<>(a.name, gather0(v)));
    }
    return ret;
}
Also used : Node(catdata.fql.decl.Node) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 24 with Edge

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

the class PSMGen method shred.

public static void shred(String pre, Transform I, Map<String, Set<Map<Object, Object>>> state) {
    for (Node n : I.src.thesig.nodes) {
        Set<Map<Object, Object>> m = new HashSet<>();
        for (Pair<Object, Object> k : I.data.get(n.string)) {
            Map<Object, Object> map = new HashMap<>();
            map.put("c0", k.first);
            map.put("c1", k.second);
            m.add(map);
        }
        state.put(pre + "_" + n.string, m);
    }
    for (Edge n : I.src.thesig.edges) {
        state.put(pre + "_" + n.name, new HashSet<>());
    }
    for (Attribute<Node> n : I.src.thesig.attrs) {
        state.put(pre + "_" + n.name, new HashSet<>());
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(catdata.fql.decl.Node) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge) HashSet(java.util.HashSet)

Example 25 with Edge

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

the class PSMNot method calcSub.

private Instance calcSub(Signature sig0, Triple<Instance, Map<Object, Path>, Map<Path, Object>> Hc, Instance A) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> notA_data = new HashMap<>();
    for (Node d : sig.nodes) {
        Set<Pair<Object, Object>> dd = new HashSet<>();
        xxx: for (Object f : Hc.first.getNode(d)) {
            Path ff = Hc.second.get(f);
            // boolean b = true;
            for (Node d0 : sig.nodes) {
                for (Arr<Node, Path> g : sig.toCategory2().first.hom(d, d0)) {
                    Arr<Node, Path> fg = sig.toCategory2().first.compose(sig.toCategory2().second.of(ff), g);
                    Object xxx = Hc.third.get(fg.arr);
                    if (xxx == null) {
                        throw new RuntimeException();
                    }
                    if (A.getNode(d0).contains(xxx)) {
                        continue xxx;
                    }
                }
            }
            dd.add(new Pair<>(f, f));
        }
        notA_data.put(d.string, dd);
    }
    for (Edge h : sig.edges) {
        Set<Pair<Object, Object>> dd = new HashSet<>();
        for (Pair<Object, Object> oo : notA_data.get(h.source.string)) {
            Object f = oo.first;
            Path ff = Hc.second.get(f);
            Arr<Node, Path> fg = sig.toCategory2().first.compose(sig.toCategory2().second.of(ff), sig.toCategory2().second.of(new Path(sig, h)));
            Object xxx = Hc.third.get(fg.arr);
            dd.add(new Pair<>(f, xxx));
        }
        notA_data.put(h.name, dd);
    }
    Instance notA = new Instance(sig0, notA_data);
    return notA;
}
Also used : Path(catdata.fql.decl.Path) Arr(catdata.fql.cat.Arr) 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)

Aggregations

Edge (catdata.fql.decl.Edge)37 Node (catdata.fql.decl.Node)33 HashMap (java.util.HashMap)27 Pair (catdata.Pair)25 HashSet (java.util.HashSet)19 LinkedList (java.util.LinkedList)19 LinkedHashMap (java.util.LinkedHashMap)17 Instance (catdata.fql.decl.Instance)15 Set (java.util.Set)13 Map (java.util.Map)12 FQLException (catdata.fql.FQLException)11 Path (catdata.fql.decl.Path)11 Attribute (catdata.fql.decl.Attribute)10 Signature (catdata.fql.decl.Signature)9 List (java.util.List)7 Arr (catdata.fql.cat.Arr)6 Fn (catdata.fql.Fn)4 Transform (catdata.fql.decl.Transform)4 Triple (catdata.Triple)3 FinCat (catdata.fql.cat.FinCat)3