Search in sources :

Example 16 with Tuple5

use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.

the class XParser method fromSuperSoed.

/*
	J = soed {
		exists f:A->B, g:C->D;
		forall a:A, a.f = p.q, a.g = p.f;
		forall b:B, p = q; 
	} : X -> Y on I
		 */
private static XSuperED fromSuperSoed(Object ooo) {
    org.jparsec.functors.Pair ooo1 = (org.jparsec.functors.Pair) ooo;
    Tuple4 a = (Tuple4) ooo1.a;
    // List<Triple<String, List<String>, String>> es = new LinkedList<>();
    List<SuperFOED> as = new LinkedList<>();
    Map<String, List<String>> dom = new HashMap<>();
    Map<String, String> cod = new HashMap<>();
    List<Tuple5> es0 = (List<Tuple5>) a.b;
    for (Tuple5 t : es0) {
        if (dom.keySet().contains(t.a)) {
            throw new RuntimeException("Duplicate function name " + t.a);
        }
        dom.put((String) t.a, (List<String>) t.c);
        cod.put((String) t.a, (String) t.e);
    }
    List<Tuple4> as0 = (List<Tuple4>) a.d;
    for (Tuple4 t : as0) {
        List<Tuple3> aas = (List<Tuple3>) t.b;
        Map<String, String> aa = new HashMap<>();
        for (Tuple3 xxx : aas) {
            if (aa.containsKey(xxx.a)) {
                throw new RuntimeException("Duplicate var " + xxx.a);
            }
            aa.put((String) xxx.a, (String) xxx.c);
        }
        Tuple3 td = (Tuple3) t.d;
        List<Tuple3> lhss = (List<Tuple3>) td.a;
        List<Tuple3> rhss = (List<Tuple3>) td.c;
        List<Pair<Triple<String, List<List<String>>, List<String>>, Triple<String, List<List<String>>, List<String>>>> cc = new LinkedList<>();
        List<Pair<Triple<String, List<List<String>>, List<String>>, Triple<String, List<List<String>>, List<String>>>> bb = new LinkedList<>();
        for (Tuple3 o : lhss) {
            bb.add(new Pair<>(fromBulb(o.a), fromBulb(o.c)));
        }
        for (Tuple3 o : rhss) {
            cc.add(new Pair<>(fromBulb(o.a), fromBulb(o.c)));
        }
        as.add(new SuperFOED(aa, bb, cc));
    }
    Tuple4 b = (Tuple4) ooo1.b;
    String src = (String) b.b;
    String dst = (String) b.c;
    String i = (String) b.d;
    // es, as, src, dst, i);
    XSuperED ret = new XSuperED(dom, cod, as, src, dst, i);
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) XSuperED(catdata.fpql.XExp.XSuperED) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) SuperFOED(catdata.fpql.XExp.XSuperED.SuperFOED) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) XPair(catdata.fpql.XExp.XPair)

Example 17 with Tuple5

use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.

the class XRaToFpql method toEInsertValues.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static EInsertValues toEInsertValues(Object decl) {
    Tuple5 t = (Tuple5) decl;
    String target = t.b.toString();
    List<Tuple3> x = (List<Tuple3>) t.d;
    List<List<String>> values = new LinkedList<>();
    for (Tuple3 y : x) {
        List<String> l = (List<String>) y.b;
        values.add(l);
    }
    return new EInsertValues(target, values);
}
Also used : Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3)

Example 18 with Tuple5

use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.

the class FQLParser method toMapping.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static MapExp toMapping(Object o) {
    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(toSchema(p2), toSchema(p3));
        } else if (p1.equals("snd")) {
            return new Snd(toSchema(p2), toSchema(p3));
        } else if (p1.equals("unit")) {
            return new TT(toSchema(p3), new HashSet<>((Collection<String>) p2));
        } else if (p1.equals("subschema")) {
            return new Sub(toSchema(p2), toSchema(p3));
        } else if (p1.equals("inl")) {
            return new Inl(toSchema(p2), toSchema(p3));
        } else if (p1.equals("inr")) {
            return new Inr(toSchema(p2), toSchema(p3));
        } else if (p1.equals("iso1")) {
            return new Iso(true, toSchema(p2), toSchema(p3));
        } else if (p1.equals("iso2")) {
            return new Iso(false, toSchema(p2), toSchema(p3));
        } else if (p1.equals("eval")) {
            return new Apply(toSchema(p2), toSchema(p3));
        } else if (p2.toString().equals("then")) {
            return new MapExp.Comp(toMapping(o1), toMapping(p3));
        } else if (p2.toString().equals("*")) {
            return new Prod(toMapping(o1), toMapping(p3));
        } else if (p2.toString().equals("+")) {
            return new Case(toMapping(o1), toMapping(p3));
        }
    } catch (RuntimeException re) {
    }
    if (o instanceof Tuple5) {
        Tuple5 p = (Tuple5) o;
        Object p2 = p.c;
        Object p3 = p.e;
        Object o1 = p.a;
        return toMapConst(o1, toSchema(p2), toSchema(p3));
    }
    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(toSchema(p2));
            case "curry":
                return new Curry(toMapping(p2));
            case "void":
                return new FF(toSchema(p2));
            case "opposite":
                return new Opposite(toMapping(p2));
            default:
                break;
        }
    } catch (RuntimeException re) {
    }
    if (o instanceof String) {
        return new MapExp.Var(o.toString());
    }
    throw new RuntimeException("Cannot parse " + o);
}
Also used : TT(catdata.fql.decl.MapExp.TT) TransCurry(catdata.fql.decl.TransExp.TransCurry) Curry(catdata.fql.decl.MapExp.Curry) FF(catdata.fql.decl.MapExp.FF) Inl(catdata.fql.decl.MapExp.Inl) Apply(catdata.fql.decl.MapExp.Apply) Var(catdata.fql.decl.FullQueryExp.Var) Snd(catdata.fql.decl.MapExp.Snd) Inr(catdata.fql.decl.MapExp.Inr) Case(catdata.fql.decl.MapExp.Case) Prod(catdata.fql.decl.MapExp.Prod) Pair(catdata.Pair) Opposite(catdata.fql.decl.MapExp.Opposite) Sub(catdata.fql.decl.MapExp.Sub) TransIso(catdata.fql.decl.TransExp.TransIso) Iso(catdata.fql.decl.MapExp.Iso) Fst(catdata.fql.decl.MapExp.Fst) MapExp(catdata.fql.decl.MapExp) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Id(catdata.fql.decl.MapExp.Id)

