Search in sources :

Example 11 with Tuple3

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

the class OplParser method fromBlock.

private static Block<String, String, String, String, String, String> fromBlock(Object o) {
    Tuple4<List, List, List, List> t = (Tuple4<List, List, List, List>) o;
    LinkedHashMap<String, String> from = new LinkedHashMap<>();
    Set<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new HashSet<>();
    Map<String, Chc<Agg<String, String, String, String, String, String>, OplTerm<String, String>>> attrs = new HashMap<>();
    Map<String, Pair<Object, Map<String, OplTerm<String, String>>>> edges = new HashMap<>();
    for (Object x : t.a) {
        Tuple3 l = (Tuple3) x;
        if (from.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        from.put(l.a.toString(), l.c.toString());
    }
    for (Object x : t.b) {
        Tuple3 l = (Tuple3) x;
        where.add(new Pair(toTerm(from.keySet(), null, l.a, true), toTerm(from.keySet(), null, l.c, true)));
    }
    for (Object x : t.c) {
        Tuple3 l = (Tuple3) x;
        if (attrs.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        if (l.c.toString().contains("agg") && l.c.toString().contains("{") && l.c.toString().contains("return") && l.c.toString().contains("}")) {
            attrs.put(l.a.toString(), Chc.inLeft(fromAgg(from.keySet(), null, l.c, true)));
        } else {
            attrs.put(l.a.toString(), Chc.inRight(toTerm(from.keySet(), null, l.c, true)));
        }
    }
    for (Object x : t.d) {
        Tuple5 l = (Tuple5) x;
        if (from.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        edges.put(l.a.toString(), new Pair(l.e.toString(), fromBlockHelper(from.keySet(), l.c)));
    }
    Block bl = new Block<>(from, where, attrs, edges);
    return bl;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Block(catdata.opl.OplQuery.Block) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) HashSet(java.util.HashSet) Chc(catdata.Chc)

Example 12 with Tuple3

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

the class OplParser method toCatConst.

public static XSchema toCatConst(Object y) {
    List<String> nodes = new LinkedList<>();
    List<Triple<String, String, String>> arrows = new LinkedList<>();
    List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
    Tuple3 s = (Tuple3) y;
    Tuple3 nodes0 = (Tuple3) s.a;
    Tuple3 arrows0 = (Tuple3) s.b;
    Tuple3 eqs0 = (Tuple3) s.c;
    List nodes1 = (List) nodes0.b;
    List arrows1 = (List) arrows0.b;
    List eqs1 = (List) eqs0.b;
    for (Object o : nodes1) {
        nodes.add((String) o);
    }
    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;
        List<String> l1 = (List<String>) x.a;
        List<String> l2 = (List<String>) x.c;
        eqs.add(new Pair<>(l1, l2));
    }
    XSchema c = new XSchema(nodes, arrows, eqs);
    return c;
}
Also used : LinkedList(java.util.LinkedList) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) XSchema(catdata.fpql.XExp.XSchema) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 13 with Tuple3

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

the class OplParser method toJava.

private static OplExp toJava(Object x) {
    Tuple3 t = (Tuple3) x;
    Tuple3 b = (Tuple3) t.b;
    List<Tuple3> l = (List<Tuple3>) b.b;
    Map<String, String> defs = new HashMap<>();
    for (Tuple3 k : l) {
        String f = (String) k.a;
        String body = (String) k.c;
        if (defs.containsKey(f)) {
            throw new DoNotIgnore("Duplicate symbol: " + f);
        }
        defs.put(f, body);
    }
    org.jparsec.functors.Pair c = (org.jparsec.functors.Pair) t.c;
    return new OplJavaInst(defs, (String) c.b);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OplJavaInst(catdata.opl.OplExp.OplJavaInst) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 14 with Tuple3

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

the class OplParser method toFlower.

private static OplFlower toFlower(Object c) {
    Tuple3 p = (Tuple3) c;
    // if (p.a.toString().equals("flower")) {
    String I = (String) p.c;
    Tuple3 q = (Tuple3) p.b;
    // list of tuple3 of (path, string)
    List s = (List) ((org.jparsec.functors.Pair) q.a).b;
    // list of tuple3 of (string, string)
    List f = (List) ((org.jparsec.functors.Pair) q.b).b;
    // list of tuple3 of (path, path)
    List w = (List) ((org.jparsec.functors.Pair) q.c).b;
    Map<String, OplTerm<String, String>> select = new HashMap<>();
    Map<String, String> from = new HashMap<>();
    List<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new LinkedList<>();
    Set<String> seen = new HashSet<>();
    for (Object o : f) {
        Tuple3 t = (Tuple3) o;
        String lhs = t.a.toString();
        String rhs = t.c.toString();
        if (seen.contains(rhs)) {
            throw new DoNotIgnore("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
        }
        seen.add(rhs);
        from.put(rhs, lhs);
    }
    for (Object o : w) {
        Tuple3 t = (Tuple3) o;
        OplTerm lhs = toTerm(from.keySet(), null, t.a, false);
        OplTerm rhs = toTerm(from.keySet(), null, t.c, false);
        where.add(new Pair<>(rhs, lhs));
    }
    for (Object o : s) {
        Tuple3 t = (Tuple3) o;
        OplTerm lhs = toTerm(from.keySet(), null, t.a, false);
        String rhs = t.c.toString();
        if (seen.contains(rhs)) {
            throw new DoNotIgnore("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
        }
        seen.add(rhs);
        select.put(rhs, lhs);
    }
    return new OplFlower<>(select, from, where, I);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) OplFlower(catdata.opl.OplExp.OplFlower) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 15 with Tuple3

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

the class MplParser method toExp.

private static MplExp<String, String> toExp(Object o) {
    if (o instanceof String) {
        return new MplVar<>((String) o);
    }
    if (o instanceof Tuple3) {
        Tuple3 t = (Tuple3) o;
        return new MplEval<>((String) t.b, toTerm(t.c));
    }
    if (o instanceof org.jparsec.functors.Pair) {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
        if (p.a.toString().equals("theory")) {
            return toTheory(p.b);
        }
        MplEval<String, String> ret = new MplEval<>((String) p.a, toTerm(p.b));
        return ret;
    }
    throw new RuntimeException();
// }
// return toTheory(o);
}
Also used : MplEval(catdata.mpl.Mpl.MplExp.MplEval) Tuple3(org.jparsec.functors.Tuple3) MplVar(catdata.mpl.Mpl.MplExp.MplVar) MplPair(catdata.mpl.Mpl.MplTerm.MplPair) Pair(catdata.Pair)

Aggregations

Tuple3 (org.jparsec.functors.Tuple3)90 Pair (catdata.Pair)69 List (java.util.List)57 LinkedList (java.util.LinkedList)56 Tuple5 (org.jparsec.functors.Tuple5)41 HashMap (java.util.HashMap)33 Tuple4 (org.jparsec.functors.Tuple4)32 LinkedHashMap (java.util.LinkedHashMap)17 Triple (catdata.Triple)15 HashSet (java.util.HashSet)15 XPair (catdata.fpql.XExp.XPair)11 Map (java.util.Map)10 Set (java.util.Set)6 Chc (catdata.Chc)5 Var (catdata.fqlpp.FunctorExp.Var)5 Program (catdata.Program)4 Const (catdata.fql.decl.SigExp.Const)4 Plus (catdata.fqlpp.CatExp.Plus)4 Apply (catdata.fqlpp.FunctorExp.Apply)4 Zero (catdata.fqlpp.FunctorExp.Zero)4