use of catdata.fpql.XExp.XMapConst in project fql by CategoricalData.
the class XRaToFpql method trans.
private static Pair<String, XSchema> trans(XSchema src, EFlower fl, String pre, Set<Object> enums) {
// SigExp src0 = new SigExp.Var("S");
// LinkedList<Pair<List<String>, List<String>>> eqs =
List<String> nodes1 = new LinkedList<>();
List<String> nodes2 = new LinkedList<>();
List<String> nodes3 = new LinkedList<>();
// nodes1.add("adom");
// nodes2.add("adom");
nodes2.add("guid");
// nodes3.add("adom");
// List<Triple<String, String, String>> attrs = new LinkedList<>();
// attrs.add(new Triple<>("att", "adom", "adom"));
List<Triple<String, String, String>> edges1 = new LinkedList<>();
List<Triple<String, String, String>> edges2 = new LinkedList<>();
List<Triple<String, String, String>> edges3 = new LinkedList<>();
List<Pair<String, String>> inodes1 = new LinkedList<>();
List<Pair<String, String>> inodes2 = new LinkedList<>();
List<Pair<String, String>> inodes3 = new LinkedList<>();
// inodes1.add(new Pair<>("adom", "adom"));
// inodes2.add(new Pair<>("adom", "adom"));
// inodes3.add(new Pair<>("adom", "adom"));
// List<Pair<String, String>> iattrs = new LinkedList<>();
// iattrs.add(new Pair<>("att", "att"));
List<Pair<String, List<String>>> iedges1 = new LinkedList<>();
List<Pair<String, List<String>>> iedges2 = new LinkedList<>();
List<Pair<String, List<String>>> iedges3 = new LinkedList<>();
for (String k : fl.from.keySet()) {
String v = fl.from.get(k);
inodes1.add(new Pair<>(k, v));
nodes1.add(k);
inodes2.add(new Pair<>(k, "guid"));
for (Triple<String, String, String> arr : src.arrows) {
if (arr.second.equals(v)) {
List<String> l = new LinkedList<>();
l.add(v);
l.add(arr.first);
edges1.add(new Triple<>(k + "_" + arr.first, k, "adom"));
iedges1.add(new Pair<>(k + "_" + arr.first, l));
edges2.add(new Triple<>(k + "_" + arr.first, "guid", "adom"));
List<String> l0 = new LinkedList<>();
l0.add("guid");
l0.add(k + "_" + arr.first);
iedges2.add(new Pair<>(k + "_" + arr.first, l0));
}
}
}
List<List<Triple<String, String, String>>> eqcs = merge(edges2, fl);
// for each p.q = 3, add (eqc_for(p.q).get(0) = 3) to some list
Iterator<Triple<String, String, String>> it = edges2.iterator();
while (it.hasNext()) {
Triple<String, String, String> k = it.next();
for (List<Triple<String, String, String>> v : eqcs) {
if (v.contains(k) && !v.get(0).equals(k)) {
it.remove();
}
}
}
for (Pair<String, List<String>> kk : iedges2) {
Triple<String, String, String> k = new Triple<>(kk.second.get(1), "guid", "adom");
for (List<Triple<String, String, String>> v : eqcs) {
if (v.contains(k) && !v.get(0).equals(k)) {
List<String> xxx = new LinkedList<>();
xxx.add("guid");
xxx.add(v.get(0).first);
kk.second = xxx;
break;
}
}
}
nodes3.add("guid");
inodes3.add(new Pair<>("guid", "guid"));
for (String k : fl.select.keySet()) {
Pair<String, String> v = fl.select.get(k);
edges3.add(new Triple<>(k, "guid", "adom"));
Triple<String, String, String> t = new Triple<>(v.first + "_" + fl.from.get(v.first) + "_" + v.second, "guid", "adom");
if (fl.from.get(v.first) == null) {
throw new RuntimeException(v.first + " is not selectable in " + fl);
}
for (List<Triple<String, String, String>> eqc : eqcs) {
if (eqc.contains(t)) {
List<String> li = new LinkedList<>();
li.add("guid");
li.add(eqc.get(0).first);
iedges3.add(new Pair<>(k, li));
}
}
}
XSchema sig1 = doSchema(nodes1, /* attrs, */
edges1, new LinkedList<>());
XSchema sig2 = doSchema(nodes2, /* attrs, */
edges2, new LinkedList<>());
XSchema sig3 = doSchema(nodes3, /* attrs, */
edges3, new LinkedList<>());
for (Pair<Pair<String, String>, Pair<String, String>> x : fl.where) {
if (x.second.second != null) {
continue;
}
// : add to global consts
String c = x.second.first;
enums.add(c);
Triple<String, String, String> found = null;
Triple<String, String, String> tofind = new Triple<>(x.first.first + "_" + fl.from.get(x.first.first) + "_" + x.first.second, "guid", "adom");
for (List<Triple<String, String, String>> eqc : eqcs) {
if (eqc.contains(tofind)) {
found = eqc.get(0);
break;
}
}
if (found == null) {
throw new RuntimeException("Bad flower: " + fl);
}
List<String> lhs = new LinkedList<>();
lhs.add(found.first);
// lhs.add("att");
List<String> rhs = new LinkedList<>();
rhs.add("\"!_guid\"");
rhs.add(c);
Pair<List<String>, List<String>> eq = new Pair<>(lhs, rhs);
sig2.eqs.add(eq);
}
XMapConst map1 = doMapping(inodes1, /* iattrs, */
iedges1, sig1, new Var("S"));
XMapConst map2 = doMapping(inodes2, /* iattrs, */
iedges2, src, sig2);
XMapConst map3 = doMapping(inodes3, /* iattrs, */
iedges3, sig3, sig2);
String xxx = "";
xxx += "\n\n" + pre + "fromSchema = " + sig1;
xxx += "\n\n" + pre + "fromMapping = " + map1 + " : " + pre + "fromSchema -> S";
xxx += "\n\n" + pre + "fromInstance = delta " + pre + "fromMapping I";
xxx += "\n\n" + pre + "whereSchema = " + sig2;
xxx += "\n\n" + pre + "whereMapping = " + map2 + " : " + pre + "fromSchema -> " + pre + "whereSchema";
xxx += "\n\n" + pre + "whereInstance = pi " + pre + "whereMapping " + pre + "fromInstance";
xxx += "\n\n" + pre + "Schema = " + sig3;
xxx += "\n\n" + pre + "selectMapping = " + map3 + " : " + pre + "Schema -> " + pre + "whereSchema";
if (fl.distinct) {
xxx += "\n\n" + pre + "selectInstance = delta " + pre + "selectMapping " + pre + "whereInstance";
xxx += "\n\n" + pre + " = relationalize " + pre + "selectInstance";
} else {
xxx += "\n\n" + pre + " = delta " + pre + "selectMapping " + pre + "whereInstance";
}
String comment = longSlash + "\n/* " + "Translation of " + pre + " */\n" + longSlash;
return new Pair<>(comment + xxx, sig3);
}
use of catdata.fpql.XExp.XMapConst in project fql by CategoricalData.
the class XParser method toMapping.
private static XMapConst toMapping(Object decl) {
Tuple5 y = (Tuple5) decl;
org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
Tuple3 nodes = (Tuple3) x.a;
Tuple3 arrows = (Tuple3) x.b;
List nodes0 = (List) nodes.b;
List arrows0 = (List) arrows.b;
List<Pair<String, String>> nodesX = new LinkedList<>();
for (Object o : nodes0) {
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
String l = (String) u.c;
nodesX.add(new Pair<>(n, l));
}
List<Pair<String, List<String>>> eqsX = new LinkedList<>();
for (Object o : arrows0) {
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
List<String> m = (List<String>) u.c;
eqsX.add(new Pair<>(n, m));
}
XMapConst ret = new XMapConst(toExp(y.c), toExp(y.e), nodesX, eqsX);
return ret;
}
Aggregations