Search in sources :

Example 11 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class ToJdbcPragmaInstance method deleteThenCreate.

private void deleteThenCreate(Connection conn) throws SQLException {
    Map<En, Triple<List<Chc<Fk, Att>>, List<String>, List<String>>> m = I.schema().toSQL(prefix, "integer", "id", truncate, Object::toString, len);
    Statement stmt = conn.createStatement();
    for (En en : I.schema().ens) {
        for (String x : m.get(en).second) {
            // TODO aql drop foreign keys here first
            // System.out.println(x);
            // .replace("Varchar", "Varchar(" + len + ")").replace("Nvarchar", "Nvarchar(" + len + ")").replace("varchar", "Varchar(" + len + ")"));
            stmt.execute(x);
        }
    }
    stmt.close();
}
Also used : Triple(catdata.Triple) Statement(java.sql.Statement) Chc(catdata.Chc)

Example 12 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class CatOps method visit.

@Override
public Functor visit(FQLPPProgram env, MapConst ic) {
    Triple<Category, Category, Mapping<String, String, String, String>> xxx = toMapping(env, ic);
    Mapping<String, String, String, String> I = xxx.third;
    FUNCTION f = p0 -> {
        Path p = (Path) p0;
        return I.apply(p);
    };
    Functor et = new Functor(xxx.first, xxx.second, x -> I.nm.get(x), f);
    et.mapping0 = xxx.third;
    return et;
}
Also used : PeterApply(catdata.fqlpp.TransExp.PeterApply) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Named(catdata.fqlpp.CatExp.Named) Edge(catdata.fqlpp.cat.Signature.Edge) Snd(catdata.fqlpp.FunctorExp.Snd) Comp(catdata.fqlpp.FunctorExp.Comp) ToInst(catdata.fqlpp.TransExp.ToInst) Id(catdata.fqlpp.FunctorExp.Id) Inr(catdata.fqlpp.FunctorExp.Inr) FF(catdata.fqlpp.FunctorExp.FF) Migrate(catdata.fqlpp.FunctorExp.Migrate) Colim(catdata.fqlpp.CatExp.Colim) Exp(catdata.fqlpp.CatExp.Exp) Pushout(catdata.fqlpp.FunctorExp.Pushout) FinCat(catdata.fqlpp.cat.FinCat) FunCat(catdata.fqlpp.cat.FunCat) Pair(catdata.Pair) CoMonad(catdata.fqlpp.cat.CoMonad) Iso(catdata.fqlpp.FunctorExp.Iso) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Inj(catdata.fqlpp.TransExp.Inj) Fn(catdata.fqlpp.cat.FinSet.Fn) Bool(catdata.fqlpp.TransExp.Bool) Case(catdata.fqlpp.FunctorExp.Case) ToMap(catdata.fqlpp.TransExp.ToMap) Zero(catdata.fqlpp.CatExp.Zero) Monad(catdata.fqlpp.cat.Monad) Plus(catdata.fqlpp.CatExp.Plus) Category(catdata.fqlpp.cat.Category) CatConst(catdata.fqlpp.FunctorExp.CatConst) Inst(catdata.fqlpp.cat.Inst) ToSet(catdata.fqlpp.TransExp.ToSet) Groth(catdata.fqlpp.cat.Groth) Mapping(catdata.fqlpp.cat.Mapping) Serializable(java.io.Serializable) Kleisli(catdata.fqlpp.CatExp.Kleisli) ApplyTrans(catdata.fqlpp.TransExp.ApplyTrans) SetSetConst(catdata.fqlpp.FunctorExp.SetSetConst) Dom(catdata.fqlpp.CatExp.Dom) Triple(catdata.Triple) Eval(catdata.fqlpp.FunctorExp.Eval) Var(catdata.fqlpp.FunctorExp.Var) Times(catdata.fqlpp.CatExp.Times) Const(catdata.fqlpp.CatExp.Const) java.util(java.util) Prod(catdata.fqlpp.FunctorExp.Prod) InstConst(catdata.fqlpp.FunctorExp.InstConst) Node(catdata.fqlpp.cat.Signature.Node) Chc(catdata.Chc) TT(catdata.fqlpp.FunctorExp.TT) Functor(catdata.fqlpp.cat.Functor) Proj(catdata.fqlpp.TransExp.Proj) Prop(catdata.fqlpp.FunctorExp.Prop) CatExpVisitor(catdata.fqlpp.CatExp.CatExpVisitor) Signature(catdata.fqlpp.cat.Signature) TransExpVisitor(catdata.fqlpp.TransExp.TransExpVisitor) Union(catdata.fqlpp.CatExp.Union) ToCat(catdata.fqlpp.TransExp.ToCat) One(catdata.fqlpp.CatExp.One) FDM(catdata.fqlpp.cat.FDM) Ker(catdata.fqlpp.TransExp.Ker) Fst(catdata.fqlpp.FunctorExp.Fst) Whisker(catdata.fqlpp.TransExp.Whisker) Curry(catdata.fqlpp.FunctorExp.Curry) Transform(catdata.fqlpp.cat.Transform) Apply(catdata.fqlpp.FunctorExp.Apply) Instance(catdata.fqlpp.cat.Instance) MapConst(catdata.fqlpp.FunctorExp.MapConst) Path(catdata.fqlpp.cat.Signature.Path) Pivot(catdata.fqlpp.FunctorExp.Pivot) Chr(catdata.fqlpp.TransExp.Chr) Cod(catdata.fqlpp.CatExp.Cod) FinSet(catdata.fqlpp.cat.FinSet) Uncurry(catdata.fqlpp.FunctorExp.Uncurry) FunctorExpVisitor(catdata.fqlpp.FunctorExp.FunctorExpVisitor) Adj(catdata.fqlpp.TransExp.Adj) SetSet(catdata.fqlpp.TransExp.SetSet) AndOrNotImplies(catdata.fqlpp.TransExp.AndOrNotImplies) FinalConst(catdata.fqlpp.FunctorExp.FinalConst) Inl(catdata.fqlpp.FunctorExp.Inl) CoProd(catdata.fqlpp.TransExp.CoProd) ApplyPath(catdata.fqlpp.TransExp.ApplyPath) Path(catdata.fqlpp.cat.Signature.Path) FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) Mapping(catdata.fqlpp.cat.Mapping) Functor(catdata.fqlpp.cat.Functor)

