use of catdata.Unit in project fql by CategoricalData.
the class XCtx method makeTables.
// private Map<C, String> xgrid;
// public JComponent getGrid(C c) {
// if (xgrid != null) {
// return xgrid.get(c);
// }
// if (DEBUG.debug.x_tables) {
// // makeTables(x -> cat().arrows(), new HashSet<>());
// return getGrid(c);
// }
// return new JPanel();
// }
// have this suppress pair IDs when possible
@SuppressWarnings({ "unchecked", "rawtypes" })
private JComponent makeTables(Function<Unit, Collection<Triple<C, C, List<C>>>> fn, Set<C> ignore) {
cl = new CardLayout();
// xgrid = new HashMap<>();
clx = new JPanel();
clx.setLayout(cl);
clx.add(new JPanel(), "0");
cl.show(clx, "0");
// xgrid.put((C)"_1", "0");
int www = 1;
try {
// Category<C, Triple<C, C, List<C>>> cat = cat();
List<JComponent> grid = new LinkedList<>();
Collection<Triple<C, C, List<C>>> cat = fn.apply(new Unit());
// Map<C, Set<List<C>>> entities = new HashMap<>();
Map entities = new HashMap<>();
Map<C, Set<C>> m = new HashMap<>();
for (C c : allIds()) {
entities.put(c, new HashSet<>());
m.put(c, new HashSet<>());
}
for (Triple<C, C, List<C>> k : cat) {
if (k.first.equals("_1")) {
// uncomment causes exception
Set set = (Set<List<C>>) entities.get(k.second);
// set.add(k);
set.add(k.third);
}
}
for (C c : allTerms()) {
Pair<C, C> t = type(c);
Set<C> set = m.get(t.first);
set.add(c);
}
List<C> keys = new LinkedList<>(m.keySet());
keys.sort((Object o1, Object o2) -> ((Comparable) o1).compareTo(o2));
for (C c : keys) {
if (c.equals("_1")) {
continue;
}
if (ignore.contains(c)) {
continue;
}
Pair<C, C> t = type(c);
Set<List<C>> src = (Set<List<C>>) entities.get(t.first);
List<C> cols = new LinkedList<>(m.get(c));
cols = cols.stream().filter(x -> !x.toString().startsWith("!")).collect(Collectors.toList());
Object[][] rowData = new Object[src.size()][cols.size()];
int idx = cols.indexOf(c);
if (idx != -1) {
C old = cols.get(0);
cols.set(0, c);
cols.set(idx, old);
if (cols.size() > 1) {
List<C> colsX = new LinkedList<>(cols.subList(1, cols.size()));
colsX.sort(null);
colsX.add(0, c);
cols = colsX;
}
}
List<String> colNames3 = cols.stream().map(x -> type(x).second.equals(x) ? x.toString() : x + " (" + type(x).second + ")").collect(Collectors.toList());
Object[] colNames = colNames3.toArray();
int row = 0;
for (List<C> l : src) {
rowData[row][0] = l;
int cl = 0;
for (C col : cols) {
List<C> r = new LinkedList<>(l);
r.add(col);
for (Triple<C, C, List<C>> cand : cat) {
if (!cand.first.equals("_1")) {
continue;
}
if (!cand.second.equals(type(col).second)) {
continue;
}
if (kb.equiv(cand.third, r)) {
rowData[row][cl] = abbrPrint(cand.third);
break;
}
}
cl++;
}
row++;
}
JPanel table = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), c + " (" + src.size() + ") rows", rowData, colNames);
JPanel table2 = GuiUtil.makeTable(BorderFactory.createEtchedBorder(), c + " (" + src.size() + ") rows", rowData, colNames);
// xgrid.put(c, Integer.toString(www));
clx.add(new JScrollPane(table2), Integer.toString(www));
www++;
grid.add(table);
}
return GuiUtil.makeGrid(grid);
} catch (Exception e) {
e.printStackTrace();
return new CodeTextPanel(BorderFactory.createEtchedBorder(), "", "ERROR\n\n" + e.getMessage());
}
}
use of catdata.Unit in project fql by CategoricalData.
the class AqlViewer method visit.
@Override
public <Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> Unit visit(JTabbedPane ret, Query<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> Q) {
try {
Query<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> q = Q.unnest();
JComponent comp = makeQueryPanel(q);
ret.add("SQL", comp);
} catch (Exception ex) {
ex.printStackTrace();
ret.add("SQL Exn", new CodeTextPanel("Exception", ex.getMessage()));
}
return new Unit();
}
use of catdata.Unit in project fql by CategoricalData.
the class AqlViewer method visit.
@Override
public <Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> Unit visit(JTabbedPane ret, Mapping<Ty, En1, Sym, Fk1, Att1, En2, Fk2, Att2> M) {
ret.addTab("Translate", viewMorphism(M.semantics(), M.src.typeSide.js));
ret.addTab("Collage", new CodeTextPanel("", M.collage().toString()));
return new Unit();
}
use of catdata.Unit in project fql by CategoricalData.
the class AqlViewer method visit.
@Override
public <Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> Unit visit(JTabbedPane ret, Instance<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> I) {
ret.addTab("Tables", viewAlgebra((Algebra<catdata.aql.exp.TyExpRaw.Ty, catdata.aql.exp.SchExpRaw.En, catdata.aql.exp.TyExpRaw.Sym, catdata.aql.exp.SchExpRaw.Fk, catdata.aql.exp.SchExpRaw.Att, catdata.aql.exp.InstExpRaw.Gen, catdata.aql.exp.InstExpRaw.Sk, X, Y>) I.algebra()));
if (I.algebra().talg().sks.size() < 1024) {
ret.addTab("Type Algebra", new CodeTextPanel("", I.algebra().talg().toString()));
} else {
ret.addTab("Type Algebra", new CodeTextPanel("", "Suppressed, size " + I.algebra().talg().sks.size() + "."));
}
ret.addTab("DP", viewDP(I.dp(), I.collage(), I.schema().typeSide.js));
return new Unit();
}
Aggregations