use of catdata.aql.exp.EdsExpRaw.EdExpRaw in project fql by CategoricalData.
the class CombinatorParser method edExpRaw.
private static Parser<EdExpRaw> edExpRaw() {
Parser<List<catdata.Pair<LocStr, String>>> as = Parsers.tuple(token("forall"), env(ident, ":")).map(x -> x.b).optional();
Parser<catdata.Pair<List<catdata.Pair<LocStr, String>>, Boolean>> es = Parsers.tuple(token("exists"), token("unique").optional(), env(ident, ":")).map(x -> new catdata.Pair<>(x.c, x.b != null)).optional();
Parser<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>> eq = Parsers.tuple(Parsers.INDEX, Parsers.tuple(term(), token("="), term()).map(x -> new catdata.Pair<>(x.a, x.c))).map(x -> new catdata.Pair<>(x.a, x.b));
Parser<List<catdata.Pair<Integer, catdata.Pair<RawTerm, RawTerm>>>> eqs = Parsers.tuple(token("where"), eq.many()).map(x -> x.b).optional();
Parser<EdExpRaw> ret = Parsers.tuple(as, eqs, token("->"), es, eqs).map(x -> new EdExpRaw(Util.newIfNull(x.a), Util.newIfNull(x.b), x.d == null ? new LinkedList<>() : x.d.first, Util.newIfNull(x.e), x.d == null ? false : x.d.second));
return ret;
}
use of catdata.aql.exp.EdsExpRaw.EdExpRaw in project fql by CategoricalData.
the class EasikAql method translate1.
private static Pair<SchExp<?, ?, ?, ?, ?>, List<Pair<String, EdsExpRaw>>> translate1(Node sketch, Set<String> used, Set<String> warnings, String sname) {
List<String> ens = new LinkedList<>();
List<Pair<String, Pair<String, Ty>>> atts = new LinkedList<>();
List<Pair<String, Pair<String, String>>> fks = new LinkedList<>();
List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
// there shouldn't be observation equations in easik
// List<Quad<String, String, RawTerm, RawTerm>> eqs2 = new
// LinkedList<>();
List<Pair<String, EdsExpRaw>> edsExps = new LinkedList<>();
NodeList l = sketch.getChildNodes();
for (int temp = 0; temp < l.getLength(); temp++) {
Node n = l.item(temp);
NodeList j = n.getChildNodes();
for (int temp2 = 0; temp2 < j.getLength(); temp2++) {
Node m = j.item(temp2);
if (m.getNodeName().equals("entity")) {
String nodeName = safe(m.getAttributes().getNamedItem("name").getTextContent());
ens.add(nodeName);
NodeList k = m.getChildNodes();
for (int temp3 = 0; temp3 < k.getLength(); temp3++) {
Node w = k.item(temp3);
if (w.getNodeName().equals("attribute")) {
String attName = safe(w.getAttributes().getNamedItem("name").getTextContent());
String tyName = w.getAttributes().getNamedItem("attributeTypeClass").getTextContent();
used.add(tyName);
atts.add(new Pair<>(nodeName + "_" + attName.replace(" ", "_"), new Pair<>(nodeName, new Ty(easikTypeToString(tyName)))));
}
}
} else if (m.getNodeName().equals("edge")) {
String ename = safe(m.getAttributes().getNamedItem("id").getTextContent());
String esrc = safe(m.getAttributes().getNamedItem("source").getTextContent());
fks.add(new Pair<>(ename, new Pair<>(esrc, safe(m.getAttributes().getNamedItem("target").getTextContent()))));
if (m.getAttributes().getNamedItem("type").getTextContent().equals("injective")) {
List<EdExpRaw> eds = new LinkedList<>();
List<Pair<String, String>> As = new LinkedList<>();
As.add(new Pair<>("x", esrc));
As.add(new Pair<>("y", esrc));
List<Pair<RawTerm, RawTerm>> Aeqs = new LinkedList<>();
Aeqs.add(new Pair<>(new RawTerm(ename, Util.singList(new RawTerm("x"))), new RawTerm(ename, Util.singList(new RawTerm("y")))));
List<Pair<String, String>> Es = new LinkedList<>();
List<Pair<RawTerm, RawTerm>> Eeqs = new LinkedList<>();
Eeqs.add(new Pair<>(new RawTerm("x"), new RawTerm("y")));
EdExpRaw ed = new EdExpRaw(As, Aeqs, Es, Eeqs, false, null);
eds.add(ed);
edsExps.add(new Pair<>("injective", new EdsExpRaw(new SchExpVar(sname), new LinkedList<>(), eds, null)));
}
if (m.getAttributes().getNamedItem("type").getTextContent().equals("partial")) {
warnings.add("Not exported - partial edges. Their AQL semantics is unclear");
}
} else if (m.getNodeName().equals("uniqueKey")) {
String esrc = safe(m.getAttributes().getNamedItem("noderef").getTextContent());
List<String> atts0 = new LinkedList<>();
for (int w = 0; w < m.getChildNodes().getLength(); w++) {
Node node = m.getChildNodes().item(w);
if (!node.getNodeName().equals("attref")) {
continue;
}
String att = safe(node.getAttributes().getNamedItem("name").getTextContent());
atts0.add(att);
}
List<EdExpRaw> eds = new LinkedList<>();
List<Pair<String, String>> As = new LinkedList<>();
As.add(new Pair<>("x", esrc));
As.add(new Pair<>("y", esrc));
List<Pair<RawTerm, RawTerm>> Aeqs = new LinkedList<>();
for (String att : atts0) {
Aeqs.add(new Pair<>(new RawTerm(esrc + "_" + att, Util.singList(new RawTerm("x"))), new RawTerm(esrc + "_" + att, Util.singList(new RawTerm("y")))));
}
List<Pair<String, String>> Es = new LinkedList<>();
List<Pair<RawTerm, RawTerm>> Eeqs = new LinkedList<>();
Eeqs.add(new Pair<>(new RawTerm("x"), new RawTerm("y")));
EdExpRaw ed = new EdExpRaw(As, Aeqs, Es, Eeqs, false, null);
eds.add(ed);
edsExps.add(new Pair<>("key", new EdsExpRaw(new SchExpVar(sname), new LinkedList<>(), eds, null)));
} else if (m.getNodeName().equals("commutativediagram")) {
NodeList k = m.getChildNodes();
Node w1 = null;
Node w2 = null;
for (int temp4 = 0; temp4 < k.getLength(); temp4++) {
Node wX = k.item(temp4);
if (wX.getNodeName().equals("path") && w1 == null) {
w1 = wX;
} else if (wX.getNodeName().equals("path") && w2 == null) {
w2 = wX;
}
}
if (w1 == null || w2 == null) {
throw new RuntimeException("Easik to AQL internal error");
}
String cod1 = safe(w1.getAttributes().getNamedItem("domain").getTextContent());
String cod2 = safe(w2.getAttributes().getNamedItem("domain").getTextContent());
List<String> lhs = new LinkedList<>();
List<String> rhs = new LinkedList<>();
lhs.add(cod1);
rhs.add(cod2);
NodeList lhsX = w1.getChildNodes();
for (int temp3 = 0; temp3 < lhsX.getLength(); temp3++) {
if (!lhsX.item(temp3).getNodeName().equals("edgeref")) {
continue;
}
String toAdd = safe(lhsX.item(temp3).getAttributes().getNamedItem("id").getTextContent());
lhs.add(toAdd);
}
NodeList rhsX = w2.getChildNodes();
for (int temp3 = 0; temp3 < rhsX.getLength(); temp3++) {
if (!rhsX.item(temp3).getNodeName().equals("edgeref")) {
continue;
}
String toAdd = safe(rhsX.item(temp3).getAttributes().getNamedItem("id").getTextContent());
rhs.add(toAdd);
}
eqs.add(new Pair<>(lhs, rhs));
}
}
}
SchExp<?, ?, ?, ?, ?> schExp = new SchExpRaw(new TyExpVar<>("sql"), new LinkedList<>(), ens, fks, eqs, atts, new LinkedList<>(), new LinkedList<>(), null);
return new Pair<>(schExp, edsExps);
}
use of catdata.aql.exp.EdsExpRaw.EdExpRaw in project fql by CategoricalData.
the class EasikAql method translateC.
private static List<Pair<String, EdsExpRaw>> translateC(Node sketch, Set<String> warnings, SchExp<?, ?, ?, ?, ?> schExp) {
List<Pair<String, EdsExpRaw>> edsExps = new LinkedList<>();
NodeList l = sketch.getChildNodes();
for (int temp = 0; temp < l.getLength(); temp++) {
Node n = l.item(temp);
NodeList j = n.getChildNodes();
for (int temp2 = 0; temp2 < j.getLength(); temp2++) {
Node m = j.item(temp2);
List<EdExpRaw> edExps = new LinkedList<>();
String name = null;
if (m.getNodeName().equals("sumconstraint")) {
warnings.add("sum constraints not exported - AQL does not currently support sum constraints");
continue;
} else if (m.getNodeName().equals("limitconstraint")) {
warnings.add("limit constraints not exported - if you see this, please report");
continue;
} else if (m.getNodeName().equals("pullbackconstraint")) {
name = "pullback";
Pair<List<String>, String> f1 = null, f2 = null, g1 = null, g2 = null;
for (int i = 0; i < m.getChildNodes().getLength(); i++) {
Node x = m.getChildNodes().item(i);
if (x.getNodeName().equals("path")) {
if (g1 == null) {
g1 = path(x);
} else if (g2 == null) {
g2 = path(x);
} else if (f1 == null) {
f1 = path(x);
} else if (f2 == null) {
f2 = path(x);
}
}
}
if (f1 == null || g1 == null || f2 == null || g2 == null) {
throw new RuntimeException("Anomaly - please report");
}
String A = f1.first.get(0);
String B = f1.second;
String C = g1.second;
f1.first.remove(0);
g1.first.remove(0);
g2.first.remove(0);
f2.first.remove(0);
List<Pair<String, String>> as = new LinkedList<>();
as.add(new Pair<>("b", B));
as.add(new Pair<>("c", C));
List<Pair<RawTerm, RawTerm>> a_eqs = new LinkedList<>();
a_eqs.add(new Pair<>(toTerm(f2.first, "b"), toTerm(g2.first, "c")));
List<Pair<String, String>> es = new LinkedList<>();
es.add(new Pair<>("a", A));
List<Pair<RawTerm, RawTerm>> e_eqs = new LinkedList<>();
e_eqs.add(new Pair<>(toTerm(f1.first, "a"), new RawTerm("b")));
e_eqs.add(new Pair<>(toTerm(g1.first, "a"), new RawTerm("c")));
EdExpRaw ed1 = new EdExpRaw(as, a_eqs, es, e_eqs, true, null);
edExps.add(ed1);
/*
as = new LinkedList<>();
as.add(new Pair<>("a1", A));
as.add(new Pair<>("a2", A));
a_eqs = new LinkedList<>();
a_eqs.add(new Pair<>(toTerm(f1.first, "a1"),toTerm(f1.first, "a2")));
a_eqs.add(new Pair<>(toTerm(g1.first, "a1"),toTerm(g1.first, "a2")));
es = new LinkedList<>();
e_eqs = new LinkedList<>();
e_eqs.add(new Pair<>(new RawTerm("a1"),new RawTerm("a2")));
EdExpRaw ed2 = new EdExpRaw(as, a_eqs, es, e_eqs);
edExps.add(ed2);
*/
} else if (m.getNodeName().equals("productconstraint")) {
name = "product";
Pair<List<String>, String> f = null, g = null;
for (int i = 0; i < m.getChildNodes().getLength(); i++) {
Node x = m.getChildNodes().item(i);
if (x.getNodeName().equals("path")) {
if (f == null) {
f = path(x);
} else if (g == null) {
g = path(x);
}
}
}
if (f == null || g == null) {
throw new RuntimeException("Anomaly - please report");
}
String A = f.first.get(0);
String B = f.second;
String C = g.second;
f.first.remove(0);
g.first.remove(0);
List<Pair<String, String>> as = new LinkedList<>();
as.add(new Pair<>("b", B));
as.add(new Pair<>("c", C));
List<Pair<RawTerm, RawTerm>> a_eqs = new LinkedList<>();
List<Pair<String, String>> es = new LinkedList<>();
es.add(new Pair<>("a", A));
List<Pair<RawTerm, RawTerm>> e_eqs = new LinkedList<>();
e_eqs.add(new Pair<>(toTerm(f.first, "a"), new RawTerm("b")));
e_eqs.add(new Pair<>(toTerm(g.first, "a"), new RawTerm("c")));
EdExpRaw ed1 = new EdExpRaw(as, a_eqs, es, e_eqs, true, null);
edExps.add(ed1);
} else if (m.getNodeName().equals("equalizerconstraint")) {
List<String> h = null, f = null, g = null;
for (int i = 0; i < m.getChildNodes().getLength(); i++) {
Node x = m.getChildNodes().item(i);
if (x.getNodeName().equals("path")) {
if (h == null) {
h = path(x).first;
} else if (f == null) {
f = path(x).first;
} else if (g == null) {
g = path(x).first;
}
}
}
if (h == null || f == null || g == null) {
throw new RuntimeException("Anomaly - please report");
}
String B = f.get(0);
String A = h.get(0);
h.remove(0);
f.remove(0);
g.remove(0);
List<Pair<String, String>> as = new LinkedList<>();
as.add(new Pair<>("b", B));
List<Pair<RawTerm, RawTerm>> a_eqs = new LinkedList<>();
a_eqs.add(new Pair<>(toTerm(f, "b"), toTerm(g, "b")));
List<Pair<String, String>> es = new LinkedList<>();
es.add(new Pair<>("a", A));
List<Pair<RawTerm, RawTerm>> e_eqs = new LinkedList<>();
e_eqs.add(new Pair<>(toTerm(h, "a"), new RawTerm("b")));
EdExpRaw ed1 = new EdExpRaw(as, a_eqs, es, e_eqs, true, null);
edExps.add(ed1);
name = "equalizer";
} else {
continue;
}
EdsExpRaw edsExp = new EdsExpRaw(schExp, new LinkedList<>(), edExps, null);
edsExps.add(new Pair<>(name, edsExp));
}
}
return edsExps;
}
Aggregations