Example 13 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class FDM method deltaPi.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static <O1, A1, O2, A2> Adjunction<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>, Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> deltaPi(Functor<O2, A2, O1, A1> F) {
    Category<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> D = Inst.get(F.source);
    Category<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> C = Inst.get(F.target);
    FUNCTION<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> f = I -> {
        Triple<Functor<O1, A1, Set, Fn>, Map<O1, Set<Map>>, Map<O1, Triple<O1, O2, A1>[]>> xxx = Pi.pi(F, Functor.compose(F, I));
        FUNCTION<O1, Fn> j = n -> new Fn<>(I.applyO(n), xxx.first.applyO(n), i -> {
            outer: for (Map m : xxx.second.get(n)) {
                for (int p = 1; p < m.size(); p++) {
                    if (xxx.third.get(n)[p - 1].third.equals(F.target.identity(n))) {
                        if (!m.get(p).equals(i)) {
                            continue outer;
                        }
                    }
                }
                return m.get(0);
            }
            throw new RuntimeException("Cannot find diagonal of " + i + " in " + xxx.second.get(n));
        });
        return new Transform<>(I, xxx.first, j);
    };
    Transform<Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>, Functor<O1, A1, Set, Fn>, Transform<O1, A1, Set, Fn>> unit = new Transform<>(Functor.identity(C), Functor.compose(deltaF(F), piF(F)), f);
    FUNCTION<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> g = I -> {
        Triple<Functor<O1, A1, Set, Fn>, Map<O1, Set<Map>>, Map<O1, Triple<O1, O2, A1>[]>> xxx = Pi.pi(F, I);
        Functor<O2, A2, Set, Fn> deltad = Functor.compose(F, xxx.first);
        FUNCTION<O2, Fn> j = m -> {
            O1 n = F.applyO(m);
            Triple<O1, O2, A1>[] col = xxx.third.get(n);
            Triple<O1, O2, A1> tofind = new Triple<>(n, m, F.target.identity(n));
            Set<Map> lim = xxx.second.get(n);
            int[] i = new int[] { 0 };
            for (Triple<O1, O2, A1> cand : col) {
                if (!cand.equals(tofind)) {
                    i[0]++;
                    continue;
                }
                FUNCTION h = id -> {
                    for (Map row : lim) {
                        if (row.get(0).equals(id)) {
                            return row.get(i[0] + 1);
                        }
                    }
                    throw new RuntimeException("Report this error to Ryan.");
                };
                return new Fn<>(deltad.applyO(m), I.applyO(m), h);
            }
            throw new RuntimeException("Report this error to Ryan.");
        };
        return new Transform<>(deltad, I, j);
    };
    Transform<Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>, Functor<O2, A2, Set, Fn>, Transform<O2, A2, Set, Fn>> counit = new Transform<>(Functor.compose(piF(F), deltaF(F)), Functor.identity(D), g);
    return new Adjunction<>(deltaF(F), sigmaF(F), counit, unit);
}
Also used : Fn(catdata.fqlpp.cat.FinSet.Fn) List(java.util.List) Quad(catdata.Quad) FUNCTION(catdata.fqlpp.FUNCTION) Map(java.util.Map) Triple(catdata.Triple) Set(java.util.Set) HashMap(java.util.HashMap) Pair(catdata.Pair) Set(java.util.Set) Fn(catdata.fqlpp.cat.FinSet.Fn) FUNCTION(catdata.fqlpp.FUNCTION) Triple(catdata.Triple) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class FqlppDisplay method doElementsView.

