Search in sources :

Example 1 with DMG

use of catdata.graph.DMG in project fql by CategoricalData.

the class AqlViewer method viewGraph.

/*
	public static Optional<JComponent> viewPragma(Pragma p) {
		if (p instanceof ToCsvPragmaTransform) {
			return Optional.empty();
		} else if (p instanceof ToCsvPragmaInstance) {
			return Optional.of(viewPragmaToCsvInstance((ToCsvPragmaInstance)p));
		}
		throw new RuntimeException("Anomaly: please report");
	} 
	
	private static JComponent viewPragmaToCsvInstance(ToCsvPragmaInstance p) {
		return new JPanel();
	} */
private static <N, E> JComponent viewGraph(DMG<N, E> g) {
    Graph<N, E> sgv = new DirectedSparseMultigraph<>();
    for (N n : g.nodes) {
        sgv.addVertex(n);
    }
    for (E e : g.edges.keySet()) {
        sgv.addEdge(e, g.edges.get(e).first, g.edges.get(e).second);
    }
    if (sgv.getVertexCount() == 0) {
        return new JPanel();
    }
    Layout<N, E> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<N, E> vv = new VisualizationViewer<>(layout);
    Function<N, Paint> vertexPaint = x -> Color.black;
    DefaultModalGraphMouse<N, E> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function<E, String> et = Object::toString;
    Function<N, String> vt = Object::toString;
    vv.getRenderContext().setEdgeLabelTransformer(et);
    vv.getRenderContext().setVertexLabelTransformer(vt);
    GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
    JPanel ret = new JPanel(new GridLayout(1, 1));
    ret.add(zzz);
    ret.setBorder(BorderFactory.createEtchedBorder());
    vv.getRenderContext().setLabelOffset(16);
    vv.setBackground(Color.white);
    return ret;
}
Also used : Color(java.awt.Color) TypeSide(catdata.aql.TypeSide) Sym(catdata.aql.exp.TyExpRaw.Sym) Comment(catdata.aql.Comment) Constraints(catdata.aql.Constraints) AqlOption(catdata.aql.AqlOptions.AqlOption) Instance(catdata.aql.Instance) Map(java.util.Map) Exp(catdata.aql.exp.Exp) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) DP(catdata.aql.DP) Term(catdata.aql.Term) BorderLayout(java.awt.BorderLayout) Pair(catdata.Pair) Semantics(catdata.aql.Semantics) Function(com.google.common.base.Function) Transform(catdata.aql.Transform) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) ColimitSchema(catdata.aql.ColimitSchema) Query(catdata.aql.Query) DMG(catdata.graph.DMG) Component(java.awt.Component) Collectors(java.util.stream.Collectors) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) List(java.util.List) Paint(java.awt.Paint) Sk(catdata.aql.exp.InstExpRaw.Sk) Triple(catdata.Triple) Algebra(catdata.aql.Algebra) CombinatorParser(catdata.aql.exp.CombinatorParser) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) Ty(catdata.aql.exp.TyExpRaw.Ty) Pragma(catdata.aql.Pragma) Ctx(catdata.Ctx) JSplitPane(javax.swing.JSplitPane) RawTerm(catdata.aql.RawTerm) En(catdata.aql.exp.SchExpRaw.En) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Chc(catdata.Chc) AqlParser(catdata.aql.exp.AqlParser) Gen(catdata.aql.exp.InstExpRaw.Gen) GridLayout(java.awt.GridLayout) LinkedHashMap(java.util.LinkedHashMap) Mapping(catdata.aql.Mapping) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) AqlJs(catdata.aql.AqlJs) Collage(catdata.aql.Collage) LinkedList(java.util.LinkedList) JComponent(javax.swing.JComponent) Morphism(catdata.aql.Morphism) Fk(catdata.aql.exp.SchExpRaw.Fk) Layout(edu.uci.ics.jung.algorithms.layout.Layout) JButton(javax.swing.JButton) CodeTextPanel(catdata.ide.CodeTextPanel) SemanticsVisitor(catdata.aql.SemanticsVisitor) Util(catdata.Util) Unit(catdata.Unit) Att(catdata.aql.exp.SchExpRaw.Att) Split(catdata.ide.Split) AqlEnv(catdata.aql.exp.AqlEnv) Schema(catdata.aql.Schema) Var(catdata.aql.Var) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Mode(edu.uci.ics.jung.visualization.control.ModalGraphMouse.Mode) JPanel(javax.swing.JPanel) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) GridLayout(java.awt.GridLayout) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Example 2 with DMG

