Search in sources :

Example 1 with Dom

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

the class PPParser method toSet.

private static SetExp toSet(Object o) {
    try {
        Tuple5 t = (Tuple5) o;
        String f = t.b.toString();
        SetExp e = toSet(t.e);
        return new SetExp.Apply(f, e);
    } catch (Exception e) {
    }
    try {
        int i = Integer.parseInt(o.toString());
        return new Numeral(i);
    } catch (Exception e) {
    }
    try {
        Tuple3<?, ?, ?> t = (Tuple3<?, ?, ?>) o;
        String y = t.b.toString();
        if (y.equals("+")) {
            return new SetExp.Plus(toSet(t.a), toSet(t.c));
        } else if (y.equals("*")) {
            return new SetExp.Times(toSet(t.a), toSet(t.c));
        } else if (y.equals("^")) {
            return new SetExp.Exp(toSet(t.a), toSet(t.c));
        } else if (y.equals("union")) {
            return new SetExp.Union(toSet(t.a), toSet(t.c));
        } else if (y.equals("intersect")) {
            return new Intersect(toSet(t.a), toSet(t.c));
        } else if (t.a.toString().equals("{")) {
            List tb = (List) t.b;
            Set x = new HashSet();
            for (Object uu : tb) {
                x.add(toValue(uu));
            }
            return new SetExp.Const(x);
        }
    } catch (RuntimeException cce) {
    }
    try {
        org.jparsec.functors.Pair<?, ?> p = (org.jparsec.functors.Pair<?, ?>) o;
        if (p.a.toString().equals("dom")) {
            return new SetExp.Dom(toFn(p.b));
        } else if (p.a.toString().equals("cod")) {
            return new SetExp.Cod(toFn(p.b));
        } else if (p.a.toString().equals("range")) {
            return new Range(toFn(p.b));
        }
    } catch (RuntimeException cce) {
    }
    try {
        if (o.toString().equals("void")) {
            return new SetExp.Zero();
        } else if (o.toString().equals("unit")) {
            return new SetExp.One();
        } else if (o.toString().equals("prop")) {
            return new SetExp.Prop();
        }
        throw new RuntimeException();
    } catch (RuntimeException cce) {
    }
    return new SetExp.Var(o.toString());
}
Also used : Numeral(catdata.fqlpp.SetExp.Numeral) Set(java.util.Set) ToSet(catdata.fqlpp.TransExp.ToSet) HashSet(java.util.HashSet) SetSet(catdata.fqlpp.TransExp.SetSet) PeterApply(catdata.fqlpp.TransExp.PeterApply) Apply(catdata.fqlpp.FunctorExp.Apply) Var(catdata.fqlpp.FunctorExp.Var) Intersect(catdata.fqlpp.SetExp.Intersect) List(java.util.List) LinkedList(java.util.LinkedList) Plus(catdata.fqlpp.CatExp.Plus) HashSet(java.util.HashSet) Pair(catdata.Pair) Zero(catdata.fqlpp.FunctorExp.Zero) Dom(catdata.fqlpp.FunctorExp.Dom) Prop(catdata.fqlpp.FunctorExp.Prop) Range(catdata.fqlpp.SetExp.Range) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Exp(catdata.fqlpp.FunctorExp.Exp)

Example 2 with Dom

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

the class PPParser method toCat.

