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;
}
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);
}
Aggregations