Search in sources :

Example 6 with Block

use of catdata.fpql.XPoly.Block in project fql by CategoricalData.

the class EnrichViewer method enrich.

private static XPoly<String, String> enrich(XCtx<String> S0, XSchema S, String s, String T, String mat, String name, String a, /*String b,*/
String l, String r, String n) {
    Map<Object, Pair<String, Block<String, String>>> blocks = new HashMap<>();
    // Map<String, Map<String, Triple<String, String, List<String>>>> vars1 = new HashMap<>();
    Map<String, Map<Triple<String, String, List<String>>, String>> vars2 = new HashMap<>();
    int i = 0;
    for (String X : S.nodes) {
        // Map<String, Triple<String, String, List<String>>> m1 = new HashMap<>();
        Map<Triple<String, String, List<String>>, String> m2 = new HashMap<>();
        // vars1.put(X, m1);
        vars2.put(X, m2);
        for (Triple<String, String, List<String>> rp : S0.cat().hom(X, mat)) {
            // m1.put("v" + i, rp);
            m2.put(rp, "v" + i);
            i++;
        }
    }
    for (String X : S.nodes) {
        Map<Object, String> from = new HashMap<>();
        from.put("x", X);
        Set<Pair<List<Object>, List<Object>>> where = new HashSet<>();
        Map<String, List<Object>> attrs = new HashMap<>();
        Map<String, Pair<Object, Map<Object, List<Object>>>> edges = new HashMap<>();
        // Map<String, Triple<String, String, List<String>>> m1 = vars1.get(X); //new HashMap<>();
        // new HashMap<>();
        Map<Triple<String, String, List<String>>, String> m2 = vars2.get(X);
        for (Triple<String, String, List<String>> p : S0.cat().hom(X, mat)) {
            String rp = m2.get(p);
            from.put(rp, a);
            List<Object> lhs = new LinkedList<>();
            List<Object> rhs = new LinkedList<>();
            lhs.add("x");
            lhs.addAll(p.third);
            lhs.add(name);
            rhs.add(rp);
            rhs.add(l);
            rhs.add(n);
            where.add(new Pair<>(lhs, rhs));
        }
        for (Triple<String, String, String> e : S.arrows) {
            Map<Object, List<Object>> map = new HashMap<>();
            if (!e.second.equals(X)) {
                continue;
            }
            if (S.nodes.contains(e.third)) {
                List<Object> xxx = new LinkedList<>();
                xxx.add("x");
                xxx.add(e.first);
                map.put("x", xxx);
                for (Triple<String, String, List<String>> p0 : S0.cat().hom(e.third, mat)) {
                    Object rep0 = vars2.get(e.third).get(p0);
                    List<String> list = new LinkedList<>();
                    list.add(e.first);
                    list.addAll(p0.third);
                    Triple<String, String, List<String>> ep0 = S0.find_fast(new Triple<>(X, p0.second, list));
                    if (ep0 == null) {
                        throw new RuntimeException("Cannot find " + new Triple<>(X, e.third, list) + " in " + S0);
                    }
                    String tgt = m2.get(ep0);
                    if (tgt == null) {
                        throw new RuntimeException("Cannot find " + ep0 + " in " + m2.keySet());
                    }
                    List<Object> yyh = Collections.singletonList(tgt);
                    map.put(rep0, yyh);
                }
                edges.put(e.first, new Pair<>("q" + e.third, map));
            // edge
            } else {
                List<Object> list = new LinkedList<>();
                if (e.first.equals(name) && X.equals(mat)) {
                    Triple<String, String, List<String>> id = S0.find_fast(new Triple<>(mat, mat, new LinkedList<>()));
                    list.add(m2.get(id));
                    list.add(r);
                    list.add(n);
                } else {
                    list.add("x");
                    list.add(e.first);
                }
                attrs.put(e.first, list);
            // att
            }
        }
        Block<String, String> block = new Block<>(from, where, attrs, edges);
        blocks.put("q" + X, new Pair<>(X, block));
    }
    XPoly<String, String> poly = new XPoly<>(new Var(s), new Var(T), blocks);
    return poly;
}
Also used : HashMap(java.util.HashMap) Var(catdata.fpql.XExp.Var) LinkedList(java.util.LinkedList) List(java.util.List) Pair(catdata.Pair) HashSet(java.util.HashSet) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Block(catdata.fpql.XPoly.Block) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Block (catdata.fpql.XPoly.Block)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Pair (catdata.Pair)5 Map (java.util.Map)5 Triple (catdata.Triple)3 Set (java.util.Set)3 Var (catdata.fpql.XExp.Var)2 XPair (catdata.fpql.XExp.XPair)1 LinkedHashMap (java.util.LinkedHashMap)1 Tuple3 (org.jparsec.functors.Tuple3)1 Tuple4 (org.jparsec.functors.Tuple4)1 Tuple5 (org.jparsec.functors.Tuple5)1