Search in sources :

Example 56 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class FqlppDisplay method build2Elements.

@SuppressWarnings("unchecked")
private static Graph build2Elements(Signature<Object, Object> sig, Transform<Object, Object, Set, Fn> trans) {
    Functor<Object, Object, Set, Fn> I = trans.source;
    Functor<Object, Object, Set, Fn> J = trans.target;
    Graph<Object, Object> ret = new DirectedSparseMultigraph<>();
    for (Node n : sig.nodes) {
        for (Object o : I.applyO(n)) {
            ret.addVertex(new Triple<>(o, n.name, "src"));
        }
    }
    for (Edge e : sig.edges) {
        for (Object o : I.applyO(e.source)) {
            Object fo = I.applyA(sig.path(e)).apply(o);
            Triple s = new Triple<>(o, e.source.name, "src");
            Triple t = new Triple<>(fo, e.target.name, "dst");
            ret.addEdge(new Quad<>(e.name, s, t, "src"), s, t);
        }
    }
    for (Node n : sig.nodes) {
        for (Object o : J.applyO(n)) {
            ret.addVertex(new Triple<>(o, n.name, "dst"));
        }
    }
    for (Edge e : sig.edges) {
        for (Object o : J.applyO(e.source)) {
            Object fo = J.applyA(sig.path(e)).apply(o);
            Triple s = new Triple<>(o, e.source.name, "dst");
            Triple t = new Triple<>(fo, e.target.name, "dst");
            ret.addEdge(new Quad<>(e.name, s, t, "dst"), s, t);
        }
    }
    int i = 0;
    for (Node n : sig.nodes) {
        for (Object o : I.applyO(n)) {
            Object fo = trans.apply(n).apply(o);
            Triple s = new Triple<>(o, n.name, "src");
            Triple t = new Triple<>(fo, n.name, "dst");
            ret.addEdge(new Quad<>("", s, t, i++), s, t);
        }
    }
    return ret;
}
Also used : Triple(catdata.Triple) Set(java.util.Set) FinSet(catdata.fqlpp.cat.FinSet) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) Node(catdata.fqlpp.cat.Signature.Node) Fn(catdata.fqlpp.cat.FinSet.Fn) Edge(catdata.fqlpp.cat.Signature.Edge) Paint(java.awt.Paint)

Example 57 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class FqlppDisplay method doElements2View.

