Search in sources :

Example 1 with InstConst

use of catdata.fqlpp.FunctorExp.InstConst in project fql by CategoricalData.

the class PPParser method toInstConst.

// @SuppressWarnings("rawtypes")
private static FunctorExp toInstConst(Object decl) {
    Tuple3 y = (Tuple3) decl;
    org.jparsec.functors.Pair x = (org.jparsec.functors.Pair) y.a;
    Tuple3 nodes = (Tuple3) x.a;
    Tuple3 arrows = (Tuple3) x.b;
    List nodes0 = (List) nodes.b;
    List arrows0 = (List) arrows.b;
    Map<String, SetExp> nodesX = new HashMap<>();
    for (Object o : nodes0) {
        if (nodesX.containsKey(o)) {
            throw new RuntimeException("Duplicate object: " + o + " in " + decl);
        }
        Tuple3 u = (Tuple3) o;
        String n = (String) u.a;
        SetExp l = toSet(u.c);
        nodesX.put(n, l);
    }
    Map<String, Chc<FnExp, SetExp>> arrowsX = new HashMap<>();
    for (Object o : arrows0) {
        if (arrowsX.containsKey(o)) {
            throw new RuntimeException("Duplicate arrow: " + o + " in " + decl);
        }
        Tuple3 u = (Tuple3) o;
        String n = (String) u.a;
        try {
            FnExp l = toFn(u.c);
            arrowsX.put(n, Chc.inLeft(l));
        } catch (Exception eee) {
            SetExp l = toSet(u.c);
            arrowsX.put(n, Chc.inRight(l));
        }
    }
    InstConst ret = new InstConst(toCat(y.c), nodesX, arrowsX);
    return ret;
}
Also used : HashMap(java.util.HashMap) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) InstConst(catdata.fqlpp.FunctorExp.InstConst) Pair(catdata.Pair) Chc(catdata.Chc)

Example 2 with InstConst

use of catdata.fqlpp.FunctorExp.InstConst in project fql by CategoricalData.

the class CatOps method toInstance.

private Pair<Category, Instance<String, String>> toInstance(FQLPPProgram env, InstConst ic) {
    CatExp e = resolve(env, ic.sig);
    if (!(e instanceof Const)) {
        throw new RuntimeException("Can only create instances for finitely-presented categories.");
    }
    Const c = (Const) e;
    Category src = c.accept(env, this);
    Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);
    Map<Node, Set> nm = new HashMap<>();
    for (String n0 : ic.nm.keySet()) {
        Node n = sig.getNode(n0);
        SetExp kkk = ic.nm.get(n.name);
        if (kkk == null) {
            throw new RuntimeException("Missing node mapping from " + n);
        }
        nm.put(n, kkk.accept(env, new SetOps(ENV)));
    }
    Map<Edge, Map> em = new HashMap<>();
    for (String n0 : ic.em.keySet()) {
        Edge n = sig.getEdge(n0);
        Chc<FnExp, SetExp> chc = ic.em.get(n.name);
        if (chc == null) {
            throw new RuntimeException("Missing edge mapping from " + n);
        }
        if (chc.left) {
            FnExp kkk = chc.l;
            em.put(n, kkk.accept(env, new SetOps(ENV)).toMap());
        } else {
            SetExp sss = chc.r;
            Set vvv = sss.accept(env, new SetOps(ENV));
            Map<Object, Object> uuu = new HashMap<>();
            for (Object o : vvv) {
                if (!(o instanceof Pair)) {
                    throw new RuntimeException("Not a pair: " + o);
                }
                Pair oo = (Pair) o;
                if (uuu.containsKey(oo.first)) {
                    throw new RuntimeException("Duplicate domain entry: " + o + " in " + ic);
                }
                uuu.put(oo.first, oo.second);
            }
            FnExp kkk = new FnExp.Const(uuu::get, ic.nm.get(n.source.name), ic.nm.get(n.target.name));
            em.put(n, kkk.accept(env, new SetOps(ENV)).toMap());
        }
    }
    return new Pair<>(src, new Instance(nm, em, sig));
}
Also used : FiniteCategory(catdata.fqlpp.cat.FiniteCategory) Category(catdata.fqlpp.cat.Category) ToSet(catdata.fqlpp.TransExp.ToSet) FinSet(catdata.fqlpp.cat.FinSet) SetSet(catdata.fqlpp.TransExp.SetSet) Instance(catdata.fqlpp.cat.Instance) 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) Signature(catdata.fqlpp.cat.Signature) Edge(catdata.fqlpp.cat.Signature.Edge) ToMap(catdata.fqlpp.TransExp.ToMap) Pair(catdata.Pair)

Aggregations

Pair (catdata.Pair)2 InstConst (catdata.fqlpp.FunctorExp.InstConst)2 Chc (catdata.Chc)1 Const (catdata.fqlpp.CatExp.Const)1 CatConst (catdata.fqlpp.FunctorExp.CatConst)1 FinalConst (catdata.fqlpp.FunctorExp.FinalConst)1 MapConst (catdata.fqlpp.FunctorExp.MapConst)1 SetSetConst (catdata.fqlpp.FunctorExp.SetSetConst)1 SetSet (catdata.fqlpp.TransExp.SetSet)1 ToMap (catdata.fqlpp.TransExp.ToMap)1 ToSet (catdata.fqlpp.TransExp.ToSet)1 Category (catdata.fqlpp.cat.Category)1 FinSet (catdata.fqlpp.cat.FinSet)1 FiniteCategory (catdata.fqlpp.cat.FiniteCategory)1 Instance (catdata.fqlpp.cat.Instance)1 Signature (catdata.fqlpp.cat.Signature)1 Edge (catdata.fqlpp.cat.Signature.Edge)1 Node (catdata.fqlpp.cat.Signature.Node)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1