use of catdata.fql.decl.InstExp.FullSigma in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String env, Return e) {
// String xxx = "return_temp_xxx";
List<PSM> ret = new LinkedList<>();
InstExp i1 = prog.insts.get(e.inst);
if (i1 instanceof Delta) {
String middle = ((Delta) i1).I;
// can't be null
InstExp i2 = prog.insts.get(middle);
Mapping f = ((Delta) i1).F.toMap(prog);
if (i2 instanceof Sigma) {
Sigma input0 = ((Sigma) i2);
String input = input0.I;
for (Node n : f.source.nodes) {
ret.add(new InsertSQL(env + "_" + n.string, PSMGen.compose(input + "_" + n.string, middle + "_" + f.nm.get(n) + "_subst", e.inst + "_" + n.string + "_subst"), "c0", "c1"));
}
} else if (i2 instanceof FullSigma) {
FullSigma input0 = ((FullSigma) i2);
String input = input0.I;
for (Node n : f.source.nodes) {
ret.add(new InsertSQL(env + "_" + n.string, PSMGen.compose(input + "_" + n.string, middle + "_" + n.string + "_e", e.inst + "_" + n.string + "_subst"), "c0", "c1"));
}
} else {
throw new RuntimeException();
}
} else if (i1 instanceof Pi) {
String middle = ((Pi) i1).I;
// can't be null
InstExp i2 = prog.insts.get(middle);
Mapping f = ((Pi) i1).F.toMap(prog);
if (i2 instanceof Delta) {
Delta input0 = ((Delta) i2);
String input = input0.I;
for (Node n : f.target.nodes) {
try {
Map<String, Triple<Node, Node, Arr<Node, Path>>[]> colmap = PSMGen.pi(f, middle, e.inst).second;
Triple<Node, Node, Arr<Node, Path>>[] col = colmap.get(n.string);
if (col.length == 0) {
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
Map<String, String> from = new HashMap<>();
List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
from.put("lim", e.inst + "_" + n.string + "_limit");
from.put("middle", input + "_" + n.string);
select.put("c0", new Pair<>("middle", "c0"));
select.put("c1", new Pair<>("lim", "guid"));
Flower flower = new Flower(select, from, where);
ret.add(new InsertSQL(env + "_" + n.string, flower, "c0", "c1"));
return ret;
}
// LinkedHashMap<String, String> attrs = new LinkedHashMap<>();
// attrs.put("guid", PSM.VARCHAR());
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
Map<String, String> from = new HashMap<>();
from.put("lim", e.inst + "_" + n.string + "_limit");
List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
int i = 0;
for (Triple<Node, Node, Arr<Node, Path>> col0 : col) {
from.put("c" + i + "_subst_inv", middle + "_" + col0.second.string + "_subst_inv");
where.add(new Pair<>(new Pair<>("lim", "c" + i), new Pair<>("c" + i + "_subst_inv", "c0")));
// attrs.put("c" + i, PSM.VARCHAR());
i++;
}
// if (col.length > 1) {
for (int j = 0; j < col.length; j++) {
if (col[j].third.arr.equals(f.target.toCategory2().second.of(new Path(f.target, n)).arr)) {
where.add(new Pair<>(new Pair<>("c" + 0 + "_subst_inv", "c1"), new Pair<>("c" + j + "_subst_inv", "c1")));
}
}
select.put("c" + 0, new Pair<>("c" + 0 + "_subst_inv", "c1"));
select.put("c1", new Pair<>("lim", "guid"));
// }
// ret.add(new CreateTable(xxx, attrs, false));
Flower flower = new Flower(select, from, where);
ret.add(new InsertSQL(env + "_" + n.string, flower, "c0", "c1"));
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
}
} else {
throw new RuntimeException();
}
} else {
throw new RuntimeException();
}
return ret;
}
use of catdata.fql.decl.InstExp.FullSigma in project fql by CategoricalData.
the class Driver method validateWithEds.
private static void validateWithEds(FQLProgram prog, Map<String, Instance> insts) throws FQLException {
for (String k : prog.insts.keySet()) {
InstExp v = prog.insts.get(k);
if (v instanceof FullSigma) {
FullSigma v0 = (FullSigma) v;
Instance x = Chase.sigma(v0.F.toMap(prog), insts.get(v0.I));
if (!Instance.quickCompare(x, insts.get(k))) {
throw new RuntimeException("Bad sigma ED compare: ED gives\n\n" + x + "\n\nbut SIGMA gives\n\n" + insts.get(k));
}
}
if (v instanceof InstExp.Sigma) {
InstExp.Sigma v0 = (InstExp.Sigma) v;
Instance x = Chase.sigma(v0.F.toMap(prog), insts.get(v0.I));
if (!Instance.quickCompare(x, insts.get(k))) {
throw new RuntimeException("Bad sigma ED compare: ED gives\n\n" + x + "\n\nbut SIGMA gives\n\n" + insts.get(k));
}
}
if (v instanceof InstExp.Delta) {
InstExp.Delta v0 = (InstExp.Delta) v;
Instance x = Chase.delta(v0.F.toMap(prog), insts.get(v0.I));
if (!Instance.quickCompare(x, insts.get(k))) {
throw new RuntimeException("Bad sigma ED compare: ED gives\n\n" + x + "\n\nbut SIGMA gives\n\n" + insts.get(k));
}
}
}
}
use of catdata.fql.decl.InstExp.FullSigma 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();
}
}
use of catdata.fql.decl.InstExp.FullSigma in project fql by CategoricalData.
the class FQLParser method toInst.
@SuppressWarnings("rawtypes")
private static InstExp toInst(Object o) {
try {
Tuple4 t = (Tuple4) o;
Token z = (Token) t.a;
String y = z.toString();
if (y.equals("step")) {
return new Step(t.d.toString(), toMapping(t.b), toMapping(t.c));
}
} catch (RuntimeException cce) {
}
try {
Tuple3 t = (Tuple3) o;
Token z = (Token) t.a;
String y = z.toString();
switch(y) {
case "delta":
return new InstExp.Delta(toMapping(t.b), t.c.toString());
case "sigma":
return new InstExp.Sigma(toMapping(t.b), t.c.toString());
case "SIGMA":
return new FullSigma(toMapping(t.b), t.c.toString());
case "pi":
return new InstExp.Pi(toMapping(t.b), t.c.toString());
case "external":
return new External(toSchema(t.b), t.c.toString());
case "eval":
return new Eval(toQuery(t.b), t.c.toString());
case "EVAL":
return new FullEval(toFullQuery(t.b), t.c.toString());
default:
break;
}
} catch (RuntimeException cce) {
}
try {
Tuple3 t = (Tuple3) o;
Token z = (Token) t.b;
String y = z.toString();
if (y.equals("+")) {
return new Plus(t.a.toString(), t.c.toString());
} else if (y.equals("*")) {
return new Times(t.a.toString(), t.c.toString());
}
if (y.equals("^")) {
return new Exp(t.a.toString(), (t.c).toString());
}
} catch (RuntimeException cce) {
}
try {
org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) o;
if (pr.a.toString().equals("unit")) {
return new One(toSchema(pr.b));
} else if (pr.a.toString().equals("void")) {
return new Zero(toSchema(pr.b));
} else if (pr.a.toString().equals("prop")) {
return new Two(toSchema(pr.b));
} else if (pr.a.toString().equals("relationalize")) {
return new Relationalize(pr.b.toString());
} else if (pr.a.toString().equals("kernel")) {
return new Kernel(pr.b.toString());
}
throw new RuntimeException();
} catch (RuntimeException cce) {
}
return toInstConst(o);
}
use of catdata.fql.decl.InstExp.FullSigma in project fql by CategoricalData.
the class InstOps method visit.
@Override
public List<PSM> visit(String env, Coreturn e) {
String xxx = "coreturn_temp_xxx";
List<PSM> ret = new LinkedList<>();
InstExp i1 = prog.insts.get(e.inst);
if (i1 instanceof Sigma) {
String middle = ((Sigma) i1).I;
// can't be null
InstExp i2 = prog.insts.get(middle);
Mapping f = ((Sigma) i1).F.toMap(prog);
if (i2 instanceof Delta) {
for (Node n : f.target.nodes) {
List<Flower> u = new LinkedList<>();
for (Node m : f.source.nodes) {
if (!f.nm.get(m).equals(n)) {
continue;
}
u.add(new CopyFlower(middle + "_" + m.string + "_subst_inv", "c0", "c1"));
}
ret.add(new SimpleCreateTable(xxx, PSM.VARCHAR(), false));
ret.add(new InsertSQL(xxx, new Union(u), "c0", "c1"));
ret.add(new InsertSQL(env + "_" + n.string, PSMGen.compose(e.inst + "_" + n.string + "_subst_inv", xxx), "c0", "c1"));
ret.add(new DropTable(xxx));
}
}
} else if (i1 instanceof FullSigma) {
String middle = ((FullSigma) i1).I;
// can't be null
InstExp i2 = prog.insts.get(middle);
Mapping f = ((FullSigma) i1).F.toMap(prog);
if (i2 instanceof Delta) {
ret.add(new FullSigmaCounit(f, ((Delta) i2).I, middle, e.inst, env));
} else {
throw new RuntimeException();
}
} else if (i1 instanceof Delta) {
String middle = ((Delta) i1).I;
// can't be null
InstExp i2 = prog.insts.get(middle);
Mapping f = ((Delta) i1).F.toMap(prog);
if (i2 instanceof Pi) {
Pi input0 = ((Pi) i2);
String input = input0.I;
try {
Map<String, Triple<Node, Node, Arr<Node, Path>>[]> colmap = PSMGen.pi(f, input, middle).second;
for (Node m : f.source.nodes) {
Node n = f.nm.get(m);
Triple<Node, Node, Arr<Node, Path>>[] col = colmap.get(n.string);
Triple<Node, Node, Arr<Node, Path>> toFind = new Triple<>(n, m, new Arr<>(new Path(f.target, n), n, n));
int i = 0;
boolean found = false;
for (Triple<Node, Node, Arr<Node, Path>> cand : col) {
if (cand.equals(toFind)) {
found = true;
Map<String, String> from = new HashMap<>();
from.put("lim", middle + "_" + n + "_limit");
LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
select.put("c0", new Pair<>("lim", "guid"));
select.put("c1", new Pair<>("lim", "c" + i));
List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
Flower flower = new Flower(select, from, where);
ret.add(new SimpleCreateTable(xxx, PSM.VARCHAR(), false));
ret.add(new InsertSQL(xxx, flower, "c0", "c1"));
ret.add(new InsertSQL(env + "_" + m, PSMGen.compose(e.inst + "_" + m + "_subst_inv", xxx), "c0", "c1"));
ret.add(new DropTable(xxx));
break;
}
i++;
}
if (!found) {
throw new RuntimeException();
}
}
} catch (FQLException fe) {
fe.printStackTrace();
throw new RuntimeException(fe.getMessage());
}
} else {
throw new RuntimeException();
}
} else {
throw new RuntimeException();
}
return ret;
}
Aggregations