Search in sources :

Example 26 with CodeTextPanel

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;
}
Also used : Att(catdata.aql.exp.SchExpRaw.Att) JPanel(javax.swing.JPanel) Ty(catdata.aql.exp.TyExpRaw.Ty) Fk(catdata.aql.exp.SchExpRaw.Fk) Ctx(catdata.Ctx) Sym(catdata.aql.exp.TyExpRaw.Sym) JButton(javax.swing.JButton) En(catdata.aql.exp.SchExpRaw.En) Term(catdata.aql.Term) RawTerm(catdata.aql.RawTerm) RawTerm(catdata.aql.RawTerm) Gen(catdata.aql.exp.InstExpRaw.Gen) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) CodeTextPanel(catdata.ide.CodeTextPanel) Sk(catdata.aql.exp.InstExpRaw.Sk) List(java.util.List) LinkedList(java.util.LinkedList) Split(catdata.ide.Split)

Example 27 with CodeTextPanel

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();
}
Also used : Ty(catdata.aql.exp.TyExpRaw.Ty) Sym(catdata.aql.exp.TyExpRaw.Sym) JComponent(javax.swing.JComponent) Unit(catdata.Unit) CodeTextPanel(catdata.ide.CodeTextPanel)

Example 28 with CodeTextPanel

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;
}
Also used : CodeTextPanel(catdata.ide.CodeTextPanel) JTabbedPane(javax.swing.JTabbedPane) Paint(java.awt.Paint)

Example 29 with CodeTextPanel

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();
}
Also used : CodeTextPanel(catdata.ide.CodeTextPanel) Unit(catdata.Unit)

Example 30 with CodeTextPanel

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();
}
Also used : Algebra(catdata.aql.Algebra) CodeTextPanel(catdata.ide.CodeTextPanel) Unit(catdata.Unit)

Aggregations

CodeTextPanel (catdata.ide.CodeTextPanel)31 JTabbedPane (javax.swing.JTabbedPane)19 JPanel (javax.swing.JPanel)18 GridLayout (java.awt.GridLayout)17 LinkedList (java.util.LinkedList)11 JComponent (javax.swing.JComponent)11 Paint (java.awt.Paint)10 List (java.util.List)9 Graph (edu.uci.ics.jung.graph.Graph)7 HashMap (java.util.HashMap)7 JSplitPane (javax.swing.JSplitPane)7 Pair (catdata.Pair)6 Unit (catdata.Unit)5 Const (catdata.fqlpp.CatExp.Const)5 Map (java.util.Map)5 Set (java.util.Set)5 JButton (javax.swing.JButton)5 JScrollPane (javax.swing.JScrollPane)5 Triple (catdata.Triple)4 Util (catdata.Util)4