Search in sources :

Example 6 with Quad

use of catdata.Quad 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 7 with Quad

use of catdata.Quad in project fql by CategoricalData.

the class LeftKanSigma method fullSigma.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static <O1, A1, O2, A2> Quad<Functor<O2, A2, Set, Fn>, Transform<O1, A1, Set, Fn>, Transform<O2, A2, Set, Fn>, Map<Object, List<Pair<A2, Object>>>> fullSigma(Functor<O1, A1, O2, A2> F, Functor<O1, A1, Set, Fn> I, Transform<O1, A1, Set, Fn> t, Functor<O2, A2, Set, Fn> JJJ) {
    Mapping<O1, A1, O2, A2> G = F.toMapping();
    FPTransform<O1, A1> m = null;
    if (t != null) {
        m = t.toFPTransform();
    }
    Instance<O2, A2> J = null;
    if (JJJ != null) {
        J = JJJ.toInstance();
    }
    Quad<Instance<O2, A2>, Map<Signature<O1, A1>.Node, Map<Object, Object>>, Map<Signature<O2, A2>.Node, Map<Object, Object>>, Map<Object, List<Pair<Signature<O2, A2>.Edge, Object>>>> q = fullSigmaOnPresentation(G, I.toInstance(), m, J, 100);
    Functor<Signature<O2, A2>.Node, Signature<O2, A2>.Path, Set, Fn> f2 = q.first.toFunctor();
    Functor<O2, A2, Set, Fn> f3 = new Functor<>(F.target, FinSet.FinSet, x -> f2.applyO(G.target.new Node(x)), a -> {
        if (F.target.isId(a)) {
            return Fn.id(f2.applyO(G.target.new Node(F.target.source(a))));
        }
        return f2.applyA(G.target.path(G.target.getEdge(a)));
    });
    // use third
    Transform<O2, A2, Set, Fn> thr = null;
    if (t != null) {
        if (JJJ == null) {
            throw new RuntimeException("Left kan sigma anomaly, please report");
        }
        thr = new Transform<>(f3, JJJ, x -> new Fn(f3.applyO(x), JJJ.applyO(x), q.third.get(G.target.new Node(x))::get));
    }
    Transform<O1, A1, Set, Fn> et = new Transform<>(I, Functor.compose(F, f3), x -> new Fn(I.applyO(x), Functor.compose(F, f3).applyO(x), q.second.get(G.source.new Node(x))::get));
    Map<Object, List<Pair<A2, Object>>> nq = new HashMap<>();
    for (Entry<Object, List<Pair<Signature<O2, A2>.Edge, Object>>> o : q.fourth.entrySet()) {
        List<Pair<A2, Object>> rt = new LinkedList<>();
        for (int j = 0; j < o.getValue().size(); j++) {
            Pair<Signature<O2, A2>.Edge, Object> fst = o.getValue().get(j);
            if (fst.first == null) {
                // because no guids, have pairs as first
                rt.add(new Pair<>(null, ((Pair) fst.second).second));
            } else {
                // 
                rt.add(new Pair<>(fst.first.name, fst.second));
            }
        }
        nq.put(o.getKey(), rt);
    }
    return new Quad<>(f3, et, thr, nq);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) List(java.util.List) Quad(catdata.Quad) Map(java.util.Map) Entry(java.util.Map.Entry) Util(catdata.Util) Set(java.util.Set) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Collectors(java.util.stream.Collectors) Pair(catdata.Pair) Quad(catdata.Quad) Set(java.util.Set) HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Fn(catdata.fqlpp.cat.FinSet.Fn) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with Quad

use of catdata.Quad in project fql by CategoricalData.

the class Pi method lim2.

