use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method fromBlock.
private static Block<String, String, String, String, String, String> fromBlock(Object o) {
Tuple4<List, List, List, List> t = (Tuple4<List, List, List, List>) o;
LinkedHashMap<String, String> from = new LinkedHashMap<>();
Set<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new HashSet<>();
Map<String, Chc<Agg<String, String, String, String, String, String>, OplTerm<String, String>>> attrs = new HashMap<>();
Map<String, Pair<Object, Map<String, OplTerm<String, String>>>> edges = new HashMap<>();
for (Object x : t.a) {
Tuple3 l = (Tuple3) x;
if (from.containsKey(l.a.toString())) {
throw new RuntimeException("Duplicate for: " + l.a);
}
from.put(l.a.toString(), l.c.toString());
}
for (Object x : t.b) {
Tuple3 l = (Tuple3) x;
where.add(new Pair(toTerm(from.keySet(), null, l.a, true), toTerm(from.keySet(), null, l.c, true)));
}
for (Object x : t.c) {
Tuple3 l = (Tuple3) x;
if (attrs.containsKey(l.a.toString())) {
throw new RuntimeException("Duplicate for: " + l.a);
}
if (l.c.toString().contains("agg") && l.c.toString().contains("{") && l.c.toString().contains("return") && l.c.toString().contains("}")) {
attrs.put(l.a.toString(), Chc.inLeft(fromAgg(from.keySet(), null, l.c, true)));
} else {
attrs.put(l.a.toString(), Chc.inRight(toTerm(from.keySet(), null, l.c, true)));
}
}
for (Object x : t.d) {
Tuple5 l = (Tuple5) x;
if (from.containsKey(l.a.toString())) {
throw new RuntimeException("Duplicate for: " + l.a);
}
edges.put(l.a.toString(), new Pair(l.e.toString(), fromBlockHelper(from.keySet(), l.c)));
}
Block bl = new Block<>(from, where, attrs, edges);
return bl;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method toCatConst.
public static XSchema toCatConst(Object y) {
List<String> nodes = new LinkedList<>();
List<Triple<String, String, String>> arrows = new LinkedList<>();
List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
Tuple3 s = (Tuple3) y;
Tuple3 nodes0 = (Tuple3) s.a;
Tuple3 arrows0 = (Tuple3) s.b;
Tuple3 eqs0 = (Tuple3) s.c;
List nodes1 = (List) nodes0.b;
List arrows1 = (List) arrows0.b;
List eqs1 = (List) eqs0.b;
for (Object o : nodes1) {
nodes.add((String) o);
}
for (Object o : arrows1) {
Tuple5 x = (Tuple5) o;
arrows.add(new Triple<>((String) x.a, (String) x.c, (String) x.e));
}
for (Object o : eqs1) {
Tuple3 x = (Tuple3) o;
List<String> l1 = (List<String>) x.a;
List<String> l2 = (List<String>) x.c;
eqs.add(new Pair<>(l1, l2));
}
XSchema c = new XSchema(nodes, arrows, eqs);
return c;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method toJava.
private static OplExp toJava(Object x) {
Tuple3 t = (Tuple3) x;
Tuple3 b = (Tuple3) t.b;
List<Tuple3> l = (List<Tuple3>) b.b;
Map<String, String> defs = new HashMap<>();
for (Tuple3 k : l) {
String f = (String) k.a;
String body = (String) k.c;
if (defs.containsKey(f)) {
throw new DoNotIgnore("Duplicate symbol: " + f);
}
defs.put(f, body);
}
org.jparsec.functors.Pair c = (org.jparsec.functors.Pair) t.c;
return new OplJavaInst(defs, (String) c.b);
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class OplParser method toFlower.
private static OplFlower toFlower(Object c) {
Tuple3 p = (Tuple3) c;
// if (p.a.toString().equals("flower")) {
String I = (String) p.c;
Tuple3 q = (Tuple3) p.b;
// list of tuple3 of (path, string)
List s = (List) ((org.jparsec.functors.Pair) q.a).b;
// list of tuple3 of (string, string)
List f = (List) ((org.jparsec.functors.Pair) q.b).b;
// list of tuple3 of (path, path)
List w = (List) ((org.jparsec.functors.Pair) q.c).b;
Map<String, OplTerm<String, String>> select = new HashMap<>();
Map<String, String> from = new HashMap<>();
List<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new LinkedList<>();
Set<String> seen = new HashSet<>();
for (Object o : f) {
Tuple3 t = (Tuple3) o;
String lhs = t.a.toString();
String rhs = t.c.toString();
if (seen.contains(rhs)) {
throw new DoNotIgnore("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
}
seen.add(rhs);
from.put(rhs, lhs);
}
for (Object o : w) {
Tuple3 t = (Tuple3) o;
OplTerm lhs = toTerm(from.keySet(), null, t.a, false);
OplTerm rhs = toTerm(from.keySet(), null, t.c, false);
where.add(new Pair<>(rhs, lhs));
}
for (Object o : s) {
Tuple3 t = (Tuple3) o;
OplTerm lhs = toTerm(from.keySet(), null, t.a, false);
String rhs = t.c.toString();
if (seen.contains(rhs)) {
throw new DoNotIgnore("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
}
seen.add(rhs);
select.put(rhs, lhs);
}
return new OplFlower<>(select, from, where, I);
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class MplParser method toExp.
private static MplExp<String, String> toExp(Object o) {
if (o instanceof String) {
return new MplVar<>((String) o);
}
if (o instanceof Tuple3) {
Tuple3 t = (Tuple3) o;
return new MplEval<>((String) t.b, toTerm(t.c));
}
if (o instanceof org.jparsec.functors.Pair) {
org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
if (p.a.toString().equals("theory")) {
return toTheory(p.b);
}
MplEval<String, String> ret = new MplEval<>((String) p.a, toTerm(p.b));
return ret;
}
throw new RuntimeException();
// }
// return toTheory(o);
}
Aggregations