use of catdata.fql.decl.Node in project fql by CategoricalData.
the class Chase method sigma.
public static Instance sigma(Mapping m, Instance i) throws FQLException {
Triple<Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>> kkk = m.toEDs();
Signature cd = kkk.second.first;
Map<String, Set<Pair<Object, Object>>> I = new HashMap<>();
for (Node n : cd.nodes) {
I.put(n.string, new HashSet<>());
}
for (Edge n : cd.edges) {
I.put(n.name, new HashSet<>());
}
for (Attribute<Node> n : cd.attrs) {
I.put(n.name, new HashSet<>());
}
for (String k : i.data.keySet()) {
I.put("src_" + k, i.data.get(k));
}
List<EmbeddedDependency> eds0 = Signature.toED("", kkk.second);
Pair<List<Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>>>, List<Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>>>> zzz = split(eds0);
Set<String> keys = new HashSet<>();
for (Node n : m.target.nodes) {
keys.add("dst_" + n.string);
}
for (Edge n : m.target.edges) {
keys.add("dst_" + n.name);
}
for (Attribute<Node> n : m.target.attrs) {
keys.add("dst_" + n.name);
}
Map<String, Set<Pair<Object, Object>>> res = chase(keys, zzz, I, KIND.PARALLEL);
Map<String, Set<Pair<Object, Object>>> res0 = new HashMap<>();
for (Node n : m.target.nodes) {
res0.put(n.string, res.get("dst_" + n.string));
}
for (Edge n : m.target.edges) {
res0.put(n.name, res.get("dst_" + n.name));
}
for (Attribute<Node> n : m.target.attrs) {
res0.put(n.name, res.get("dst_" + n.name));
}
Instance ret = new Instance(m.target, res0);
return ret;
}
use of catdata.fql.decl.Node in project fql by CategoricalData.
the class Chase method delta.
public static Instance delta(Mapping m, Instance i) throws FQLException {
Triple<Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>> kkk = m.toEDs();
Signature cd = m.toEDs().first.first;
Map<String, Set<Pair<Object, Object>>> I = new HashMap<>();
for (Node n : cd.nodes) {
I.put(n.string, new HashSet<>());
}
for (Edge n : cd.edges) {
I.put(n.name, new HashSet<>());
}
for (Attribute<Node> n : cd.attrs) {
I.put(n.name, new HashSet<>());
}
for (String k : i.data.keySet()) {
I.put("dst_" + k, i.data.get(k));
}
List<EmbeddedDependency> eds0 = Signature.toED("", kkk.first);
Pair<List<Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>>>, List<Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>>>> zzz = split(eds0);
Set<String> keys = new HashSet<>();
for (Node n : m.target.nodes) {
keys.add("src_" + n.string);
}
for (Edge n : m.target.edges) {
keys.add("src_" + n.name);
}
for (Attribute<Node> n : m.target.attrs) {
keys.add("src_" + n.name);
}
// changed
Map<String, Set<Pair<Object, Object>>> res = chase(keys, zzz, I, KIND.HYBRID);
Map<String, Set<Pair<Object, Object>>> res0 = new HashMap<>();
for (Node n : m.source.nodes) {
res0.put(n.string, res.get("src_" + n.string));
}
for (Edge n : m.source.edges) {
res0.put(n.name, res.get("src_" + n.name));
}
for (Attribute<Node> n : m.source.attrs) {
res0.put(n.name, res.get("src_" + n.name));
}
Instance ret = new Instance(m.source, res0);
return ret;
}
use of catdata.fql.decl.Node in project fql by CategoricalData.
the class CategoryOfElements method build.
private static Pair<Graph<Pair<Node, Object>, Pair<Path, Integer>>, HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>>> build(Instance i) throws FQLException {
FinCat<Node, Path> c = i.thesig.toCategory2().first;
HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>> map = new HashMap<>();
Graph<Pair<Node, Object>, Pair<Path, Integer>> g2 = new DirectedSparseMultigraph<>();
for (Node n : c.objects) {
for (Pair<Object, Object> o : i.data.get(n.string)) {
Pair<Node, Object> xx = new Pair<>(n, o.first);
g2.addVertex(xx);
List<Attribute<Node>> attrs = i.thesig.attrsFor(n);
Map<Attribute<Node>, Object> m = new HashMap<>();
for (Attribute<Node> attr : attrs) {
Object a = lookup(i.data.get(attr.name), o.first);
m.put(attr, a);
}
map.put(xx, m);
}
}
int j = 0;
for (Pair<Node, Object> x : g2.getVertices()) {
for (Pair<Node, Object> y : g2.getVertices()) {
Set<Arr<Node, Path>> h = c.hom(x.first, y.first);
for (Arr<Node, Path> arr : h) {
if (c.isId(arr)) {
continue;
}
if (!DefunctGlobalOptions.debug.fql.ALL_GR_PATHS && arr.arr.path.size() != 1) {
continue;
}
if (doLookup(i, arr.arr, x.second, y.second)) {
g2.addEdge(new Pair<>(arr.arr, j++), x, y);
}
}
}
}
return new Pair<>(g2, map);
}
use of catdata.fql.decl.Node 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);
}
use of catdata.fql.decl.Node in project fql by CategoricalData.
the class PSMGen method deltaX.
private static List<PSM> deltaX(String pre, Map<Triple<Node, Node, Arr<Node, Path>>, String> ob, Map<Pair<Arr<Node, Path>, Arr<Node, Path>>, String> ar, FinFunctor<Triple<Node, Node, Arr<Node, Path>>, Pair<Arr<Node, Path>, Arr<Node, Path>>, Node, Path> projB) {
Map<String, String> twocol_attrs = new HashMap<>();
twocol_attrs.put("c0", PSM.VARCHAR());
twocol_attrs.put("c1", PSM.VARCHAR());
List<PSM> ret = new LinkedList<>();
for (Entry<Triple<Node, Node, Arr<Node, Path>>, Node> p : projB.objMapping.entrySet()) {
ob.put(p.getKey(), pre + "_" + p.getKey().second.string);
}
for (Entry<Arr<Triple<Node, Node, Arr<Node, Path>>, Pair<Arr<Node, Path>, Arr<Node, Path>>>, Arr<Node, Path>> p : projB.arrowMapping.entrySet()) {
Path x = p.getKey().arr.second.arr;
ret.add(new CreateTable("temp" + tempTables, twocol_attrs, false));
ret.add(new InsertSQL("temp" + tempTables, compose(pre, x), "c0", "c1"));
ar.put(p.getKey().arr, "temp" + tempTables++);
}
return ret;
}
Aggregations