private static <OA, AA, OB, AB, AC> Set<Map> lim2(Functor<Triple<OA, OB, AC>, Quad<AA, AB, AC, AC>, Set, Fn> I) {
    Category<Triple<OA, OB, AC>, Quad<AA, AB, AC, AC>> B = I.source;
    if (B.objects().isEmpty()) {
        Set<Map> ret = new HashSet<>();
        Map m = new HashMap();
        m.put(0, new Unit());
        ret.add(m);
        return ret;
    }
    Triple<OA, OB, AC>[] cnames = cnames(I.source);
    int temp = 0;
    List<Pair<Pair<String, String>, Pair<String, String>>> where = new LinkedList<>();
    // store objects of B directly
    Map<String, Object> from = new HashMap<>();
    LinkedHashMap<String, Pair<String, String>> select = new LinkedHashMap<>();
    Map<Object, Set<Map<Object, Object>>> state = new HashMap<>();
    for (Triple<OA, OB, AC> n : B.objects()) {
        from.put("t" + temp, n);
        select.put("c" + temp, new Pair<>("t" + temp, "c0"));
        temp++;
        state.put(n, shred(I.applyO(n)));
    }
    for (Quad<AA, AB, AC, AC> e : B.arrows()) {
        if (B.isId(e)) {
            continue;
        }
        from.put("t" + temp, e);
        where.add(new Pair<>(new Pair<>("t" + temp, "c0"), new Pair<>("t" + cnamelkp(cnames, B.source(e)), "c0")));
        where.add(new Pair<>(new Pair<>("t" + temp, "c1"), new Pair<>("t" + cnamelkp(cnames, B.target(e)), "c0")));
        temp++;
        state.put(e, shred(I.applyA(e)));
    }
    Flower f = new Flower(select, from, where);
    Set<Map<Object, Object>> uuu = f.eval(state);
    Set<Map> x0 = unshred(B.objects().size(), uuu);
    x0 = keygen(x0);
    return x0;
}
Also used : Quad(catdata.Quad) Unit(catdata.Unit) Pair(catdata.Pair) Triple(catdata.Triple)

Example 9 with Quad

use of catdata.Quad in project fql by CategoricalData.

the class LeftKanSigma method fullSigmaWithAttrs.

public static Quad<Instance, Map<Node, Map<Object, Integer>>, Map<Node, Map<Integer, Object>>, Map<Object, List<Pair<String, Object>>>> fullSigmaWithAttrs(PSMInterp inter, Mapping f, Instance i, Transform t, Instance JJJ, Integer xxx) throws FQLException {
    Mapping F = deAttr(f);
    Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> I = deAttr(inter, i, F.source);
    Integer kkk = inter.guid;
    Instance JJJ0 = null;
    Transform ttt = null;
    if (JJJ != null) {
        inter.guid = xxx;
        Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> JJJ0X = deAttr(inter, JJJ, F.target);
        Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> qqq = delta(f, F, JJJ0X);
        ttt = deAttr(f.source, I, qqq, t);
        JJJ0 = JJJ0X.first;
        inter.guid = kkk;
    }
    // System.out.println("!!!!!!!!!!!!!!!");
    LeftKan D = new LeftKan(inter.guid, F, I.first, ttt, JJJ0);
    Pair<Instance, Map<Object, List<Pair<String, Object>>>> hhh = sigma(D);
    inter.guid = D.fresh;
    Map<Node, Map<Object, Integer>> etables = makeE(D.ua);
    Instance j = hhh.first;
    Instance ret = reAttr(etables, f.target, j, I.second);
    return new Quad<>(ret, etables, D.utables, hhh.second);
}
Also used : Quad(catdata.Quad) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Mapping(catdata.fql.decl.Mapping) Transform(catdata.fql.decl.Transform) HashMap(java.util.HashMap) Map(java.util.Map) Pair(catdata.Pair)

Example 10 with Quad

use of catdata.Quad in project fql by CategoricalData.

the class InstOps method visit.

