Search in sources :

Example 61 with Tuple3

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

the class OplParser method fromBlockHelper.

// {b2=a1.f, b3=a1.f}
private static Map<String, OplTerm<String, String>> fromBlockHelper(Set<String> vars, Object o) {
    List<Tuple3> l = (List<Tuple3>) o;
    Map<String, OplTerm<String, String>> ret = new HashMap<>();
    for (Tuple3 t : l) {
        if (ret.containsKey(t.a.toString())) {
            throw new DoNotIgnore("Duplicate column: " + t.a + "\n in " + o);
        }
        ret.put(t.a.toString(), toTerm(vars, null, t.c, 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 62 with Tuple3

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

the class OplParser method toSCHEMA.

private static OplExp toSCHEMA(Object ox) {
    Tuple4 oy = (Tuple4) ox;
    String ts = (String) oy.d;
    org.jparsec.functors.Pair newobj = (org.jparsec.functors.Pair) oy.b;
    List<String> imports = newobj.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) newobj.a).b;
    Tuple5 t = (Tuple5) newobj.b;
    Tuple3 a = (Tuple3) t.a;
    Tuple3 b = (Tuple3) t.b;
    Tuple3 c = (Tuple3) t.c;
    Tuple3 d = (Tuple3) t.d;
    Tuple3 e = (Tuple3) t.e;
    Set<String> sorts = a == null ? new HashSet<>() : new HashSet<>((Collection<String>) a.b);
    List<Tuple3> symbolsE0 = b == null ? new LinkedList<>() : (List<Tuple3>) b.b;
    List<Tuple3> symbolsA0 = c == null ? new LinkedList<>() : (List<Tuple3>) c.b;
    List<org.jparsec.functors.Pair> equationsE0 = c == null ? new LinkedList<>() : (List<org.jparsec.functors.Pair>) d.b;
    List<org.jparsec.functors.Pair> equationsA0 = c == null ? new LinkedList<>() : (List<org.jparsec.functors.Pair>) e.b;
    Map<String, Pair<List<String>, String>> symbolsE = new HashMap<>();
    Map<String, Pair<List<String>, String>> symbolsA = new HashMap<>();
    Map<String, Pair<List<String>, String>> symbolsEA = new HashMap<>();
    Map<String, Integer> prec = new HashMap<>();
    for (Tuple3 x : symbolsE0) {
        String dom;
        List<String> args;
        if (x.c instanceof Tuple3) {
            Tuple3 zzz = (Tuple3) x.c;
            args = (List<String>) zzz.a;
            dom = (String) zzz.c;
        } else {
            dom = (String) x.c;
            args = new LinkedList<>();
        }
        List<org.jparsec.functors.Pair> name0s = (List<org.jparsec.functors.Pair>) x.a;
        for (org.jparsec.functors.Pair name0 : name0s) {
            String name = (String) name0.a;
            if (name0.b != null) {
                org.jparsec.functors.Pair zzz = (org.jparsec.functors.Pair) name0.b;
                Integer i = (Integer) zzz.b;
                prec.put(name, i);
            }
            if (symbolsE.containsKey(name)) {
                throw new DoNotIgnore("Duplicate symbol " + name);
            }
            symbolsE.put(name, new Pair<>(args, dom));
            symbolsEA.put(name, new Pair<>(args, dom));
        }
    }
    for (Tuple3 x : symbolsA0) {
        String dom;
        List<String> args;
        if (x.c instanceof Tuple3) {
            Tuple3 zzz = (Tuple3) x.c;
            args = (List<String>) zzz.a;
            dom = (String) zzz.c;
        } else {
            dom = (String) x.c;
            args = new LinkedList<>();
        }
        List<org.jparsec.functors.Pair> name0s = (List<org.jparsec.functors.Pair>) x.a;
        for (org.jparsec.functors.Pair name0 : name0s) {
            String name = (String) name0.a;
            if (name0.b != null) {
                org.jparsec.functors.Pair zzz = (org.jparsec.functors.Pair) name0.b;
                Integer i = (Integer) zzz.b;
                prec.put(name, i);
            }
            if (symbolsA.containsKey(name)) {
                throw new DoNotIgnore("Duplicate symbol " + name);
            }
            symbolsA.put(name, new Pair<>(args, dom));
            symbolsEA.put(name, new Pair<>(args, dom));
        }
    }
    // /////////////
    List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> equationsE = new LinkedList<>();
    List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> equationsA = new LinkedList<>();
    for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equationsE0) {
        List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
        OplCtx<String, String> ctx = toCtx(fa);
        Tuple3 eq = x.b;
        OplTerm lhs = toTerm(ctx.names(), consts(symbolsEA), eq.a, false);
        OplTerm rhs = toTerm(ctx.names(), consts(symbolsEA), eq.c, false);
        equationsE.add(new Triple<>(ctx, lhs, rhs));
    }
    for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equationsA0) {
        List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
        OplCtx<String, String> ctx = toCtx(fa);
        Tuple3 eq = x.b;
        OplTerm lhs = toTerm(ctx.names(), consts(symbolsEA), eq.a, false);
        OplTerm rhs = toTerm(ctx.names(), consts(symbolsEA), eq.c, false);
        equationsA.add(new Triple<>(ctx, lhs, rhs));
    }
    OplSCHEMA0 ret = new OplSCHEMA0(prec, sorts, symbolsE, symbolsA, equationsE, equationsA, ts);
    ret.imports = new HashSet<>(imports);
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) LinkedList(java.util.LinkedList) OplSCHEMA0(catdata.opl.OplExp.OplSCHEMA0) Tuple4(org.jparsec.functors.Tuple4) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Collection(java.util.Collection)