private static JComponent doElementsView(Color clr, Graph<Pair, Triple> sgv) {
    Layout<Pair, Triple> layout = new FRLayout<>(sgv);
    layout.setSize(new Dimension(600, 400));
    VisualizationViewer<Pair, Triple> vv = new VisualizationViewer<>(layout);
    Function<Pair, Paint> vertexPaint = z -> clr;
    DefaultModalGraphMouse<String, String> gm = new DefaultModalGraphMouse<>();
    gm.setMode(Mode.TRANSFORMING);
    vv.setGraphMouse(gm);
    gm.setMode(Mode.PICKING);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    Function<Pair, String> ttt1 = arg0 -> Util.nice(arg0.second.toString());
    vv.getRenderContext().setVertexLabelTransformer(ttt1);
    Function<Triple, String> ttt2 = arg0 -> Util.nice(arg0.first.toString());
    vv.getRenderContext().setEdgeLabelTransformer(ttt2);
    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) 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) Triple(catdata.Triple) GridLayout(java.awt.GridLayout) VisualizationViewer(edu.uci.ics.jung.visualization.VisualizationViewer) Pair(catdata.Pair)

Example 15 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class Relationalizer method terminal.

public static Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> terminal(FQLProgram prog, SigExp.Const sig0) {
    Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> jjj = cache.get(new Pair<>(prog, sig0));
    if (jjj != null) {
        // so do not have to recompute when doing omega operations
        return jjj;
    }
    try {
        Signature sig = sig0.toSig(prog);
        Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> start = sig.toCategory2();
        // FinCat<Node, Path> cat = start.first;
        Fn<Path, Arr<Node, Path>> map = start.second;
        Map<Node, List<Pair<Arr<Node, Path>, Attribute<Node>>>> obs = sig.obs();
        Map<Node, List<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m = sig.obsbar();
        List<Pair<String, List<Pair<Object, Object>>>> nodes = new LinkedList<>();
        List<Pair<String, List<Pair<Object, Object>>>> attrs = new LinkedList<>();
        List<Pair<String, List<Pair<Object, Object>>>> arrows = new LinkedList<>();
        // Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
        Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m1 = new HashMap<>();
        Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>> m2 = new HashMap<>();
        int i = 0;
        for (Node n : sig.nodes) {
            Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> map1 = new HashMap<>();
            Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object> map2 = new HashMap<>();
            List<Pair<Object, Object>> set = new LinkedList<>();
            m1.put(n, map1);
            m2.put(n, map2);
            for (LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> i2 : m.get(n)) {
                Object o = Integer.toString(++i);
                map1.put(o, i2);
                map2.put(i2, o);
                set.add(new Pair<>(o, o));
            }
            nodes.add(new Pair<>(n.string, set));
        }
        for (Attribute<Node> a : sig.attrs) {
            List<Pair<Object, Object>> set = new LinkedList<>();
            for (Pair<Object, Object> k : PropPSM.lookup(nodes, a.source.string)) {
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = m1.get(a.source).get(k.first);
                set.add(new Pair<>(k.first, new_id.get(new Pair<>(map.of(new Path(sig, a.source)), a))));
            }
            attrs.add(new Pair<>(a.name, set));
        }
        for (Edge a : sig.edges) {
            List<Pair<Object, Object>> set = new LinkedList<>();
            for (Pair<Object, Object> k : PropPSM.lookup(nodes, a.source.string)) {
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = m1.get(a.source).get(k.first);
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = PropPSM.truncate2(sig, new_id, new Arr<>(new Path(sig, a), a.source, a.target), obs.get(a.target));
                // LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = PropPSM.truncate(sig, new_id, a, m.get(a.target));
                Object o = m2.get(a.target).get(new_id0);
                set.add(new Pair<>(k.first, o));
            }
            arrows.add(new Pair<>(a.name, set));
        }
        // Instance ret0 = new Instance(sig, data);
        Const retX = new Const(nodes, attrs, arrows, sig.toConst());
        Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> ret = new Triple<>(retX, m1, m2);
        cache.put(new Pair<>(prog, sig0), ret);
        return ret;
    } catch (FQLException fe) {
        throw new RuntimeException(fe.getLocalizedMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Attribute(catdata.fql.decl.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FinCat(catdata.fql.cat.FinCat) Node(catdata.fql.decl.Node) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Path(catdata.fql.decl.Path) Const(catdata.fql.decl.InstExp.Const) Fn(catdata.fql.Fn) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Signature(catdata.fql.decl.Signature) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Edge(catdata.fql.decl.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