@Override
public Pair<List<PSM>, Object> visit(String dst, Plus e) {
    SigExp k = e.type(prog);
    Signature s = k.toSig(prog);
    List<PSM> ret = new LinkedList<>();
    for (Node n : s.nodes) {
        List<Flower> l = new LinkedList<>();
        l.add(new CopyFlower(e.a + "_" + n.string, "c0", "c1"));
        l.add(new CopyFlower(e.b + "_" + n.string, "c0", "c1"));
        ret.add(new InsertSQL(dst + "_" + n.string, new Union(l), "c0", "c1"));
    }
    for (Attribute<Node> n : s.attrs) {
        List<Flower> l = new LinkedList<>();
        l.add(new CopyFlower(e.a + "_" + n.name, "c0", "c1"));
        l.add(new CopyFlower(e.b + "_" + n.name, "c0", "c1"));
        ret.add(new InsertSQL(dst + "_" + n.name, new Union(l), "c0", "c1"));
    }
    for (Edge n : s.edges) {
        List<Flower> l = new LinkedList<>();
        l.add(new CopyFlower(e.a + "_" + n.name, "c0", "c1"));
        l.add(new CopyFlower(e.b + "_" + n.name, "c0", "c1"));
        ret.add(new InsertSQL(dst + "_" + n.name, new Union(l), "c0", "c1"));
    }
    ret.addAll(PSMGen.guidify(dst, s, true));
    ret.addAll(PSMGen.makeTables(dst + "_inl", s, false));
    ret.addAll(PSMGen.makeTables(dst + "_inr", s, false));
    for (Node n : s.nodes) {
        SQL f = PSMGen.compose(e.a + "_" + n.string, dst + "_" + n.string + "_subst");
        ret.add(new InsertSQL(dst + "_inl_" + n.string, f, "c0", "c1"));
        SQL f0 = PSMGen.compose(e.b + "_" + n.string, dst + "_" + n.string + "_subst");
        ret.add(new InsertSQL(dst + "_inr_" + n.string, f0, "c0", "c1"));
    }
    // (f+g) : A+B -> C f : A -> C g : B -> C
    Fn<Quad<String, String, String, String>, List<PSM>> fn = x -> {
        // e.a -> x.third
        String f = x.first;
        // e.b -> x.third
        String g = x.second;
        // String C = x.third;
        String dst0 = x.fourth;
        // must be a map dst -> x.third
        List<PSM> ret1 = new LinkedList<>();
        for (Node n : s.nodes) {
            Flower sql1 = PSMGen.compose(dst + "_" + n.string + "_subst_inv", f + "_" + n.string);
            Flower sql2 = PSMGen.compose(dst + "_" + n.string + "_subst_inv", g + "_" + n.string);
            List<Flower> flowers = new LinkedList<>();
            flowers.add(sql1);
            flowers.add(sql2);
            ret1.add(new InsertSQL(dst0 + "_" + n.string, new Union(flowers), "c0", "c1"));
        }
        return ret1;
    };
    return new Pair<>(ret, fn);
}
Also used : Inr(catdata.fql.decl.TransExp.Inr) Case(catdata.fql.decl.TransExp.Case) TransEval(catdata.fql.decl.TransExp.TransEval) Snd(catdata.fql.decl.TransExp.Snd) TransIso(catdata.fql.decl.TransExp.TransIso) Kernel(catdata.fql.decl.InstExp.Kernel) TransCurry(catdata.fql.decl.TransExp.TransCurry) Inl(catdata.fql.decl.TransExp.Inl) Coreturn(catdata.fql.decl.TransExp.Coreturn) PSMStep(catdata.fql.sql.PSMStep) CopyFlower(catdata.fql.sql.CopyFlower) Map(java.util.Map) Or(catdata.fql.decl.TransExp.Or) Squash(catdata.fql.decl.TransExp.Squash) TT(catdata.fql.decl.TransExp.TT) And(catdata.fql.decl.TransExp.And) Exp(catdata.fql.decl.InstExp.Exp) Fn(catdata.fql.Fn) Pair(catdata.Pair) Not(catdata.fql.decl.TransExp.Not) FullSigma(catdata.fql.decl.InstExp.FullSigma) PSMAnd(catdata.fql.sql.PSMAnd) Plus(catdata.fql.decl.InstExp.Plus) Quad(catdata.Quad) FullSigmaCounit(catdata.fql.sql.FullSigmaCounit) PropPSM(catdata.fql.sql.PropPSM) FullEval(catdata.fql.decl.InstExp.FullEval) Set(java.util.Set) PSMGen(catdata.fql.sql.PSMGen) FullQueryVisitor(catdata.fql.decl.FullQuery.FullQueryVisitor) Eval(catdata.fql.decl.InstExp.Eval) InsertSQL2(catdata.fql.sql.InsertSQL2) PSMUnChi(catdata.fql.sql.PSMUnChi) Times(catdata.fql.decl.InstExp.Times) Fst(catdata.fql.decl.TransExp.Fst) PSMNot(catdata.fql.sql.PSMNot) List(java.util.List) Delta(catdata.fql.decl.InstExp.Delta) ExpPSM(catdata.fql.sql.ExpPSM) TransExpVisitor(catdata.fql.decl.TransExp.TransExpVisitor) PSMBool(catdata.fql.sql.PSMBool) Triple(catdata.Triple) Flower(catdata.fql.sql.Flower) Implies(catdata.fql.decl.TransExp.Implies) Id(catdata.fql.decl.TransExp.Id) External(catdata.fql.decl.InstExp.External) InsertKeygen(catdata.fql.sql.InsertKeygen) Chi(catdata.fql.decl.TransExp.Chi) FullSigmaTrans(catdata.fql.sql.FullSigmaTrans) HashMap(java.util.HashMap) Var(catdata.fql.decl.TransExp.Var) SQL(catdata.fql.sql.SQL) FQLException(catdata.fql.FQLException) Two(catdata.fql.decl.InstExp.Two) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) PSM(catdata.fql.sql.PSM) FF(catdata.fql.decl.TransExp.FF) LinkedList(java.util.LinkedList) UnChi(catdata.fql.decl.TransExp.UnChi) SimpleCreateTable(catdata.fql.sql.SimpleCreateTable) Comp(catdata.fql.decl.TransExp.Comp) PSMIso(catdata.fql.sql.PSMIso) CreateTable(catdata.fql.sql.CreateTable) InsertValues(catdata.fql.sql.InsertValues) Prod(catdata.fql.decl.TransExp.Prod) Const(catdata.fql.decl.InstExp.Const) Relationalize(catdata.fql.decl.InstExp.Relationalize) PSMCurry(catdata.fql.sql.PSMCurry) One(catdata.fql.decl.InstExp.One) Zero(catdata.fql.decl.InstExp.Zero) Pi(catdata.fql.decl.InstExp.Pi) DropTable(catdata.fql.sql.DropTable) InstExpVisitor(catdata.fql.decl.InstExp.InstExpVisitor) Step(catdata.fql.decl.InstExp.Step) Arr(catdata.fql.cat.Arr) Return(catdata.fql.decl.TransExp.Return) InsertSQL(catdata.fql.sql.InsertSQL) Union(catdata.fql.sql.Union) Sigma(catdata.fql.decl.InstExp.Sigma) Bool(catdata.fql.decl.TransExp.Bool) PSMEval(catdata.fql.sql.PSMEval) Relationalizer(catdata.fql.sql.Relationalizer) PSMChi(catdata.fql.sql.PSMChi) Quad(catdata.Quad) CopyFlower(catdata.fql.sql.CopyFlower) Flower(catdata.fql.sql.Flower) CopyFlower(catdata.fql.sql.CopyFlower) PropPSM(catdata.fql.sql.PropPSM) ExpPSM(catdata.fql.sql.ExpPSM) PSM(catdata.fql.sql.PSM) LinkedList(java.util.LinkedList) Union(catdata.fql.sql.Union) SQL(catdata.fql.sql.SQL) InsertSQL(catdata.fql.sql.InsertSQL) InsertSQL(catdata.fql.sql.InsertSQL) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Aggregations

Quad (catdata.Quad)14 Pair (catdata.Pair)13 HashMap (java.util.HashMap)11 LinkedList (java.util.LinkedList)10 Map (java.util.Map)10 Triple (catdata.Triple)9 List (java.util.List)8 Set (java.util.Set)7 Arr (catdata.fql.cat.Arr)6 FQLException (catdata.fql.FQLException)5 Fn (catdata.fql.Fn)4 LinkedHashMap (java.util.LinkedHashMap)4 Util (catdata.Util)3 Const (catdata.fql.decl.MapExp.Const)3 Times (catdata.fql.decl.SigExp.Times)3 Paint (java.awt.Paint)3 FullQueryVisitor (catdata.fql.decl.FullQuery.FullQueryVisitor)2 Const (catdata.fql.decl.InstExp.Const)2 Delta (catdata.fql.decl.InstExp.Delta)2 Eval (catdata.fql.decl.InstExp.Eval)2