use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class XParser method fromBlock.
private static Block<String, String> fromBlock(Object o) {
Tuple4<List, List, List, List> t = (Tuple4<List, List, List, List>) o;
Map<Object, String> from = new HashMap<>();
Set<Pair<List<Object>, List<Object>>> where = new HashSet<>();
Map<String, List<Object>> attrs = new HashMap<>();
Map<String, Pair<Object, Map<Object, List<Object>>>> 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(l.a, l.c));
}
for (Object x : t.c) {
Tuple3 l = (Tuple3) x;
if (attrs.containsKey(l.a.toString())) {
throw new RuntimeException("Duplicate for: " + l.a);
}
attrs.put(l.a.toString(), (List<Object>) l.c);
}
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(l.c)));
}
return new Block<>(from, where, attrs, edges);
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class XParser method toWhere.
private static XBool toWhere(Object o) {
if (o instanceof Tuple5) {
Tuple5 o2 = (Tuple5) o;
boolean isAnd = o2.c.toString().equals("and");
return new XBool(toWhere(o2.b), toWhere(o2.d), isAnd);
}
if (o instanceof Tuple3) {
Tuple3 o2 = (Tuple3) o;
return new XBool((List<Object>) o2.a, (List<Object>) o2.c);
}
if (o instanceof org.jparsec.functors.Pair) {
org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) o;
return new XBool(toWhere(x.b));
}
if (o.toString().equals("true")) {
return new XBool(true);
}
if (o.toString().equals("false")) {
return new XBool(false);
}
throw new RuntimeException();
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class XParser method fromBulb.
private static Triple<String, List<List<String>>, List<String>> fromBulb(Object o) {
try {
Tuple3 t = (Tuple3) o;
Tuple3 a = (Tuple3) t.a;
Tuple3 b = (Tuple3) a.c;
return new Triple<>((String) a.b, (List<List<String>>) b.b, (List<String>) t.c);
} catch (Exception ee) {
}
try {
Tuple3 a = (Tuple3) o;
Tuple3 b = (Tuple3) a.c;
return new Triple<>((String) a.b, (List<List<String>>) b.b, null);
} catch (Exception ee) {
}
return new Triple<>(null, null, (List<String>) o);
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class XParser method fromSoed.
/*
J = soed {
exists f:A->B, g:C->D;
forall a:A, a.f = p.q, a.g = p.f;
forall b:B, p = q;
} : X -> Y on I
*/
private static XSOED fromSoed(Object ooo) {
org.jparsec.functors.Pair ooo1 = (org.jparsec.functors.Pair) ooo;
Tuple4 a = (Tuple4) ooo1.a;
List<Triple<String, String, String>> es = new LinkedList<>();
List<FOED> as = new LinkedList<>();
List<Tuple5> es0 = (List<Tuple5>) a.b;
for (Tuple5 t : es0) {
es.add(new Triple(t.a, t.c, t.e));
}
List<Tuple4> as0 = (List<Tuple4>) a.d;
for (Tuple4 t : as0) {
List<Tuple3> eqs = (List<Tuple3>) t.d;
List<Pair<List<String>, List<String>>> eqs0 = new LinkedList<>();
for (Tuple3 x : eqs) {
eqs0.add(new Pair(x.a, x.c));
}
as.add(new FOED((String) t.b, (String) t.c, eqs0));
}
Tuple4 b = (Tuple4) ooo1.b;
String src = (String) b.b;
String dst = (String) b.c;
String i = (String) b.d;
XSOED ret = new XSOED(es, as, src, dst, i);
return ret;
}
use of org.jparsec.functors.Tuple3 in project fql by CategoricalData.
the class XParser method path.
/*
// @SuppressWarnings("rawtypes")
public static FunctorExp toInstConst(Object decl) {
Tuple3 y = (Tuple3) 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;
Map<String, SetExp> nodesX = new HashMap<>();
for (Object o : nodes0) {
if (nodesX.containsKey(o)) {
throw new RuntimeException("Duplicate object: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
SetExp l = toSet(u.c);
nodesX.put(n, l);
}
Map<String, Chc<FnExp,SetExp>> arrowsX = new HashMap<>();
for (Object o : arrows0) {
if (arrowsX.containsKey(o)) {
throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
try {
FnExp l = toFn(u.c);
arrowsX.put(n, Chc.inLeft(l));
} catch (Exception eee) {
SetExp l = toSet(u.c);
arrowsX.put(n, Chc.inRight(l));
}
}
InstConst ret = new InstConst(toCat(y.c), nodesX, arrowsX);
return ret;
}
*/
/*
public static FunctorExp toCatFtrConst(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;
Map<String, CatExp> nodesX = new HashMap<>();
for (Object o : nodes0) {
if (nodesX.containsKey(o)) {
throw new RuntimeException("Duplicate object: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
CatExp l = toCat(u.c);
nodesX.put(n, l);
}
Map<String, FunctorExp> arrowsX = new HashMap<>();
for (Object o : arrows0) {
if (arrowsX.containsKey(o)) {
throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
FunctorExp l = toFtr(u.c);
arrowsX.put(n, l);
}
CatConst ret = new CatConst(toCat(y.c), nodesX, arrowsX);
return ret;
}
*/
/*public static FunctorExp toMapConst(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;
Map<String, String> nodesX = new HashMap<>();
for (Object o : nodes0) {
if (nodesX.containsKey(o)) {
throw new RuntimeException("Duplicate object: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
String l = u.c.toString();
nodesX.put(n, l);
}
Map<String, Pair<String, List<String>>> arrowsX = new HashMap<>();
for (Object o : arrows0) {
if (arrowsX.containsKey(o)) {
throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
}
Tuple3 u = (Tuple3) o;
String n = (String) u.a;
List<String> l = (List<String>) u.c;
String ll = l.remove(0);
arrowsX.put(n, new Pair<>(ll, l));
}
MapConst ret = new MapConst(toCat(y.c), toCat(y.e), nodesX, arrowsX);
return ret;
} */
public static List path(String s) {
Parser p = Parsers.or(StringLiteral.PARSER, IntegerLiteral.PARSER, Identifier.PARSER);
Parser e = Parsers.tuple(p, term(","), p);
Parser q = Parsers.between(term("("), e, term(")"));
Parser a = Parsers.or(q, p).sepBy1(term("."));
List l = (List) a.from(TOKENIZER, IGNORED).parse(s);
List ret = new LinkedList();
for (Object o : l) {
if (o instanceof Tuple3) {
Tuple3 z = (Tuple3) o;
ret.add(new Pair(z.a, z.c));
} else {
ret.add(o);
}
}
return ret;
}
Aggregations