use of catdata.Pair in project fql by CategoricalData.
the class OplParser method toTheory.
private static OplExp toTheory(Object o) {
Tuple5 t = (Tuple5) o;
List<String> imports = t.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) t.a).b;
Tuple3 a = (Tuple3) t.b;
Tuple3 b = (Tuple3) t.c;
Tuple3 c = (Tuple3) t.d;
Tuple3 d = (Tuple3) t.e;
Set<String> sorts = a == null ? new HashSet<>() : new HashSet<>((Collection<String>) a.b);
List<Tuple3> symbols0 = b == null ? new LinkedList<>() : (List<Tuple3>) b.b;
List<org.jparsec.functors.Pair> equations0 = c == null ? new LinkedList<>() : (List<org.jparsec.functors.Pair>) c.b;
List<org.jparsec.functors.Pair> implications0 = new LinkedList<>();
if (d != null) {
implications0 = (List<org.jparsec.functors.Pair>) d.b;
}
Map<String, Pair<List<String>, String>> symbols = new HashMap<>();
Map<String, Integer> prec = new HashMap<>();
for (Tuple3 x : symbols0) {
String dom;
List<String> args;
if (x.c instanceof Tuple3) {
Tuple3 zzz = (Tuple3) x.c;
args = (List<String>) zzz.a;
dom = (String) zzz.c;
} else {
dom = (String) x.c;
args = new LinkedList<>();
}
List<org.jparsec.functors.Pair> name0s = (List<org.jparsec.functors.Pair>) x.a;
for (org.jparsec.functors.Pair name0 : name0s) {
// org.jparsec.functors.Pair name0 =
// (org.jparsec.functors.Pair) x.a;
String name = (String) name0.a;
if (name0.b != null) {
org.jparsec.functors.Pair zzz = (org.jparsec.functors.Pair) name0.b;
Integer i = (Integer) zzz.b;
prec.put(name, i);
}
if (symbols.containsKey(name)) {
throw new DoNotIgnore("Duplicate symbol " + name);
}
symbols.put(name, new Pair<>(args, dom));
}
}
if (sorts.contains("Nat") && symbols.keySet().contains("zero") && symbols.keySet().contains("succ") && DefunctGlobalOptions.debug.opl.opl_desugar_nat) {
sugarForNat = true;
}
List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> equations = new LinkedList<>();
for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equations0) {
List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
OplCtx<String, String> ctx = toCtx(fa);
Tuple3 eq = x.b;
OplTerm lhs = toTerm(ctx.names(), consts(symbols), eq.a, false);
OplTerm rhs = toTerm(ctx.names(), consts(symbols), eq.c, false);
equations.add(new Triple<>(ctx, lhs, rhs));
}
List<Triple<OplCtx<String, String>, List<Pair<OplTerm<String, String>, OplTerm<String, String>>>, List<Pair<OplTerm<String, String>, OplTerm<String, String>>>>> implications = new LinkedList<>();
for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : implications0) {
List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
OplCtx<String, String> ctx = toCtx(fa);
Tuple3 eq = x.b;
List<Tuple3> lhs0 = (List<Tuple3>) eq.a;
List<Tuple3> rhs0 = (List<Tuple3>) eq.c;
List<Pair<OplTerm<String, String>, OplTerm<String, String>>> lhs = new LinkedList<>();
List<Pair<OplTerm<String, String>, OplTerm<String, String>>> rhs = new LinkedList<>();
for (Tuple3 obj : lhs0) {
OplTerm lhsX = toTerm(ctx.names(), consts(symbols), obj.a, false);
OplTerm rhsX = toTerm(ctx.names(), consts(symbols), obj.c, false);
lhs.add(new Pair<>(lhsX, rhsX));
}
for (Tuple3 obj : rhs0) {
OplTerm lhsX = toTerm(ctx.names(), consts(symbols), obj.a, false);
OplTerm rhsX = toTerm(ctx.names(), consts(symbols), obj.c, false);
rhs.add(new Pair<>(lhsX, rhsX));
}
implications.add(new Triple<>(ctx, lhs, rhs));
}
OplSig ret = new OplSig<>(new VIt(), prec, sorts, symbols, equations, implications);
ret.imports = new HashSet<>(imports);
return ret;
}
use of catdata.Pair in project fql by CategoricalData.
the class OplParser method fromBlocks2.
private static Map<Object, Pair<String, Block<String, String, String, String, String, String>>> fromBlocks2(List l) {
Map<Object, Pair<String, Block<String, String, String, String, String, String>>> ret = new HashMap<>();
for (Object o : l) {
Tuple4 t = (Tuple4) o;
Block<String, String, String, String, String, String> b = fromBlock2(t.d);
ret.put(t.c.toString(), new Pair<>(t.c.toString(), b));
}
return ret;
}
use of catdata.Pair in project fql by CategoricalData.
the class OplParser method fromAgg.
@SuppressWarnings("unused")
private static Agg<String, String, String, String, String, String> fromAgg(Collection vars, Collection consts, Object o, boolean suppressError) {
Tuple5<Tuple4<?, String, String, ?>, List<Tuple3<String, ?, String>>, List<Tuple3<?, ?, ?>>, org.jparsec.functors.Pair<?, ?>, ?> t = (Tuple5<Tuple4<?, String, String, ?>, List<Tuple3<String, ?, String>>, List<Tuple3<?, ?, ?>>, org.jparsec.functors.Pair<?, ?>, ?>) o;
LinkedHashMap<String, String> from = new LinkedHashMap<>();
Set<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new HashSet<>();
for (Object x : t.b) {
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());
}
Set<String> allVars = new HashSet<>();
allVars.addAll(vars);
allVars.addAll(from.keySet());
for (Object x : t.c) {
Tuple3 l = (Tuple3) x;
where.add(new Pair(toTerm(allVars, null, l.a, true), toTerm(allVars, null, l.c, true)));
}
OplTerm<String, String> att = toTerm(allVars, null, t.d.b, true);
return new Agg<>(t.a.b, t.a.c, from, where, att);
}
use of catdata.Pair 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 catdata.Pair 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;
}
Aggregations