use of catdata.Pair 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 catdata.Pair in project fql by CategoricalData.
the class OplToKB method nice.
@SuppressWarnings({ "rawtypes", "unchecked" })
private Pair<OplCtx<S, V>, OplTerm<C, V>> nice(OplCtx<S, V> G, OplTerm<C, V> e) {
int i = 0;
Map m = new HashMap();
List<Pair> l = new LinkedList<>();
for (V v : G.names()) {
l.add(new Pair("v" + i, G.get(v)));
m.put(v, new OplTerm("v" + i++));
}
OplCtx ret = new OplCtx(l);
return new Pair(ret, e.subst(m));
}
use of catdata.Pair in project fql by CategoricalData.
the class OplWarehouse method addBlanks.
// TODO aql alphabetize tabs
// TODO aql heuristic: if something already there, leave it. otherwise, create new
private void addBlanks() {
switch(state) {
case INITIAL:
if (!bindings.containsKey(THEORY)) {
bindings.put(THEORY, new OplSig<>(new VIt(), new HashMap<>(), new HashSet<>(), new HashMap<>(), new LinkedList<>()));
}
break;
case THEORY:
if (!bindings.containsKey(SHAPE)) {
bindings.put(SHAPE, new OplGraph<String, String>(new HashSet<>(), new HashMap<>()));
}
break;
case SHAPE:
{
OplGraph<String, String> shape = (OplGraph<String, String>) bindings.get(SHAPE);
for (String en : shape.nodes) {
if (bindings.containsKey(SCHEMA + "_" + en)) {
// TODO: aql false
continue;
}
bindings.put(SCHEMA + "_" + en, new OplSCHEMA0<String, String, String>(new HashMap<>(), new HashSet<>(), new HashMap<>(), new HashMap<>(), new LinkedList<>(), new LinkedList<>(), THEORY));
}
break;
}
case SCHEMA:
{
OplGraph<String, String> shape = (OplGraph<String, String>) bindings.get(SHAPE);
for (String ed : shape.edges.keySet()) {
if (bindings.containsKey(MAPPING + "_" + ed)) {
continue;
}
String src = SCHEMA + "_" + shape.edges.get(ed).first;
// String dst = SCHEMA + "_" + shape.edges.get(ed).second;
OplSCHEMA0<String, String, String> src0 = (OplSCHEMA0<String, String, String>) bindings.get(src);
Map<String, String> sorts = new HashMap<>();
for (String x : src0.entities) {
sorts.put(x, "?");
}
Map<String, Pair<OplCtx<String, String>, OplTerm<String, String>>> symbols = new HashMap<>();
for (String g : src0.attrs.keySet()) {
OplCtx<String, String> ctx = new OplCtx<>(Util.singList(new Pair<>("x", "?")));
OplTerm<String, String> term = new OplTerm<>("?");
symbols.put(g, new Pair<>(ctx, term));
}
for (String g : src0.edges.keySet()) {
OplCtx<String, String> ctx = new OplCtx<>(Util.singList(new Pair<>("t", "?")));
OplTerm<String, String> term = new OplTerm<>("?");
symbols.put(g, new Pair<>(ctx, term));
}
bindings.put(MAPPING + "_" + ed, new OplMapping<>(sorts, symbols, src, SCHEMA + "_" + shape.edges.get(ed).second));
}
break;
}
case MAPPING:
{
OplGraph<String, String> shape = (OplGraph<String, String>) bindings.get(SHAPE);
Set<String> en2 = shape.nodes.stream().map(x -> SCHEMA + "_" + x).collect(Collectors.toSet());
Map<String, Pair<String, String>> ed2 = new HashMap<>();
for (String e : shape.edges.keySet()) {
Pair<String, String> x = shape.edges.get(e);
String l = SCHEMA + "_" + x.first;
ed2.put(MAPPING + "_" + e, new Pair<>(l, SCHEMA + "_" + x.second));
}
OplGraph<String, String> shape2 = new OplGraph<>(en2, ed2);
// TODO: aql needs to compile to here
computeColimit(bindings, shape2, THEORY);
for (String en : shape.nodes) {
if (bindings.containsKey(INSTANCE + "_" + en)) {
// TODO aql false
continue;
}
bindings.put(INSTANCE + "_" + en, new OplInst0<>(new OplPres<>(new HashMap<>(), SCHEMA + "_" + en, null, new HashMap<>(), new LinkedList<>())));
}
break;
}
case INSTANCE:
{
OplGraph<String, String> shape = (OplGraph<String, String>) bindings.get(SHAPE);
for (String ed : shape.edges.keySet()) {
String en = shape.edges.get(ed).first;
String en2 = shape.edges.get(ed).second;
String src = INSTANCE + "_" + ed + "_forward";
bindings.put(src, new OplSigma(MAPPING + "_" + ed, INSTANCE + "_" + en));
if (bindings.containsKey(TRANSFORM + "_" + ed + "_forward")) {
continue;
}
OplMapping<String, String, String, String, String> mmm = (OplMapping<String, String, String, String, String>) bindings.get(MAPPING + "_" + ed);
// TODO: aql factor getting into separate method, or use compiler
OplInst0<String, String, String, String> src1 = (OplInst0<String, String, String, String>) bindings.get(INSTANCE + "_" + en);
OplInst0<String, String, String, String> src0 = (OplInst0<String, String, String, String>) bindings.get(INSTANCE + "_" + en2);
OplSCHEMA0<String, String, String> src0_sch = (OplSCHEMA0<String, String, String>) bindings.get(src0.P.S);
OplSCHEMA0<String, String, String> src1_sch = (OplSCHEMA0<String, String, String>) bindings.get(src1.P.S);
Map<String, Map<String, OplTerm<Object, String>>> sorts = new HashMap<>();
for (String x : src0_sch.entities) {
sorts.put(x, new HashMap<>());
}
for (String g : src1.P.gens.keySet()) {
String gty = src1.P.gens.get(g);
String s2 = mmm.sorts.get(gty);
if (s2 == null) {
continue;
}
Map<String, OplTerm<Object, String>> symbols = sorts.get(s2);
if (symbols != null) {
symbols.put(g, new OplTerm<>("?"));
}
}
bindings.put(TRANSFORM + "_" + ed + "_forward", new OplPresTrans<String, String, String, String, String>(sorts, src, INSTANCE + "_" + shape.edges.get(ed).second));
}
break;
}
case TRANSFORM:
OplGraph<String, String> shape = (OplGraph<String, String>) bindings.get(SHAPE);
for (String en : shape.nodes) {
bindings.put(INSTANCE + "_" + en + "_colimit", new OplSigma(MAPPING + "_" + SCHEMA + "_" + en + "_colimit", INSTANCE + "_" + en));
}
Map<String, Pair<String, String>> ed2 = new HashMap<>();
for (String e : shape.edges.keySet()) {
Pair<String, String> x = shape.edges.get(e);
String l = INSTANCE + "_" + x.first + "_colimit";
// String en = x.first.get(0);
String en = x.second;
bindings.put(TRANSFORM + "_" + e + "_colimit", new OplSigma(MAPPING + "_" + SCHEMA + "_" + en + "_colimit", TRANSFORM + "_" + e + "_forward"));
ed2.put(TRANSFORM + "_" + e + "_colimit", new Pair<>(l, INSTANCE + "_" + x.second + "_colimit"));
}
Set<String> en2 = shape.nodes.stream().map(x -> INSTANCE + "_" + x + "_colimit").collect(Collectors.toSet());
OplGraph<String, String> shape2 = new OplGraph<>(en2, ed2);
bindings.put(SCHEMA + "_for_result", shape2);
bindings.put(FINISHED, new OplExp.OplString("colimit " + SCHEMA + "_Colimit" + " " + SCHEMA + "_for_result"));
// bindings.put(FINISHED + " all", new OplExp.OplString(complete().toString()));
break;
default:
break;
}
}
use of catdata.Pair in project fql by CategoricalData.
the class SqlChecker method doChecks.
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
private void doChecks(List<Pair<String, Pair<Triple<String, List<Pair<String, List<Pair<String, String>>>>, List<Pair<String, String>>>, Triple<String, List<Pair<String, List<Pair<String, String>>>>, List<Pair<String, String>>>>>> tocheck) throws SQLException {
for (Pair<String, Pair<Triple<String, List<Pair<String, List<Pair<String, String>>>>, List<Pair<String, String>>>, Triple<String, List<Pair<String, List<Pair<String, String>>>>, List<Pair<String, String>>>>> eq : tocheck) {
JTabbedPane ret = new JTabbedPane();
Triple<String, List<Pair<String, List<Pair<String, String>>>>, List<Pair<String, String>>> lhs = eq.second.first;
Triple<String, List<Pair<String, List<Pair<String, String>>>>, List<Pair<String, String>>> rhs = eq.second.second;
if (!lhs.first.equals(rhs.first)) {
throw new RuntimeException(eq.first + " starts at two different tables, " + lhs.first + " and " + rhs.first);
}
Triple<String, Set<String>, String> q1 = path(lhs.first, lhs.second, lhs.third, info);
Triple<String, Set<String>, String> q2 = path(rhs.first, rhs.second, rhs.third, info);
endMatches(eq.first, q1.third, q2.third, lhs.third, rhs.third);
Statement stmt = conn.createStatement();
stmt.execute(q1.first);
ResultSet q1r = stmt.getResultSet();
stmt = conn.createStatement();
stmt.execute(q2.first);
ResultSet q2r = stmt.getResultSet();
Set<Map<String, String>> tuples1 = toTuples(q1r);
Set<Map<String, String>> tuples2 = toTuples(q2r);
boolean b = tuples1.equals(tuples2);
if (b) {
CodeTextPanel p2 = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "OK");
ret.add(p2, "Result");
} else {
ret.add(showDiff(lhs.first, q1.third, tuples1, tuples2, new LinkedList<>(endType(info, q1.third, lhs.third).keySet())), "Result");
}
if (!q1.second.isEmpty() || !q2.second.isEmpty()) {
String exns = "LHS warnings:\n\n" + Util.sep(q1.second, "\n") + "\n\nRHS warnings:\n\n" + Util.sep(q2.second, "\n");
CodeTextPanel p = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", exns);
ret.add("Warnings", p);
}
CodeTextPanel p = new CodeTextPanel(BorderFactory.createEtchedBorder(), "", q1.first + "\n\n = \n\n" + q2.first);
ret.add(p, "Query");
frames.add(new Pair<>(eq.first, ret));
}
}
use of catdata.Pair in project fql by CategoricalData.
the class GUI method getCurrent.
public static Pair<AqlEnv, String> getCurrent() {
CodeEditor<?, ?, ?> c = getSelectedEditor();
if (c == null || c.lang() != Language.AQL) {
return null;
}
AqlCodeEditor e = (AqlCodeEditor) c;
return new Pair<>(e.last_env, e.title);
}
Aggregations