Search in sources :

Example 31 with Tuple5

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

the class OplParser method fromBlocks.

private static Map<Object, Pair<String, Block<String, String, String, String, String, String>>> fromBlocks(List l) {
    Map<Object, Pair<String, Block<String, String, String, String, String, String>>> ret = new HashMap<>();
    for (Object o : l) {
        Tuple5 t = (Tuple5) o;
        Block<String, String, String, String, String, String> b = fromBlock(t.c);
        ret.put(t.a.toString(), new Pair<>(t.e.toString(), b));
    }
    return ret;
}
Also used : Tuple5(org.jparsec.functors.Tuple5) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair)

Example 32 with Tuple5

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

the class OplParser method toTerm.

private static OplTerm toTerm(Collection vars, Collection consts, Object a, boolean suppressError) {
    if (a instanceof List) {
        List<String> aa = (List<String>) a;
        if (aa.isEmpty()) {
            throw new RuntimeException();
        }
        OplTerm head = toTerm(vars, consts, aa.get(0), suppressError);
        // List<String> bb = new LinkedList<>(aa); Collections.reverse(list)
        for (int j = 1; j < aa.size(); j++) {
            head = new OplTerm(aa.get(j), Util.singList(head));
        }
        return head;
    }
    if (a instanceof String) {
        String a0 = (String) a;
        try {
            int i = Integer.parseInt(a0);
            if (sugarForNat) {
                return OplTerm.natToTerm(i);
            }
        } catch (Exception e) {
        }
        if (vars != null && vars.contains(a0)) {
            return new OplTerm(a0);
        } else if (vars != null && !vars.contains(a0) || consts != null && consts.contains(a0)) {
            return new OplTerm(a0, new LinkedList<>());
        } else if (consts == null || vars == null) {
            return new OplTerm(a0);
        } else if (suppressError) {
            return new OplTerm(a0, new LinkedList<>());
        }
        throw new DoNotIgnore(a + " is neither a bound variable nor a (0-ary) constant ");
    }
    if (a instanceof Tuple5) {
        Tuple5 t = (Tuple5) a;
        String f = (String) t.c;
        List<OplTerm> l0 = new LinkedList<>();
        l0.add(toTerm(vars, consts, t.b, suppressError));
        l0.add(toTerm(vars, consts, t.d, suppressError));
        return new OplTerm(f, l0);
    }
    Tuple3 t = (Tuple3) a;
    String f = (String) t.a;
    List<Object> l = (List<Object>) t.c;
    List<OplTerm> l0 = l.stream().map(x -> toTerm(vars, consts, x, suppressError)).collect(Collectors.toList());
    return new OplTerm(f, l0);
}
Also used : OplPres(catdata.opl.OplExp.OplPres) Scanners(org.jparsec.Scanners) Tuple3(org.jparsec.functors.Tuple3) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) StringLiteral(org.jparsec.Terminals.StringLiteral) OplGround(catdata.opl.OplExp.OplGround) OplPushoutSch(catdata.opl.OplExp.OplPushoutSch) Map(java.util.Map) OplSchema(catdata.opl.OplExp.OplSchema) OplColim(catdata.opl.OplExp.OplColim) OplPushout(catdata.opl.OplExp.OplPushout) OplSetInst(catdata.opl.OplExp.OplSetInst) Pair(catdata.Pair) OplPushoutBen(catdata.opl.OplExp.OplPushoutBen) Collection(java.util.Collection) OplInst(catdata.opl.OplExp.OplInst) Set(java.util.Set) Collectors(java.util.stream.Collectors) Parser(org.jparsec.Parser) OplChaseExp(catdata.opl.OplExp.OplChaseExp) OplDelta(catdata.opl.OplExp.OplDelta) List(java.util.List) IntegerLiteral(org.jparsec.Terminals.IntegerLiteral) OplUnion(catdata.opl.OplExp.OplUnion) Parsers(org.jparsec.Parsers) Program(catdata.Program) OplId(catdata.opl.OplExp.OplId) XSchema(catdata.fpql.XExp.XSchema) Triple(catdata.Triple) OplSat(catdata.opl.OplExp.OplSat) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) Terminals(org.jparsec.Terminals) OplJavaInst(catdata.opl.OplExp.OplJavaInst) OplDelta0(catdata.opl.OplExp.OplDelta0) Chc(catdata.Chc) HashMap(java.util.HashMap) OplApply(catdata.opl.OplExp.OplApply) OplDistinct(catdata.opl.OplExp.OplDistinct) OplUberSat(catdata.opl.OplExp.OplUberSat) OplSig(catdata.opl.OplExp.OplSig) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) OplFlower(catdata.opl.OplExp.OplFlower) OplPragma(catdata.opl.OplExp.OplPragma) OplPresTrans(catdata.opl.OplExp.OplPresTrans) OplSetTrans(catdata.opl.OplExp.OplSetTrans) LinkedList(java.util.LinkedList) Block(catdata.opl.OplQuery.Block) Iterator(java.util.Iterator) Reference(org.jparsec.Parser.Reference) Util(catdata.Util) OplSCHEMA0(catdata.opl.OplExp.OplSCHEMA0) OplEval(catdata.opl.OplExp.OplEval) OplPivot(catdata.opl.OplExp.OplPivot) OplSchemaProj(catdata.opl.OplExp.OplSchemaProj) Agg(catdata.opl.OplQuery.Agg) Identifier(org.jparsec.Terminals.Identifier) OplGraph(catdata.opl.OplExp.OplGraph) OplUnSat(catdata.opl.OplExp.OplUnSat) OplInst0(catdata.opl.OplExp.OplInst0) OplSigma(catdata.opl.OplExp.OplSigma) OplVar(catdata.opl.OplExp.OplVar) OplMapping(catdata.opl.OplExp.OplMapping) LinkedList(java.util.LinkedList) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList)

Example 33 with Tuple5

use of org.jparsec.functors.Tuple5 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 34 with Tuple5

use of org.jparsec.functors.Tuple5 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 35 with Tuple5

use of org.jparsec.functors.Tuple5 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)

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