Example 63 with Tuple3

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

the class OplParser method toTrans.

private static OplExp toTrans(Object c) {
    Tuple3 t = (Tuple3) c;
    if (!t.a.toString().equals("transform")) {
        throw new RuntimeException();
    }
    Map<String, Map<String, String>> map = new HashMap<>();
    Tuple3 tb = (Tuple3) t.b;
    List<Tuple5> l = (List<Tuple5>) tb.b;
    for (Tuple5 x : l) {
        String name = (String) x.a;
        List<Tuple5> y = (List<Tuple5>) x.d;
        Map<String, String> m = new HashMap<>();
        for (Tuple5 z : y) {
            String xx = (String) z.b;
            String yy = (String) z.d;
            if (m.containsKey(xx)) {
                throw new DoNotIgnore("Duplicate argument: " + xx);
            }
            m.put(xx, yy);
        }
        if (map.containsKey(name)) {
            throw new DoNotIgnore("Duplicate sort: " + name);
        }
        map.put(name, m);
    }
    Tuple4 tc = (Tuple4) t.c;
    return new OplSetTrans(map, (String) tc.b, (String) tc.d);
}
Also used : OplSetTrans(catdata.opl.OplExp.OplSetTrans) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 64 with Tuple3

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

the class OplParser method toModel.

private static OplExp toModel(Object o) {
    if (!o.toString().contains("model")) {
        throw new RuntimeException();
    }
    Tuple3 t = (Tuple3) o;
    org.jparsec.functors.Pair b = (org.jparsec.functors.Pair) t.b;
    org.jparsec.functors.Pair c = (org.jparsec.functors.Pair) t.c;
    Tuple3 y = (Tuple3) b.a;
    List<Tuple3> sorts = (List<Tuple3>) y.b;
    Map<String, Set<String>> sorts0 = new HashMap<>();
    for (Tuple3 x : sorts) {
        String s = x.a.toString();
        List<String> s0 = (List<String>) x.c;
        if (sorts0.containsKey(s)) {
            throw new DoNotIgnore("Duplicate sort: " + s);
        }
        Set<String> s1 = new HashSet<>(s0);
        if (s1.size() != s0.size()) {
            throw new DoNotIgnore("Duplicate member: " + s0);
        }
        sorts0.put(s, s1);
    }
    Map<String, Map<List<String>, String>> symbols0 = new HashMap<>();
    Tuple3 z = (Tuple3) b.b;
    List<Tuple3> q = (List<Tuple3>) z.b;
    for (Tuple3 r : q) {
        List<Tuple5> u = (List<Tuple5>) r.c;
        String fname = (String) r.a;
        if (symbols0.containsKey(fname)) {
            throw new DoNotIgnore("Duplicte symbol " + fname);
        }
        Map<List<String>, String> toadd = new HashMap<>();
        for (Tuple5 e : u) {
            List<String> args = (List<String>) e.b;
            String ret = (String) e.d;
            if (toadd.containsKey(args)) {
                throw new DoNotIgnore("Duplicate argument at " + args);
            }
            toadd.put(args, ret);
        }
        symbols0.put(fname, toadd);
    }
    return new OplSetInst(sorts0, symbols0, c.b.toString());
}
Also used : OplSetInst(catdata.opl.OplExp.OplSetInst) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 65 with Tuple3

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

the class OplParser method toINSTANCE.

private static OplExp toINSTANCE(Object o) {
    if (!o.toString().contains("INSTANCE")) {
        throw new RuntimeException();
    }
    OplPres ex = toPresentation(o);
    OplInst0 ret = new OplInst0(ex);
    Tuple4 t = (Tuple4) o;
    Tuple3 e = (Tuple3) t.b;
    List<String> imports = e.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) e.a).b;
    ret.imports = new HashSet<>(imports);
    return ret;
}
Also used : Tuple4(org.jparsec.functors.Tuple4) OplInst0(catdata.opl.OplExp.OplInst0) Tuple3(org.jparsec.functors.Tuple3) OplPres(catdata.opl.OplExp.OplPres) 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