private static CatExp toCat(Object o) {
    if (o.toString().equals("Set")) {
        return new Named("Set");
    }
    if (o.toString().equals("Cat")) {
        return new Named("Cat");
    }
    if (o instanceof Tuple4) {
        Tuple4 t = (Tuple4) o;
        return new Kleisli(t.b.toString(), t.c.toString(), t.d.toString(), t.a.toString().equals("cokleisli"));
    }
    try {
        Tuple3<?, ?, ?> t = (Tuple3<?, ?, ?>) o;
        String y = t.b.toString();
        if (y.equals("+")) {
            return new Plus(toCat(t.a), toCat(t.c));
        } else if (y.equals("*")) {
            return new Times(toCat(t.a), toCat(t.c));
        } else if (y.equals("^")) {
            return new CatExp.Exp(toCat(t.a), toCat(t.c));
        } else if (t.a.toString().equals("union")) {
            return new Union(toCat(t.b), toCat(t.c));
        } else {
            return toCatConst(o);
        }
    } catch (RuntimeException cce) {
    }
    try {
        org.jparsec.functors.Pair<?, ?> p = (org.jparsec.functors.Pair<?, ?>) o;
        if (p.a.toString().equals("dom")) {
            return new CatExp.Dom(toFtr(p.b));
        } else if (p.a.toString().equals("cod")) {
            return new Cod(toFtr(p.b));
        } else if (p.a.toString().equals("colim")) {
            return new Colim((String) p.b);
        }
    } catch (RuntimeException cce) {
    }
    try {
        if (o.toString().equals("void")) {
            return new CatExp.Zero();
        } else if (o.toString().equals("unit")) {
            return new CatExp.One();
        }
    } catch (RuntimeException cce) {
    }
    return new CatExp.Var(o.toString());
}
Also used : Colim(catdata.fqlpp.CatExp.Colim) Named(catdata.fqlpp.CatExp.Named) Zero(catdata.fqlpp.FunctorExp.Zero) Dom(catdata.fqlpp.FunctorExp.Dom) Var(catdata.fqlpp.FunctorExp.Var) Union(catdata.fqlpp.CatExp.Union) Tuple4(org.jparsec.functors.Tuple4) Kleisli(catdata.fqlpp.CatExp.Kleisli) Tuple3(org.jparsec.functors.Tuple3) Times(catdata.fqlpp.CatExp.Times) Cod(catdata.fqlpp.CatExp.Cod) Plus(catdata.fqlpp.CatExp.Plus) Exp(catdata.fqlpp.FunctorExp.Exp) Pair(catdata.Pair)

Example 3 with Dom

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

the class PPParser method toFtr.