Example 19 with Tuple5

use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.

the class XSqlToFql method toECreateTable.

@SuppressWarnings("rawtypes")
private static ECreateTable toECreateTable(Object decl) {
    Tuple4 t = (Tuple4) decl;
    String name = t.c.toString();
    Tuple3 t0 = (Tuple3) t.d;
    List t1 = (List) t0.b;
    List<Pair<String, String>> types = new LinkedList<>();
    List<Pair<String, String>> fks = new LinkedList<>();
    for (Object o : t1) {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
        if (p.a.toString().equals("FOREIGN")) {
            Tuple5 x = (Tuple5) o;
            Tuple3 y = (Tuple3) x.b;
            fks.add(new Pair<>(y.b.toString(), x.d.toString()));
        } else {
            // if (p.a.toString().toLowerCase().equals("id")) {
            types.add(new Pair<>(p.a.toString(), p.b.toString()));
        // } else {
        // types.add(new Pair<>(name + "_" + p.a.toString(), p.b.toString()));
        // }
        }
    }
    return new ECreateTable(name, types, fks);
}
Also used : LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) LinkedList(java.util.LinkedList) List(java.util.List) Pair(catdata.Pair)

Example 20 with Tuple5

use of org.jparsec.functors.Tuple5 in project fql by CategoricalData.

the class FQLParser method toSchemaConst.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static SigExp toSchemaConst(Object y) {
    List<String> nodes = new LinkedList<>();
    List<Triple<String, String, String>> attrs = new LinkedList<>();
    List<Triple<String, String, String>> arrows = new LinkedList<>();
    List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
    Tuple4 s = (Tuple4) y;
    Tuple3 nodes0 = (Tuple3) s.a;
    Tuple3 attrs0 = (Tuple3) s.b;
    Tuple3 arrows0 = (Tuple3) s.c;
    Tuple3 eqs0 = (Tuple3) s.d;
    List nodes1 = (List) nodes0.b;
    List arrows1 = (List) arrows0.b;
    List eqs1 = (List) eqs0.b;
    for (Object o : nodes1) {
        nodes.add((String) o);
    }
    if (attrs0.b.toString().equals("ASWRITTEN")) {
        for (String k : nodes) {
            attrs.add(new Triple<>(k + "_att", k, "string"));
        }
    } else {
        List attrs1 = (List) attrs0.b;
        for (Object o : attrs1) {
            Tuple5 x = (Tuple5) o;
            attrs.add(new Triple<>((String) x.a, (String) x.c, (String) x.e));
        }
    }
    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;
        eqs.add(new Pair<>((List<String>) x.a, (List<String>) x.c));
    }
    Const c = new Const(nodes, attrs, arrows, eqs);
    return c;
}
Also used : Const(catdata.fql.decl.SigExp.Const) Triple(catdata.Triple) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Pair(catdata.Pair)

Aggregations

Tuple5 (org.jparsec.functors.Tuple5)47 Tuple3 (org.jparsec.functors.Tuple3)41 Pair (catdata.Pair)36 LinkedList (java.util.LinkedList)36 List (java.util.List)36 HashMap (java.util.HashMap)21 Tuple4 (org.jparsec.functors.Tuple4)20 Triple (catdata.Triple)10 HashSet (java.util.HashSet)10 LinkedHashMap (java.util.LinkedHashMap)10 XPair (catdata.fpql.XExp.XPair)9 Map (java.util.Map)8 Set (java.util.Set)5 Apply (catdata.fqlpp.FunctorExp.Apply)4 Var (catdata.fqlpp.FunctorExp.Var)4 PeterApply (catdata.fqlpp.TransExp.PeterApply)4 Pair (org.jparsec.functors.Pair)4 XSchema (catdata.fpql.XExp.XSchema)3 Plus (catdata.fqlpp.CatExp.Plus)3 Program (catdata.Program)2