Search in sources :

Example 1 with OplFlower

use of catdata.opl.OplExp.OplFlower 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)

Aggregations

Pair (catdata.Pair)1 OplFlower (catdata.opl.OplExp.OplFlower)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Tuple3 (org.jparsec.functors.Tuple3)1