use of catdata.ide.CodeTextPanel in project fql by CategoricalData.
the class AqlViewer method viewDP.
/*public static <Ty, En, Sym, Fk, Att> JComponent viewSchema2(Schema<Ty, En, Sym, Fk, Att> schema) {
mxGraph graph = new mxGraph();
Object parent = graph.getDefaultParent();
Ctx<Chc<En,Ty>, Object> nodes = new Ctx<>();
for (En en : schema.ens) {
Object v1 = graph.insertVertex(parent, null, en.toString(), 20, 20, 80, 30);
nodes.put(Chc.inLeft(en), v1);
}
for (Ty ty : schema.typeSide.tys) {
Object v1 = graph.insertVertex(parent, null, ty.toString(), 20, 20, 80, 30);
nodes.put(Chc.inRight(ty), v1);
}
for (Att att : schema.atts.keySet()) {
graph.insertEdge(parent, null, att.toString(), nodes.get(Chc.inLeft(schema.atts.get(att).first)), nodes.get(Chc.inRight(schema.atts.get(att).second)));
}
for (Fk fk : schema.fks.keySet()) {
graph.insertEdge(parent, null, fk.toString(), nodes.get(Chc.inLeft(schema.fks.get(fk).first)), nodes.get(Chc.inLeft(schema.fks.get(fk).second)));
}
mxGraphLayout layout = new mxOrganicLayout(graph); // or whatever layouting algorithm
layout.execute(parent);
mxGraphComponent graphComponent = new mxGraphComponent(graph);
// Map<String, Object> style = graph.getStylesheet().getDefaultEdgeStyle();
// style.put(mxConstants.STYLE_ROUNDED, true);
// style.put(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ENTITY_RELATION);
return graphComponent;
} */
private static <Ty, En, Sym, Fk, Att, Gen, Sk> JComponent viewDP(DP<Ty, En, Sym, Fk, Att, Gen, Sk> dp, Collage col, AqlJs js) {
CodeTextPanel input = new CodeTextPanel("Input (either equation-in-ctx or term-in-ctx)", "");
CodeTextPanel output = new CodeTextPanel("Output", "");
JButton eq = new JButton("Decide Equation-in-ctx");
JButton nf = new JButton("Normalize Term-in-ctx");
/*
* if (!dp.hasNFs()) { nf.setEnabled(false); }
*/
JButton print = new JButton("Show Info");
JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
buttonPanel.add(eq);
buttonPanel.add(nf);
buttonPanel.add(print);
// TODO: aql does not position correctly
Split split = new Split(.5, JSplitPane.VERTICAL_SPLIT);
split.add(input);
split.add(output);
JPanel main = new JPanel(new BorderLayout());
main.add(split, BorderLayout.CENTER);
main.add(buttonPanel, BorderLayout.NORTH);
print.addActionListener(x -> output.setText(dp.toStringProver()));
eq.addActionListener(x -> {
try {
Triple<List<Pair<String, String>>, RawTerm, RawTerm> y = AqlParser.getParser().parseEq(input.getText());
Triple<Ctx<Var, Chc<Ty, En>>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>> z = RawTerm.infer2(y.first, y.second, y.third, col, js);
boolean isEq = dp.eq(z.first, z.second, z.third);
output.setText(Boolean.toString(isEq));
} catch (Exception ex) {
ex.printStackTrace();
output.setText(ex.getMessage());
}
});
nf.addActionListener(x -> {
try {
Pair<List<Pair<String, String>>, RawTerm> y = AqlParser.getParser().parseTermInCtx(input.getText());
Triple<Ctx<Var, Chc<Ty, En>>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>, Term<Ty, En, Sym, Fk, Att, Gen, Sk>> z = RawTerm.infer2(y.first, y.second, y.second, col, js);
Term<Ty, En, Sym, Fk, Att, Gen, Sk> w = dp.nf(z.first, z.second);
output.setText(w.toString());
} catch (Exception ex) {
ex.printStackTrace();
output.setText(ex.getMessage());
}
});
return main;
}
use of catdata.ide.CodeTextPanel 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.ide.CodeTextPanel in project fql by CategoricalData.
the class AqlViewer method view.
public static JComponent view(float time, Semantics s, int maxrows, Exp<?> exp, AqlEnv env) {
JTabbedPane ret = new JTabbedPane();
new AqlViewer(maxrows, env).visit(ret, s);
ret.addTab("Text", new CodeTextPanel("", s.toString()));
ret.addTab("Expression", new CodeTextPanel("", exp.toString()));
int sampleSize = (int) exp.getOrDefault(env, AqlOption.gui_sample_size);
boolean doSample = (boolean) exp.getOrDefault(env, AqlOption.gui_sample);
if (doSample) {
String sample = s.sample(sampleSize);
if (sample != null) {
ret.addTab("Sample", new CodeTextPanel("", "May not include all tables, columns, or rows.\n\n" + sample));
}
}
ret.addTab("Performance", new CodeTextPanel("", "Compute time: " + time + " seconds.\n\nSize: " + s.size()));
return ret;
}
use of catdata.ide.CodeTextPanel 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.ide.CodeTextPanel 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