private static JComponent doElements2View(Color clr, Graph<Triple, Quad> sgv) {
    Layout<Triple, Quad> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<Triple, Quad> vv = new VisualizationViewer<>(layout);
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    Color clr1 = clr.brighter().brighter();
    Color clr2 = clr.darker().darker();
    Function<Triple, Paint> vertexPaint = x -> x.third.equals("src") ? clr1 : clr2;
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function<Triple, String> ttt1 = arg0 -> Util.nice(arg0.first.toString());
    vv.getRenderContext().setVertexLabelTransformer(ttt1);
    Function<Quad, String> ttt2 = arg0 -> Util.nice(arg0.first.toString());
    vv.getRenderContext().setEdgeLabelTransformer(ttt2);
    float[] dash = { 1.0f };
    Stroke edgeStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 10.0f);
    Stroke bs = new BasicStroke();
    Function<Quad, Stroke> edgeStrokeTransformer = x -> x.fourth instanceof Integer ? edgeStroke : bs;
    vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    GraphZoomScrollPane zzz = new GraphZoomScrollPane(vv);
    JPanel ret = new JPanel(new GridLayout(1, 1));
    ret.add(zzz);
    ret.setBorder(BorderFactory.createEtchedBorder());
    return ret;
}
Also used : Color(java.awt.Color) Edge(catdata.fqlpp.cat.Signature.Edge) Vector(java.util.Vector) Map(java.util.Map) FinCat(catdata.fqlpp.cat.FinCat) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) FunCat(catdata.fqlpp.cat.FunCat) JFrame(javax.swing.JFrame) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Pair(catdata.Pair) KeyStroke(javax.swing.KeyStroke) ItemEvent(java.awt.event.ItemEvent) Fn(catdata.fqlpp.cat.FinSet.Fn) Quad(catdata.Quad) Function(com.google.common.base.Function) Disp(catdata.ide.Disp) Category(catdata.fqlpp.cat.Category) Set(java.util.Set) Inst(catdata.fqlpp.cat.Inst) BorderFactory(javax.swing.BorderFactory) KeyEvent(java.awt.event.KeyEvent) Component(java.awt.Component) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) List(java.util.List) Paint(java.awt.Paint) Entry(java.util.Map.Entry) Triple(catdata.Triple) BasicStroke(java.awt.BasicStroke) GuiUtil(catdata.ide.GuiUtil) JPanel(javax.swing.JPanel) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) InputEvent(java.awt.event.InputEvent) ListSelectionModel(javax.swing.ListSelectionModel) Const(catdata.fqlpp.CatExp.Const) CardLayout(java.awt.CardLayout) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) Node(catdata.fqlpp.cat.Signature.Node) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Functor(catdata.fqlpp.cat.Functor) HashMap(java.util.HashMap) GridLayout(java.awt.GridLayout) Signature(catdata.fqlpp.cat.Signature) JTabbedPane(javax.swing.JTabbedPane) Graph(edu.uci.ics.jung.graph.Graph) GUI(catdata.ide.GUI) LinkedList(java.util.LinkedList) Stroke(java.awt.Stroke) JComponent(javax.swing.JComponent) Transform(catdata.fqlpp.cat.Transform) Layout(edu.uci.ics.jung.algorithms.layout.Layout) CodeTextPanel(catdata.ide.CodeTextPanel) JList(javax.swing.JList) Util(catdata.Util) ActionEvent(java.awt.event.ActionEvent) FinSet(catdata.fqlpp.cat.FinSet) JScrollPane(javax.swing.JScrollPane) 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) BasicStroke(java.awt.BasicStroke) Quad(catdata.Quad) JPanel(javax.swing.JPanel) KeyStroke(javax.swing.KeyStroke) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) DefaultModalGraphMouse(edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Color(java.awt.Color) GraphZoomScrollPane(edu.uci.ics.jung.visualization.GraphZoomScrollPane) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Triple(catdata.Triple) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer)

Example 58 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class PPParser method toCatConst.

public static CatExp.Const toCatConst(Object y) {
    Set<String> nodes = new HashSet<>();
    Set<Triple<String, String, String>> arrows = new HashSet<>();
    Set<Pair<Pair<String, List<String>>, Pair<String, List<String>>>> eqs = new HashSet<>();
    Tuple3 s = (Tuple3) y;
    Tuple3 nodes0 = (Tuple3) s.a;
    Tuple3 arrows0 = (Tuple3) s.b;
    Tuple3 eqs0 = (Tuple3) s.c;
    List nodes1 = (List) nodes0.b;
    List arrows1 = (List) arrows0.b;
    List eqs1 = (List) eqs0.b;
    for (Object o : nodes1) {
        nodes.add((String) o);
    }
    for (Object o : arrows1) {
        Tuple5 x = (Tuple5) o;
        arrows.add(new Triple<>((String) x.a, (String) x.c, (String) x.e));
    }
    for (Object o : eqs1) {
        Tuple3 x = (Tuple3) o;
        List<String> l1 = (List<String>) x.a;
        List<String> l2 = (List<String>) x.c;
        String xxx = l1.remove(0);
        String yyy = l2.remove(0);
        eqs.add(new Pair<>(new Pair<>(xxx, l1), new Pair<>(yyy, l2)));
    }
    CatExp.Const c = new CatExp.Const(nodes, arrows, eqs);
    return c;
}
Also used : Const(catdata.fqlpp.FnExp.Const) CatConst(catdata.fqlpp.FunctorExp.CatConst) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) InstConst(catdata.fqlpp.FunctorExp.InstConst) MapConst(catdata.fqlpp.FunctorExp.MapConst) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Pair(catdata.Pair)

Example 59 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class PreProcessor method visit.

