Search in sources :

Example 66 with Tuple3

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

the class SqlChecker method toEdge.

@SuppressWarnings("rawtypes")
private static Pair<String, List<Pair<String, String>>> toEdge(Object a) {
    Tuple4 t = (Tuple4) a;
    String n = (String) t.b;
    List z = (List) t.d;
    List<Pair<String, String>> y = new LinkedList<>();
    for (Object q : z) {
        Tuple3 q2 = (Tuple3) q;
        Pair<String, String> pair = new Pair<>(((String) q2.a).toUpperCase(), ((String) q2.c).toUpperCase());
        y.add(pair);
    }
    Pair<String, List<Pair<String, String>>> u = new Pair<>(n.toUpperCase(), y);
    return u;
}
Also used : Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) JList(javax.swing.JList) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 67 with Tuple3

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

the class SqlChecker method toPath.

@SuppressWarnings("rawtypes")
private static Triple<String, List<Pair<String, List<Pair<String, String>>>>, List<Pair<String, String>>> toPath(Object ox) {
    Tuple3 o = (Tuple3) ox;
    String start = (String) o.a;
    List l = (List) o.b;
    List<Pair<String, List<Pair<String, String>>>> x = new LinkedList<>();
    for (Object a : l) {
        x.add(toEdge(a));
    }
    Set<String> seen = new HashSet<>();
    List<Pair<String, String>> y = null;
    org.jparsec.functors.Pair qq = (org.jparsec.functors.Pair) o.c;
    if (qq != null) {
        y = new LinkedList<>();
        List z = (List) qq.b;
        for (Object q : z) {
            Tuple3 q2 = (Tuple3) q;
            Pair<String, String> pair = new Pair<>(((String) q2.a).toUpperCase(), ((String) q2.c).toUpperCase());
            if (seen.contains(pair.second)) {
                throw new RuntimeException("Duplicate col: " + pair.second);
            }
            seen.add(pair.second);
            y.add(pair);
        }
    }
    return new Triple<>(start.toUpperCase(), x, y);
}
Also used : LinkedList(java.util.LinkedList) Triple(catdata.Triple) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) JList(javax.swing.JList) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 68 with Tuple3

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

the class OplParser method fromBlock2.

private static Block<String, String, String, String, String, String> fromBlock2(Object o) {
    Tuple3<List, List, List> t = (Tuple3<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<>();
    // from
    for (Object x : (Iterable) ((org.jparsec.functors.Pair) t.b).b) {
        org.jparsec.functors.Pair l = (org.jparsec.functors.Pair) x;
        String gen;
        String ty;
        if (l.b == null) {
            gen = (String) l.a;
            ty = (String) l.a;
        } else {
            org.jparsec.functors.Pair g = (org.jparsec.functors.Pair) l.b;
            gen = (String) g.b;
            ty = (String) l.a;
        }
        if (from.containsKey(gen)) {
            throw new DoNotIgnore("In from clause, duplicate for: " + gen);
        }
        from.put(gen, ty);
    }
    // Object z = ((org.jparsec.functors.Pair)t.c).b;
    if (t.c != null) {
        for (Object x : (Iterable) ((org.jparsec.functors.Pair) t.c).b) {
            Tuple3 l = (Tuple3) x;
            where.add(new Pair(toTerm(from.keySet(), null, l.a, true), toTerm(from.keySet(), null, l.c, true)));
        }
    }
    // return
    for (Object x : (Iterable) ((org.jparsec.functors.Pair) t.a).b) {
        Tuple3 l = (Tuple3) x;
        String dst = (String) l.c;
        if (attrs.containsKey(dst) || edges.containsKey(dst)) {
            throw new DoNotIgnore("In select clause, duplicate for: " + dst);
        }
        if (l.a instanceof Tuple3 && ((org.jparsec.functors.Pair) l.a).a.toString().equals("(")) {
            edges.put(dst, new Pair(null, fromBlockHelper2(from.keySet(), l.a)));
        } else {
            attrs.put(dst, Chc.inRight(toTerm(from.keySet(), null, l.a, true)));
        }
    }
    Block bl = new Block<>(from, where, attrs, edges);
    return bl;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) 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 69 with Tuple3

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

the class OplParser method fromBlockHelper2.

private static Map<String, OplTerm<String, String>> fromBlockHelper2(Set<String> vars, Object o) {
    Tuple3 tx = (Tuple3) o;
    // is token ( ?
    List<Tuple3> l = (List<Tuple3>) tx.b;
    Map<String, OplTerm<String, String>> ret = new HashMap<>();
    for (Tuple3 t : l) {
        if (ret.containsKey(t.c.toString())) {
            throw new DoNotIgnore("Duplicate column: " + t.c + "\n in " + o);
        }
        ret.put(t.c.toString(), toTerm(vars, null, t.a, true));
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList)

Example 70 with Tuple3

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

the class MplParser method toTheory.

private static MplExp toTheory(Object o) {
    Tuple3 t = (Tuple3) o;
    Tuple3 a = (Tuple3) t.a;
    Tuple3 b = (Tuple3) t.b;
    Tuple3 c = (Tuple3) t.c;
    Set<String> sorts = new HashSet<>((Collection<String>) a.b);
    List<Tuple3> symbols0 = (List<Tuple3>) b.b;
    List<Tuple3> equations0 = (List<Tuple3>) c.b;
    Map<String, Pair<MplType<String>, MplType<String>>> symbols = new HashMap<>();
    for (Tuple3 x : symbols0) {
        MplType<String> dom;
        MplType<String> args;
        Tuple3 zzz = (Tuple3) x.c;
        args = toType(zzz.a);
        dom = toType(zzz.c);
        List<String> name0s = (List<String>) x.a;
        for (String name : name0s) {
            if (symbols.containsKey(name)) {
                throw new DoNotIgnore("Duplicate symbol " + name);
            }
            symbols.put(name, new Pair<>(args, dom));
        }
    }
    Set<Pair<MplTerm<String, String>, MplTerm<String, String>>> equations = new HashSet<>();
    for (Tuple3 eq : equations0) {
        MplTerm<String, String> lhs = toTerm(eq.a);
        MplTerm<String, String> rhs = toTerm(eq.c);
        equations.add(new Pair<>(lhs, rhs));
    }
    return new MplSch<>(sorts, symbols, equations);
}
Also used : MplSch(catdata.mpl.Mpl.MplExp.MplSch) Tuple3(org.jparsec.functors.Tuple3) 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