use of catdata.fql.decl.MapExp in project fql by CategoricalData.
the class FQLParser method toMapConst.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static MapExp toMapConst(Object decl, SigExp t1, SigExp t2) {
Tuple3 x = (Tuple3) decl;
List<Pair<String, String>> objs = new LinkedList<>();
List<Pair<String, String>> attrs = new LinkedList<>();
List<Pair<String, List<String>>> arrows = new LinkedList<>();
Tuple3 a = (Tuple3) x.a;
Tuple3 b = (Tuple3) x.b;
Tuple3 c = (Tuple3) x.c;
List a0 = (List) a.b;
for (Object o : a0) {
Tuple3 z = (Tuple3) o;
String p = (String) z.a;
String q = (String) z.c;
objs.add(new Pair<>(p, q));
}
if (b.b.toString().equals("ASWRITTEN")) {
for (Pair<String, String> k : objs) {
attrs.add(new Pair<>(k.first + "_att", k.second + "_att"));
}
} else {
List b0 = (List) b.b;
for (Object o : b0) {
Tuple3 z = (Tuple3) o;
String p = (String) z.a;
String q = (String) z.c;
attrs.add(new Pair<>(p, q));
}
}
List c0 = (List) c.b;
for (Object o : c0) {
Tuple3 z = (Tuple3) o;
String p = (String) z.a;
List<String> q = (List<String>) z.c;
arrows.add(new Pair<>(p, q));
}
try {
MapExp.Const ret = new MapExp.Const(objs, attrs, arrows, t1, t2);
return ret;
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
}
use of catdata.fql.decl.MapExp in project fql by CategoricalData.
the class FQLParser method toMapping.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static MapExp toMapping(Object o) {
try {
Tuple3 p = (Tuple3) o;
Object p2 = p.b;
Object p3 = p.c;
Object o1 = p.a;
String p1 = p.a.toString();
if (p1.equals("fst")) {
return new Fst(toSchema(p2), toSchema(p3));
} else if (p1.equals("snd")) {
return new Snd(toSchema(p2), toSchema(p3));
} else if (p1.equals("unit")) {
return new TT(toSchema(p3), new HashSet<>((Collection<String>) p2));
} else if (p1.equals("subschema")) {
return new Sub(toSchema(p2), toSchema(p3));
} else if (p1.equals("inl")) {
return new Inl(toSchema(p2), toSchema(p3));
} else if (p1.equals("inr")) {
return new Inr(toSchema(p2), toSchema(p3));
} else if (p1.equals("iso1")) {
return new Iso(true, toSchema(p2), toSchema(p3));
} else if (p1.equals("iso2")) {
return new Iso(false, toSchema(p2), toSchema(p3));
} else if (p1.equals("eval")) {
return new Apply(toSchema(p2), toSchema(p3));
} else if (p2.toString().equals("then")) {
return new MapExp.Comp(toMapping(o1), toMapping(p3));
} else if (p2.toString().equals("*")) {
return new Prod(toMapping(o1), toMapping(p3));
} else if (p2.toString().equals("+")) {
return new Case(toMapping(o1), toMapping(p3));
}
} catch (RuntimeException re) {
}
if (o instanceof Tuple5) {
Tuple5 p = (Tuple5) o;
Object p2 = p.c;
Object p3 = p.e;
Object o1 = p.a;
return toMapConst(o1, toSchema(p2), toSchema(p3));
}
try {
org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
String p1 = p.a.toString();
Object p2 = p.b;
switch(p1) {
case "id":
return new Id(toSchema(p2));
case "curry":
return new Curry(toMapping(p2));
case "void":
return new FF(toSchema(p2));
case "opposite":
return new Opposite(toMapping(p2));
default:
break;
}
} catch (RuntimeException re) {
}
if (o instanceof String) {
return new MapExp.Var(o.toString());
}
throw new RuntimeException("Cannot parse " + o);
}
use of catdata.fql.decl.MapExp in project fql by CategoricalData.
the class FqlDisplay method handleInstanceFlowEdge.
private void handleInstanceFlowEdge(Object o) {
InstExp i = (InstExp) o;
Object f = i.accept(new Unit(), new InstExpVisitor<Object, Unit>() {
@Override
public MapExp visit(Unit env, Zero e) {
return null;
}
@Override
public MapExp visit(Unit env, One e) {
return null;
}
@Override
public MapExp visit(Unit env, Two e) {
throw new RuntimeException();
}
@Override
public MapExp visit(Unit env, Plus e) {
return null;
}
@Override
public MapExp visit(Unit env, Times e) {
return null;
}
@Override
public MapExp visit(Unit env, Exp e) {
throw new RuntimeException();
}
@Override
public MapExp visit(Unit env, Const e) {
return null;
}
@Override
public MapExp visit(Unit env, Delta e) {
return e.F;
}
@Override
public MapExp visit(Unit env, Sigma e) {
return e.F;
}
@Override
public MapExp visit(Unit env, Pi e) {
return e.F;
}
@Override
public MapExp visit(Unit env, FullSigma e) {
return e.F;
}
@Override
public Unit visit(Unit env, Relationalize e) {
return null;
}
@Override
public Unit visit(Unit env, External e) {
return null;
}
@Override
public Object visit(Unit env, Eval e) {
return e.q;
}
@Override
public Object visit(Unit env, FullEval e) {
return e.q;
}
@Override
public Object visit(Unit env, Kernel e) {
return null;
}
@Override
public Object visit(Unit env, Step e) {
// (Step) this should return a pair
return null;
}
});
if (f == null) {
return;
}
if (f instanceof QueryExp) {
QueryExp q = (QueryExp) f;
if (q instanceof QueryExp.Var) {
QueryExp.Var qq = (QueryExp.Var) q;
yyy.setSelectedValue(indices.get(qq.v), true);
return;
}
String k = FQLProgram.revLookup(prog.queries, q);
if (k != null) {
yyy.setSelectedValue(indices.get(k), true);
return;
}
String str = q.toString();
if (!extraInsts.contains(str)) {
Query view = q.toQuery(prog);
JPanel p = showQuery(prog, env, view);
x.add(p, str);
extraInsts.add(str);
}
yyy.clearSelection();
cl.show(x, str);
} else if (f instanceof FullQueryExp) {
FullQueryExp q = (FullQueryExp) f;
if (q instanceof FullQueryExp.Var) {
FullQueryExp.Var qq = (FullQueryExp.Var) q;
yyy.setSelectedValue(indices.get(qq.v), true);
return;
}
String k = FQLProgram.revLookup(prog.full_queries, q);
if (k != null) {
yyy.setSelectedValue(indices.get(k), true);
return;
}
String str = q.toString();
if (!extraInsts.contains(str)) {
FullQuery view = q.toFullQuery(prog);
JPanel p = showFullQuery(prog, env, view, q);
x.add(p, str);
extraInsts.add(str);
}
yyy.clearSelection();
cl.show(x, str);
} else if (f instanceof MapExp) {
MapExp q = (MapExp) f;
if (q instanceof MapExp.Var) {
MapExp.Var qq = (MapExp.Var) q;
yyy.setSelectedValue(indices.get(qq.v), true);
return;
}
String k = FQLProgram.revLookup(prog.maps, q);
if (k != null) {
yyy.setSelectedValue(indices.get(k), true);
return;
}
String str = q.toString();
if (!extraInsts.contains(str)) {
Mapping view = q.toMap(prog);
JPanel p = showMapping(env, prog.smap(view.source.toConst()), prog.smap(view.target.toConst()), view);
x.add(p, str);
extraInsts.add(str);
}
yyy.clearSelection();
cl.show(x, str);
} else {
throw new RuntimeException();
}
}
Aggregations