Search in sources :

Example 36 with Edge

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

the class JDBCBridge method makeInserts.

private static List<PSM> makeInserts(String k, Map<String, Set<Map<Object, Object>>> state, Signature sig, Signature src_sig) {
    List<PSM> ret = new LinkedList<>();
    List<String> attrs = new LinkedList<>();
    attrs.add("c0");
    attrs.add("c1");
    if (src_sig != null) {
        for (Node n : src_sig.nodes) {
            Set<Map<Object, Object>> v = state.get(k + "_" + n.string + "_e");
            ret.add(new SimpleCreateTable(k + "_" + n.string + "_e", PSM.VARCHAR(), false));
            if (v.isEmpty()) {
                continue;
            }
            ret.add(new InsertValues(k + "_" + n.string + "_e", attrs, v));
        }
        Set<Map<Object, Object>> v = state.get(k + "_lineage");
        Map<String, String> at = new LinkedHashMap<>();
        at.put("c0", PSM.VARCHAR());
        at.put("c1", PSM.VARCHAR());
        at.put("c2", PSM.VARCHAR());
        at.put("c3", PSM.VARCHAR());
        ret.add(new CreateTable(k + "_lineage", at, false));
        if (!v.isEmpty()) {
            ret.add(new InsertValues(k + "_lineage", new LinkedList<>(at.keySet()), v));
        }
    }
    for (Node n : sig.nodes) {
        Set<Map<Object, Object>> v = state.get(k + "_" + n.string);
        if (v.isEmpty()) {
            continue;
        }
        ret.add(new InsertValues(k + "_" + n.string, attrs, v));
    }
    for (Edge e : sig.edges) {
        Set<Map<Object, Object>> v = state.get(k + "_" + e.name);
        if (v.isEmpty()) {
            continue;
        }
        ret.add(new InsertValues(k + "_" + e.name, attrs, v));
    }
    for (Attribute<Node> a : sig.attrs) {
        Set<Map<Object, Object>> v = state.get(k + "_" + a.name);
        if (v.isEmpty()) {
            continue;
        }
        ret.add(new InsertValues(k + "_" + a.name, attrs, v));
    }
    return ret;
}
Also used : Node(catdata.fql.decl.Node) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) CreateTable(catdata.fql.sql.CreateTable) PSM(catdata.fql.sql.PSM) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) InsertValues(catdata.fql.sql.InsertValues) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge)

Example 37 with Edge

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

the class LeftKanCat method helper.

private static Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> helper(LeftKan lk, Signature B) throws FQLException {
    List<Node> objects = B.nodes;
    Set<Arr<Node, Path>> arrows = new HashSet<>();
    Map<Node, Arr<Node, Path>> identities = new HashMap<>();
    Fn<Path, Integer> fn = makeFn(lk);
    List<Path> paths = new LinkedList<>();
    Map<Integer, Path> fn2 = new HashMap<>();
    int numarrs = numarrs(lk);
    for (Node n : B.nodes) {
        paths.add(new Path(B, n));
    }
    outer: for (int iter = 0; iter < DefunctGlobalOptions.debug.fql.MAX_PATH_LENGTH; iter++) {
        for (Path p : paths) {
            Integer i = fn.of(p);
            fn2.putIfAbsent(i, p);
            if (fn2.size() == numarrs) {
                break outer;
            }
        }
        List<Path> paths0 = new LinkedList<>();
        for (Path p : paths) {
            for (Edge e : B.outEdges(p.target)) {
                paths0.add(Path.append(B, p, new Path(B, e)));
            }
        }
        paths = paths0;
    }
    if (fn2.size() < numarrs) {
        String old_str = "Basis path lengths exceed allowed limit (" + DefunctGlobalOptions.debug.fql.MAX_PATH_LENGTH + ").  Only have " + fn2.size() + " basis paths out of required " + numarrs + "." + "  Probable cause: using parallel or hybrid left-kan algorithm (see options).";
        throw new FQLException(old_str);
    }
    for (Integer i : fn2.keySet()) {
        Path p = fn2.get(i);
        arrows.add(new Arr<>(p, p.source, p.target));
    }
    for (Node n : objects) {
        Arr<Node, Path> a = new Arr<>(fn2.get(getOne(lk.ua.get(n)).second), n, n);
        identities.put(n, a);
        for (Pair<Integer, Integer> i : lk.Pb.get(n)) {
            Path p = fn2.get(i.first);
            arrows.add(new Arr<>(p, p.source, p.target));
        }
    }
    Fn<Path, Arr<Node, Path>> r2 = (Path x) -> {
        if (fn2.get(fn.of(x)) == null) {
            throw new RuntimeException("Given path " + x + ", transforms to " + fn.of(x) + ", which is not in " + fn2);
        }
        return new Arr<>(fn2.get(fn.of(x)), x.source, x.target);
    };
    Map<Pair<Arr<Node, Path>, Arr<Node, Path>>, Arr<Node, Path>> composition = new HashMap<>();
    for (Arr<Node, Path> x : arrows) {
        for (Arr<Node, Path> y : arrows) {
            if (x.dst.equals(y.src)) {
                composition.put(new Pair<>(x, y), r2.of(Path.append(B, x.arr, y.arr)));
            }
        }
    }
    FinCat<Node, Path> r1 = new FinCat<>(objects, new LinkedList<>(arrows), composition, identities);
    return new Pair<>(r1, r2);
}
Also used : HashMap(java.util.HashMap) Node(catdata.fql.decl.Node) FQLException(catdata.fql.FQLException) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Pair(catdata.Pair) Path(catdata.fql.decl.Path) LinkedList(java.util.LinkedList) Edge(catdata.fql.decl.Edge)

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