@Override
public CatExp visit(FQLPPProgram env, Union e) {
    CatExp l = e.l.accept(env, this);
    CatExp r = e.r.accept(env, this);
    CatExp lx = CatOps.resolve(env, l);
    CatExp rx = CatOps.resolve(env, r);
    if (!(lx instanceof Const)) {
        throw new RuntimeException("Not a const: " + lx);
    }
    if (!(rx instanceof Const)) {
        throw new RuntimeException("Not a const: " + rx);
    }
    Const ly = (Const) lx;
    Const ry = (Const) rx;
    Set<Pair<Pair<String, List<String>>, Pair<String, List<String>>>> eqs = new HashSet<>();
    Set<Triple<String, String, String>> arrows = new HashSet<>();
    Set<String> nodes = new HashSet<>();
    nodes.addAll(ly.nodes);
    nodes.addAll(ry.nodes);
    arrows.addAll(ly.arrows);
    arrows.addAll(ry.arrows);
    eqs.addAll(ly.eqs);
    eqs.addAll(ry.eqs);
    return new Const(nodes, arrows, eqs);
}
Also used : Triple(catdata.Triple) Const(catdata.fqlpp.CatExp.Const) List(java.util.List) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 60 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class CatOps method toMapping.

private Triple<Category, Category, Mapping<String, String, String, String>> toMapping(FQLPPProgram env, MapConst ic) {
    CatExp src0 = resolve(env, ic.src);
    if (src0 == null) {
        throw new RuntimeException("Missing category: " + ic.src);
    }
    if (!(src0 instanceof Const)) {
        throw new RuntimeException("Can only create mappings for finitely-presented categories.");
    }
    Const src = (Const) src0;
    CatExp dst0 = resolve(env, ic.dst);
    if (!(dst0 instanceof Const)) {
        throw new RuntimeException("Can only create mappings for finitely-presented categories.");
    }
    Const dst = (Const) dst0;
    Category srcX = src.accept(env, this);
    Category dstX = dst.accept(env, this);
    Signature<String, String> srcY = new Signature<>(src.nodes, src.arrows, src.eqs);
    Signature<String, String> dstY = new Signature<>(dst.nodes, dst.arrows, dst.eqs);
    Map<Node, Node> nm = new HashMap<>();
    for (String n0 : ic.nm.keySet()) {
        Signature<String, String>.Node n = srcY.getNode(n0);
        String v = ic.nm.get(n.name);
        if (v == null) {
            throw new RuntimeException("Missing object mapping for " + n.name);
        }
        nm.put(n, dstY.getNode(v));
    }
    Map<Edge, Path> em = new HashMap<>();
    for (String n0 : ic.em.keySet()) {
        Signature<String, String>.Edge n = srcY.getEdge(n0);
        Pair<String, List<String>> k = ic.em.get(n.name);
        if (k == null) {
            throw new RuntimeException("Missing arrow mapping for " + n.name);
        }
        em.put(n, dstY.path(k.first, k.second));
    }
    Mapping<String, String, String, String> I = new Mapping(nm, em, srcY, dstY);
    return new Triple<>(srcX, dstX, I);
}
Also used : ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Path(catdata.fqlpp.cat.Signature.Path) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) CatConst(catdata.fqlpp.FunctorExp.CatConst) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) Const(catdata.fqlpp.CatExp.Const) InstConst(catdata.fqlpp.FunctorExp.InstConst) MapConst(catdata.fqlpp.FunctorExp.MapConst) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Node(catdata.fqlpp.cat.Signature.Node) Mapping(catdata.fqlpp.cat.Mapping) Triple(catdata.Triple) Signature(catdata.fqlpp.cat.Signature) Edge(catdata.fqlpp.cat.Signature.Edge)

Aggregations

Triple (catdata.Triple)116 Pair (catdata.Pair)93 LinkedList (java.util.LinkedList)84 List (java.util.List)75 HashMap (java.util.HashMap)65 Map (java.util.Map)49 HashSet (java.util.HashSet)47 LinkedHashMap (java.util.LinkedHashMap)36 Set (java.util.Set)28 Chc (catdata.Chc)22 Util (catdata.Util)18 En (catdata.aql.exp.SchExpRaw.En)18 Ty (catdata.aql.exp.TyExpRaw.Ty)18 Ctx (catdata.Ctx)17 Sym (catdata.aql.exp.TyExpRaw.Sym)17 Collectors (java.util.stream.Collectors)17 Att (catdata.aql.exp.SchExpRaw.Att)16 Fk (catdata.aql.exp.SchExpRaw.Fk)16 Tuple3 (org.jparsec.functors.Tuple3)16 Quad (catdata.Quad)13