private static FunctorExp toFtr(Object o) {
    try {
        Tuple5 p = (Tuple5) o;
        if (p.a.toString().equals("apply")) {
            FunctorExp f = toFtr(p.b);
            FunctorExp e = toFtr(p.e);
            return new Apply(f, e);
        }
        if (p.e.toString().equals("Set")) {
            return p.c.toString().equals("Set") ? toSetSet(o) : toInstConst(o);
        } else if (p.e.toString().equals("Cat")) {
            return toCatFtrConst(o);
        } else {
            if (p.e instanceof Tuple3) {
                Tuple3 t = (Tuple3) p.e;
                if ((t.a.toString().equals("Cat") || t.a.toString().equals("Set")) && t.b.toString().equals("^")) {
                    return toFinalConst(o);
                } else {
                    throw new RuntimeException();
                }
            }
            return toMapConst(o);
        }
    } catch (Exception e) {
    }
    try {
        Tuple3 p = (Tuple3) o;
        Object p2 = p.b;
        Object p3 = p.c;
        Object o1 = p.a;
        String p1 = p.a.toString();
        if (p1.equals("fst")) {
            return new Fst(toCat(p2), toCat(p3));
        } else if (p1.equals("snd")) {
            return new Snd(toCat(p2), toCat(p3));
        } else if (p1.equals("inl")) {
            return new Inl(toCat(p2), toCat(p3));
        } else if (p1.equals("inr")) {
            return new Inr(toCat(p2), toCat(p3));
        } else if (p1.equals("iso1")) {
            return new Iso(true, toCat(p2), toCat(p3));
        } else if (p1.equals("iso2")) {
            return new Iso(false, toCat(p2), toCat(p3));
        } else if (p1.equals("eval")) {
            return new Eval(toCat(p2), toCat(p3));
        } else if (p2.toString().equals(";")) {
            return new Comp(toFtr(o1), toFtr(p3));
        } else if (p2.toString().equals("*")) {
            return new Prod(toFtr(o1), toFtr(p3));
        } else if (p2.toString().equals("+")) {
            return new Case(toFtr(o1), toFtr(p3));
        } else if (p2.toString().equals("^")) {
            return new Exp(toFtr(o1), toFtr(p3));
        } else if (p1.equals("unit")) {
            return new One(toCat(p.b), toCat(p.c));
        } else if (p1.equals("void")) {
            return new Zero(toCat(p.b), toCat(p.c));
        } else if (p1.equals("pushout")) {
            return new Pushout(p.b.toString(), p.c.toString());
        }
    } catch (RuntimeException re) {
    }
    try {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
        String p1 = p.a.toString();
        Object p2 = p.b;
        switch(p1) {
            case "id":
                return new Id(toCat(p2));
            case "prop":
                return new Prop(toCat(p2));
            case "curry":
                return new Curry(toFtr(p2));
            case "uncurry":
                return new Uncurry(toFtr(p2));
            case "delta":
            case "sigma":
            case "pi":
                return new Migrate(toFtr(p2), p1);
            case "ff":
                return new FF(toCat(p2));
            case "tt":
                return new TT(toCat(p2));
            case "dom":
                return new Dom(p2.toString(), true);
            case "cod":
                return new Dom(p2.toString(), false);
            case "pivot":
                return new Pivot(toFtr(p2), true);
            case "unpivot":
                return new Pivot(toFtr(p2), false);
            default:
                break;
        }
    } catch (RuntimeException re) {
    }
    if (o instanceof String) {
        return new Var(o.toString());
    }
    throw new RuntimeException("Bad: " + o);
}
Also used : Curry(catdata.fqlpp.FunctorExp.Curry) FF(catdata.fqlpp.FunctorExp.FF) TT(catdata.fqlpp.FunctorExp.TT) PeterApply(catdata.fqlpp.TransExp.PeterApply) Apply(catdata.fqlpp.FunctorExp.Apply) Inl(catdata.fqlpp.FunctorExp.Inl) Migrate(catdata.fqlpp.FunctorExp.Migrate) Var(catdata.fqlpp.FunctorExp.Var) One(catdata.fqlpp.FunctorExp.One) Snd(catdata.fqlpp.FunctorExp.Snd) Pushout(catdata.fqlpp.FunctorExp.Pushout) Inr(catdata.fqlpp.FunctorExp.Inr) Comp(catdata.fqlpp.FunctorExp.Comp) Case(catdata.fqlpp.FunctorExp.Case) Prod(catdata.fqlpp.FunctorExp.Prod) CoProd(catdata.fqlpp.TransExp.CoProd) Eval(catdata.fqlpp.FunctorExp.Eval) Pair(catdata.Pair) Zero(catdata.fqlpp.FunctorExp.Zero) Dom(catdata.fqlpp.FunctorExp.Dom) Iso(catdata.fqlpp.FunctorExp.Iso) Prop(catdata.fqlpp.FunctorExp.Prop) Fst(catdata.fqlpp.FunctorExp.Fst) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Pivot(catdata.fqlpp.FunctorExp.Pivot) Id(catdata.fqlpp.FunctorExp.Id) Exp(catdata.fqlpp.FunctorExp.Exp) Uncurry(catdata.fqlpp.FunctorExp.Uncurry)

Aggregations

Pair (catdata.Pair)3 Dom (catdata.fqlpp.FunctorExp.Dom)3 Exp (catdata.fqlpp.FunctorExp.Exp)3 Var (catdata.fqlpp.FunctorExp.Var)3 Zero (catdata.fqlpp.FunctorExp.Zero)3 Tuple3 (org.jparsec.functors.Tuple3)3 Plus (catdata.fqlpp.CatExp.Plus)2 Apply (catdata.fqlpp.FunctorExp.Apply)2 Prop (catdata.fqlpp.FunctorExp.Prop)2 PeterApply (catdata.fqlpp.TransExp.PeterApply)2 Tuple5 (org.jparsec.functors.Tuple5)2 Cod (catdata.fqlpp.CatExp.Cod)1 Colim (catdata.fqlpp.CatExp.Colim)1 Kleisli (catdata.fqlpp.CatExp.Kleisli)1 Named (catdata.fqlpp.CatExp.Named)1 Times (catdata.fqlpp.CatExp.Times)1 Union (catdata.fqlpp.CatExp.Union)1 Case (catdata.fqlpp.FunctorExp.Case)1 Comp (catdata.fqlpp.FunctorExp.Comp)1 Curry (catdata.fqlpp.FunctorExp.Curry)1