use of catdata.graph.DMG in project fql by CategoricalData.

the class Constraints method step.

// TODO aql needs to be over all eds
public <Gen, Sk, X, Y> Instance<Ty, En, Sym, Fk, Att, ?, ?, ?, ?> step(Instance<Ty, En, Sym, Fk, Att, Gen, Sk, X, Y> I, AqlOptions options) {
    Collection<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>> T = triggers(I, options);
    if (T.isEmpty()) {
        return null;
    }
    DMG<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Void> shape = new DMG<>(T, new HashMap<>());
    Ctx<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>>> nodesA = new Ctx<>();
    Ctx<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>>> nodesE = new Ctx<>();
    Map<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Term<Void, En, Void, Fk, Void, Gen, Void>> aaa = new HashMap<>();
    Map<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Term<Void, En, Void, Fk, Void, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Void>> xxx = new HashMap<>();
    for (Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>> t : T) {
        Query<Ty, En, Sym, Fk, Att, WHICH, Unit, Void> Q = t.first.Q;
        Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> A = Q.ens.get(WHICH.FRONT);
        Instance<Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> E = Q.ens.get(WHICH.BACK);
        Transform<Ty, En, Sym, Fk, Att, Var, Var, Var, Var, ID, Chc<Var, Pair<ID, Att>>, ID, Chc<Var, Pair<ID, Att>>> AE = Q.fks.get(new Unit());
        nodesA.put(t, A);
        nodesE.put(t, E);
        for (Var v : AE.src().gens().keySet()) {
            // revisit after colimit fixed
            xxx.put(new Pair<>(t, v), Term.Gen(new Pair<>(t, v)));
            aaa.put(new Pair<>(t, v), I.algebra().repr(t.second.get(v)));
        }
    /*for (Void v : AE.src().sks().keySet()) {
				yyy.put(v, Util.abort(v)); // revisit after colimit fixed
				bbb.put(v, Util.abort(v));
			}*/
    }
    ColimitInstance<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Void, Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> A0 = new ColimitInstance<>(schema, shape, nodesA, new Ctx<>(), options);
    ColimitInstance<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Void, Ty, En, Sym, Fk, Att, Var, Var, ID, Chc<Var, Pair<ID, Att>>> E0 = new ColimitInstance<>(schema, shape, nodesE, new Ctx<>(), options);
    LiteralTransform<Ty, En, Sym, Fk, Att, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, ID, Chc<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<ID, Att>>, ID, Chc<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<ID, Att>>> A0E0 = new LiteralTransform<>(xxx, new HashMap<>(), A0, E0, false);
    LiteralTransform<Ty, En, Sym, Fk, Att, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Gen, Sk, ID, Chc<Pair<Pair<ED<Ty, En, Sym, Fk, Att>, Row<WHICH, X>>, Var>, Pair<ID, Att>>, X, Y> A0I = new LiteralTransform<>(aaa, new HashMap<>(), A0, I, false);
    return pushout(A0E0, A0I, options);
// TODO aql disable checking for speed
}
Also used : EvalInstance(catdata.aql.fdm.EvalInstance) ColimitInstance(catdata.aql.fdm.ColimitInstance) HashMap(java.util.HashMap) Ctx(catdata.Ctx) ColimitInstance(catdata.aql.fdm.ColimitInstance) Unit(catdata.Unit) WHICH(catdata.aql.ED.WHICH) ID(catdata.aql.It.ID) Pair(catdata.Pair) DMG(catdata.graph.DMG) LiteralTransform(catdata.aql.fdm.LiteralTransform) Row(catdata.aql.fdm.EvalAlgebra.Row) Chc(catdata.Chc)

Aggregations

Chc (catdata.Chc)2 Ctx (catdata.Ctx)2 Pair (catdata.Pair)2 Unit (catdata.Unit)2 DMG (catdata.graph.DMG)2 Triple (catdata.Triple)1 Util (catdata.Util)1 Algebra (catdata.aql.Algebra)1 AqlJs (catdata.aql.AqlJs)1 AqlOption (catdata.aql.AqlOptions.AqlOption)1 ColimitSchema (catdata.aql.ColimitSchema)1 Collage (catdata.aql.Collage)1 Comment (catdata.aql.Comment)1 Constraints (catdata.aql.Constraints)1 DP (catdata.aql.DP)1 WHICH (catdata.aql.ED.WHICH)1 Instance (catdata.aql.Instance)1 ID (catdata.aql.It.ID)1 Mapping (catdata.aql.Mapping)1 Morphism (catdata.aql.Morphism)1