Search in sources :

Example 36 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class PSMEval method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        Quad<Instance, Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>>, Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>>, Map<Node, Map<Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>, Object>>> xxx = interp.exps2.get(AB);
        Instance Jw = xxx.first;
        Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>> map = xxx.second;
        Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>> map2 = xxx.third;
        FinCat<Node, Path> cat = Jw.thesig.toCategory2().first;
        Instance abb = new Instance(sig, PSMGen.gather(ABB, sig, state));
        // Instance ab = new Instance(sig, PSMGen.gather(AB, sig, state));
        // //already have in interp
        Instance a = new Instance(sig, PSMGen.gather(A, sig, state));
        Instance b = new Instance(sig, PSMGen.gather(B, sig, state));
        Transform fst = new Transform(abb, Jw, PSMGen.gather(ABB + "_fst", sig, state));
        Transform snd = new Transform(abb, b, PSMGen.gather(ABB + "_snd", sig, state));
        List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
        for (Node n : sig.nodes) {
            List<Pair<Object, Object>> d = new LinkedList<>();
            Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>> m2 = map2.get(n);
            for (Pair<Object, Object> id : abb.data.get(n.string)) {
                Object id_ab = lookup(fst.data.get(n.string), id.first);
                Object x = lookup(snd.data.get(n.string), id.first);
                Transform t = m2.get(id_ab).second;
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> w = m2.get(id_ab).first;
                Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>> m = map.get(new Pair<>(n, w));
                Object y = m.third.get(n).get(new Pair<>(cat.id(n), x));
                Object f = lookup(t.data.get(n.string), y);
                d.add(new Pair<>(id.first, f));
            }
            data.add(new Pair<>(n.string, d));
        }
        Transform curry = new Transform(abb, a, data);
        PSMGen.shred(pre, curry, state);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Instance(catdata.fql.decl.Instance) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Pair(catdata.Pair) Path(catdata.fql.decl.Path) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Transform(catdata.fql.decl.Transform) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 37 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class OplOps method visit.

@Override
public OplObject visit(Program<OplExp> env, OplColim e) {
    OplObject o = ENV.get(e.name);
    if (!(o instanceof OplGraph)) {
        throw new RuntimeException("Not a graph: " + e.name);
    }
    OplGraph<String, String> shape = (OplGraph<String, String>) o;
    OplObject base0 = ENV.get(e.base);
    String typeSide;
    if (base0 instanceof OplSig) {
        typeSide = e.base;
        OplUnion u0 = new OplUnion(new LinkedList<>(shape.nodes), typeSide);
        OplObject u1 = u0.accept(env, this);
        OplSchema<String, String, String> u = (OplSchema<String, String, String>) u1;
        Map<String, Set<String>> equivs = new HashMap<>();
        Map<String, String> equivs0 = new HashMap<>();
        for (String schname : shape.nodes) {
            OplSchema<String, String, String> sch = (OplSchema<String, String, String>) ENV.get(schname);
            for (String ename : sch.entities) {
                Set<String> set = new HashSet<>();
                set.add(schname + "_" + ename);
                equivs.put(schname + "_" + ename, set);
            }
        }
        // : type check colimit
        for (String mname : shape.edges.keySet()) {
            Pair<String, String> mt = shape.edges.get(mname);
            String s = mt.first;
            String t = mt.second;
            OplSchema<String, String, String> s0 = (OplSchema<String, String, String>) ENV.get(s);
            OplTyMapping<String, String, String, String, String> m0 = (OplTyMapping<String, String, String, String, String>) ENV.get(mname);
            if (!m0.src0.equals(s)) {
                throw new RuntimeException("Source of " + m0 + " is " + m0.src + " and not " + s + "as expected");
            }
            if (!m0.dst0.equals(t)) {
                throw new RuntimeException("Target of " + m0 + " is " + m0.dst + " and not " + t + "as expected");
            }
            for (String ob : s0.entities) {
                String ob0 = m0.m.sorts.get(ob);
                Set<String> set1 = equivs.get(s + "_" + ob);
                Set<String> set2 = equivs.get(t + "_" + ob0);
                set1.addAll(set2);
                equivs.put(s + "_" + ob, set1);
                equivs.put(t + "_" + ob0, set1);
            }
        }
        for (String k : equivs.keySet()) {
            List<String> v = new LinkedList<>(equivs.get(k));
            v.sort(String.CASE_INSENSITIVE_ORDER);
            equivs0.put(k, Util.sep(v, "__"));
        }
        Set<String> entities = new HashSet<>(equivs0.values());
        Map<String, Pair<List<String>, String>> edges = new HashMap<>();
        Map<String, Pair<List<String>, String>> attrs = new HashMap<>();
        List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> pathEqs = new LinkedList<>();
        List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> obsEqs = new LinkedList<>();
        Function<String, String> fun = x -> {
            if (equivs0.containsKey(x)) {
                return equivs0.get(x);
            }
            return x;
        };
        for (String edge : u.toSchema0().edges.keySet()) {
            Pair<List<String>, String> ty = u.toSchema0().edges.get(edge);
            edges.put(edge, new Pair<>(ty.first.stream().map(fun).collect(Collectors.toList()), fun.apply(ty.second)));
        }
        for (String attr : u.toSchema0().attrs.keySet()) {
            Pair<List<String>, String> ty = u.toSchema0().attrs.get(attr);
            attrs.put(attr, new Pair<>(ty.first.stream().map(fun).collect(Collectors.toList()), fun.apply(ty.second)));
        }
        for (Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>> eq : u.toSchema0().pathEqs) {
            OplCtx<String, String> ctx = new OplCtx<>(eq.first.values2().stream().map(x -> new Pair<>(x.first, fun.apply(x.second))).collect(Collectors.toList()));
            pathEqs.add(new Triple<>(ctx, fun2(equivs0, eq.second), fun2(equivs0, eq.third)));
        }
        for (Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>> eq : u.toSchema0().obsEqs) {
            OplCtx<String, String> ctx = new OplCtx<>(eq.first.values2().stream().map(x -> new Pair<>(x.first, fun.apply(x.second))).collect(Collectors.toList()));
            obsEqs.add(new Triple<>(ctx, fun2(equivs0, eq.second), fun2(equivs0, eq.third)));
        }
        for (String mname : shape.edges.keySet()) {
            Pair<String, String> mt = shape.edges.get(mname);
            String s = mt.first;
            String t = mt.second;
            OplSchema<String, String, String> s0 = (OplSchema<String, String, String>) ENV.get(s);
            // OplSchema<String, String, String> t0 = (OplSchema<String,
            // String, String>) ENV.get(t);
            OplTyMapping<String, String, String, String, String> m0 = (OplTyMapping<String, String, String, String, String>) ENV.get(mname);
            for (String edge : s0.projE().symbols.keySet()) {
                Pair<OplCtx<String, String>, OplTerm<String, String>> edge2 = m0.m.symbols.get(edge);
                List<OplTerm<String, String>> args = edge2.first.vars0.keySet().stream().map((Function<String, OplTerm<String, String>>) OplTerm::new).collect(Collectors.toList());
                OplTerm<String, String> lhs = fun2(equivs0, new OplTerm<>(s + "_" + edge, args));
                OplCtx<String, String> ctx = new OplCtx<>(edge2.first.values2().stream().map(x -> new Pair<>(x.first, fun.apply(s + "_" + x.second))).collect(Collectors.toList()));
                OplTerm<String, String> rhs = fun2(equivs0, prepend(t, edge2.second));
                pathEqs.add(new Triple<>(ctx, lhs, rhs));
            }
            for (String edge : s0.projA().symbols.keySet()) {
                Pair<OplCtx<String, String>, OplTerm<String, String>> edge2 = m0.m.symbols.get(edge);
                List<OplTerm<String, String>> args = edge2.first.vars0.keySet().stream().map((Function<String, OplTerm<String, String>>) OplTerm::new).collect(Collectors.toList());
                OplTerm<String, String> lhs = fun2(equivs0, new OplTerm<>(s + "_" + edge, args));
                OplCtx<String, String> ctx = new OplCtx<>(edge2.first.values2().stream().map(x -> new Pair<>(x.first, fun.apply(s + "_" + x.second))).collect(Collectors.toList()));
                OplTerm<String, String> rhs = fun2(equivs0, prepend(t, edge2.second));
                obsEqs.add(new Triple<>(ctx, lhs, rhs));
            }
        }
        OplSCHEMA0<String, String, String> ret = new OplSCHEMA0<>(new HashMap<>(), entities, edges, attrs, pathEqs, obsEqs, typeSide);
        OplSchema retsch = (OplSchema) ret.accept(env, this);
        e.compiled.put("Colimit", ret);
        for (String schname : shape.nodes) {
            OplSchema<String, String, String> sch = (OplSchema<String, String, String>) ENV.get(schname);
            Map<String, String> inj_sorts = new HashMap<>();
            Map<String, Pair<OplCtx<String, String>, OplTerm<String, String>>> inj_symbols = new HashMap<>();
            for (String ename : sch.entities) {
                inj_sorts.put(ename, fun.apply(schname + "_" + ename));
            }
            for (String c1 : sch.projEA().symbols.keySet()) {
                Pair<List<String>, String> t = sch.projEA().symbols.get(c1);
                List<Pair<String, String>> l = new LinkedList<>();
                List<OplTerm<String, String>> vs = new LinkedList<>();
                for (String s1 : t.first) {
                    String v = (String) retsch.sig.fr.next();
                    vs.add(new OplTerm<>(v));
                    l.add(new Pair<>(v, fun.apply(schname + "_" + s1)));
                }
                OplCtx<String, String> ctx = new OplCtx<>(l);
                OplTerm<String, String> value = fun2(equivs0, new OplTerm<>(schname + "_" + c1, vs));
                inj_symbols.put(c1, new Pair<>(ctx, value));
            }
            OplMapping<String, String, String, String, String> mapping = new OplMapping<>(inj_sorts, inj_symbols, schname, "Colimit");
            // : name of colimit
            OplTyMapping<String, String, String, String, String> tm = new OplTyMapping<>(schname, "Colimit", sch, retsch, mapping);
            tm.extend().validate(sch.sig, retsch.sig);
            e.compiled.put(schname + "To" + "Colimit", mapping);
        }
        return e;
    } else if (base0 instanceof OplSchema) {
        OplSchema sch2 = (OplSchema) base0;
        // OplSCHEMA0 sch = sch2.toSchema0();
        List<Pair<OplTerm<Chc<String, String>, String>, OplTerm<Chc<String, String>, String>>> equations = new LinkedList<>();
        // List<Pair<OplTerm<Object, String>, OplTerm<Object, String>>> equations1 = new LinkedList<>();
        Map<String, String> gens = new HashMap<>();
        Map<String, Integer> prec = new HashMap<>();
        for (String s : shape.nodes) {
            OplInst<String, String, String, String> toAdd = (OplInst<String, String, String, String>) ENV.get(s);
            for (Object gen : toAdd.P.gens.keySet()) {
                Object ty = toAdd.P.gens.get(gen);
                gens.put(s + "_" + gen, ty.toString());
            }
            for (Object gen : toAdd.P.prec.keySet()) {
                if (toAdd.P.gens.keySet().contains(gen)) {
                    if (toAdd.P.prec.containsKey(gen)) {
                        prec.put(s + "_" + gen, toAdd.P.prec.get(gen));
                    }
                } else {
                    if (toAdd.P.prec.containsKey(gen)) {
                        prec.put(toAdd.P.S + "_" + gen, toAdd.P.prec.get(gen));
                    }
                }
            }
            for (Pair<OplTerm<Chc<String, String>, String>, OplTerm<Chc<String, String>, String>> tr : toAdd.P.equations) {
                OplTerm lhs1 = prepend3(s, tr.first);
                OplTerm rhs1 = prepend3(s, tr.second);
                equations.add(new Pair<>(lhs1, rhs1));
            }
        }
        for (String mname : shape.edges.keySet()) {
            Pair<String, String> mt = shape.edges.get(mname);
            String s = mt.first;
            String t = mt.second;
            OplInst<String, String, String, String> s0 = (OplInst<String, String, String, String>) ENV.get(s);
            // OplSchema<String, String, String> t0 = (OplSchema<String,
            // String, String>) ENV.get(t);
            OplPresTrans<String, String, String, String, String> m0 = (OplPresTrans<String, String, String, String, String>) ENV.get(mname);
            for (String edge : s0.projE().gens.keySet()) {
                Pair<OplCtx<String, String>, OplTerm<Chc<String, String>, String>> edge2 = m0.mapping.symbols.get(Chc.inRight(edge));
                OplTerm<Chc<String, String>, String> lhs = new OplTerm<>(Chc.inRight(s + "_" + edge), new LinkedList<>());
                equations.add(new Pair<>(lhs, prepend3(t, edge2.second)));
            }
        }
        OplPres<String, String, String, String> pres = new OplPres<>(prec, e.base, sch2.sig, gens, equations);
        OplInst<String, String, String, String> colimInst = new OplInst<>(e.base, "?", null);
        colimInst.validate(sch2, pres, null);
        e.compiled.put("ColimitInstance", colimInst);
        for (String s : shape.nodes) {
            OplInst<String, String, String, String> toAdd = (OplInst<String, String, String, String>) ENV.get(s);
            Map<String, Map<String, OplTerm<Chc<String, String>, String>>> inj_map = new HashMap<>();
            for (String entity : toAdd.S.entities) {
                inj_map.put(entity, new HashMap<>());
            }
            for (Object gen : toAdd.P.gens.keySet()) {
                Object ty = toAdd.P.gens.get(gen);
                gens.put(s + "_" + gen, ty.toString());
                Map<String, OplTerm<Chc<String, String>, String>> m = inj_map.get(ty);
                OplTerm<Chc<String, String>, String> term = new OplTerm<>(Chc.inRight(s + "_" + gen), new LinkedList<>());
                m.put((String) gen, term);
            }
            // OplPresTrans
            OplPresTrans<String, String, String, String, String> inj = new OplPresTrans<>(inj_map, s, "ColimitInstance", toAdd.P, pres);
            e.compiled.put(s + "ToColimitInstance", inj);
        }
        return colimInst;
    }
    throw new RuntimeException("Report your program to Ryan");
}
Also used : OplPres(catdata.opl.OplExp.OplPres) OplTyMapping(catdata.opl.OplExp.OplTyMapping) OplGround(catdata.opl.OplExp.OplGround) OplExpVisitor(catdata.opl.OplExp.OplExpVisitor) OplPushoutSch(catdata.opl.OplExp.OplPushoutSch) Map(java.util.Map) Environment(catdata.Environment) 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) OplInst(catdata.opl.OplExp.OplInst) Set(java.util.Set) Collectors(java.util.stream.Collectors) OplChaseExp(catdata.opl.OplExp.OplChaseExp) OplDelta(catdata.opl.OplExp.OplDelta) List(java.util.List) OplUnion(catdata.opl.OplExp.OplUnion) Program(catdata.Program) OplId(catdata.opl.OplExp.OplId) Triple(catdata.Triple) OplSat(catdata.opl.OplExp.OplSat) DefunctGlobalOptions(catdata.ide.DefunctGlobalOptions) 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) Function(java.util.function.Function) OplSig(catdata.opl.OplExp.OplSig) HashSet(java.util.HashSet) OplFlower(catdata.opl.OplExp.OplFlower) OplPragma(catdata.opl.OplExp.OplPragma) OplPresTrans(catdata.opl.OplExp.OplPresTrans) OplSetTrans(catdata.opl.OplExp.OplSetTrans) LinkedList(java.util.LinkedList) Util(catdata.Util) OplSCHEMA0(catdata.opl.OplExp.OplSCHEMA0) OplEval(catdata.opl.OplExp.OplEval) OplPivot(catdata.opl.OplExp.OplPivot) OplSchemaProj(catdata.opl.OplExp.OplSchemaProj) 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) Collections(java.util.Collections) OplSchema(catdata.opl.OplExp.OplSchema) HashMap(java.util.HashMap) OplPres(catdata.opl.OplExp.OplPres) List(java.util.List) LinkedList(java.util.LinkedList) OplGraph(catdata.opl.OplExp.OplGraph) HashSet(java.util.HashSet) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Map(java.util.Map) HashMap(java.util.HashMap) Set(java.util.Set) HashSet(java.util.HashSet) OplInst(catdata.opl.OplExp.OplInst) Function(java.util.function.Function) OplTyMapping(catdata.opl.OplExp.OplTyMapping) Pair(catdata.Pair) OplPresTrans(catdata.opl.OplExp.OplPresTrans) OplUnion(catdata.opl.OplExp.OplUnion) OplSig(catdata.opl.OplExp.OplSig) OplSCHEMA0(catdata.opl.OplExp.OplSCHEMA0) OplMapping(catdata.opl.OplExp.OplMapping) Chc(catdata.Chc)

Example 38 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class OplOps method visit.

// private static int temp = 0;
@Override
public OplObject visit(Program<OplExp> env, OplUnion e) {
    String typeSide;
    OplSchema schema = null;
    Map<String, Integer> prec = new HashMap<>();
    OplObject o = ENV.get(e.base);
    if (o instanceof OplSchema) {
        schema = (OplSchema) o;
        typeSide = schema.forSchema0;
        if (typeSide == null) {
            throw new RuntimeException(e.base + " is not a SCHEMA literal");
        }
    } else if (o instanceof OplSig) {
        typeSide = e.base;
    } else {
        throw new RuntimeException("Report this program to Ryan");
    }
    if (schema == null) {
        Set<String> entities = new HashSet<>();
        Map<String, Pair<List<String>, String>> edges = new HashMap<>();
        Map<String, Pair<List<String>, String>> attrs = new HashMap<>();
        List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> pathEqs = new LinkedList<>();
        List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> obsEqs = new LinkedList<>();
        for (String s : e.names) {
            OplExp exp = env.exps.get(s);
            if (exp == null) {
                throw new RuntimeException("Missing expression: " + s);
            }
            if (!(exp instanceof OplSCHEMA0)) {
                throw new RuntimeException("Not a schema: " + s);
            }
            OplSCHEMA0<String, String, String> toAdd = (OplSCHEMA0<String, String, String>) exp;
            if (!toAdd.typeSide.equals(typeSide)) {
                throw new RuntimeException("not all equal typesides in " + e);
            }
            for (Object entity : toAdd.entities) {
                String proposed = s + "_" + entity;
                if (entities.contains(proposed)) {
                    throw new RuntimeException("name clash: " + entity);
                }
                entities.add(proposed);
            }
            for (Object edge : toAdd.edges.keySet()) {
                String proposed = s + "_" + edge;
                if (edges.containsKey(proposed)) {
                    throw new RuntimeException("name clash: " + edge);
                }
                edges.put(proposed, new Pair<>(Util.singList(s + "_" + toAdd.edges.get(edge).first.get(0)), s + "_" + toAdd.edges.get(edge).second));
                if (toAdd.prec.containsKey(edge)) {
                    prec.put(proposed, toAdd.prec.get(edge));
                }
            }
            for (Object att : toAdd.attrs.keySet()) {
                String proposed = s + "_" + att;
                if (attrs.containsKey(proposed)) {
                    throw new RuntimeException("name clash: " + att);
                }
                attrs.put(proposed, new Pair<>(Util.singList(s + "_" + toAdd.attrs.get(att).first.get(0)), toAdd.attrs.get(att).second));
                if (toAdd.prec.containsKey(att)) {
                    prec.put(proposed, toAdd.prec.get(att));
                }
            }
            for (Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>> tr : toAdd.pathEqs) {
                String v = tr.first.names().get(0);
                String t = s + "_" + tr.first.values().get(0);
                OplCtx<String, String> ctx = new OplCtx<>(Util.singList(new Pair<>(v, t)));
                OplTerm<String, String> lhs1 = prepend(s, tr.second);
                OplTerm<String, String> rhs1 = prepend(s, tr.third);
                pathEqs.add(new Triple<>(ctx, lhs1, rhs1));
            }
            for (Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>> tr : toAdd.obsEqs) {
                String v = tr.first.names().get(0);
                String t = s + "_" + tr.first.values().get(0);
                OplCtx<String, String> ctx = new OplCtx<>(Util.singList(new Pair<>(v, t)));
                OplTerm<String, String> lhs1 = prepend(s, tr.second);
                OplTerm<String, String> rhs1 = prepend(s, tr.third);
                obsEqs.add(new Triple<>(ctx, lhs1, rhs1));
            }
        }
        return new OplSCHEMA0<>(prec, entities, edges, attrs, pathEqs, obsEqs, typeSide).accept(env, this);
    } else {
        for (String s : e.names) {
            OplObject exp = ENV.get(s);
            if (!(exp instanceof OplInst)) {
                throw new RuntimeException("Not an instance: " + s);
            }
            OplInst<String, String, String, String> toAdd = (OplInst<String, String, String, String>) exp;
            if (!toAdd.S.equals(schema)) {
                throw new RuntimeException(s + " is not on schema " + schema);
            }
        }
        OplSig<String, String, String> sig = schema.sig;
        Map<String, String> gens = new HashMap<>();
        List<Pair<OplTerm<Object, String>, OplTerm<Object, String>>> equations1 = new LinkedList<>();
        // List<Pair<OplTerm<Chc<String,String>, String>, OplTerm<Chc<String,String>, String>>> equations2 = new LinkedList<>();
        for (String s : e.names) {
            OplExp exp = env.exps.get(s);
            OplInst0<String, String, String, String> toAdd = (OplInst0<String, String, String, String>) exp;
            for (Object gen : toAdd.P.gens.keySet()) {
                Object ty = toAdd.P.gens.get(gen);
                gens.put(s + "_" + gen, /* toAdd.P.S + "_" + */
                ty.toString());
            }
            for (Object gen : toAdd.P.prec.keySet()) {
                if (toAdd.P.gens.keySet().contains(gen)) {
                    if (toAdd.P.prec.containsKey(gen)) {
                        prec.put(s + "_" + gen, toAdd.P.prec.get(gen));
                    }
                } else {
                    if (toAdd.P.prec.containsKey(gen)) {
                        prec.put(toAdd.P.S + "_" + gen, toAdd.P.prec.get(gen));
                    }
                }
            }
            for (Pair<OplTerm<Chc<String, String>, String>, OplTerm<Chc<String, String>, String>> tr : toAdd.P.equations) {
                OplTerm<Object, String> lhs1 = prepend2((OplTerm) tr.first, s, toAdd.P.gens.keySet());
                OplTerm<Object, String> rhs1 = prepend2((OplTerm) tr.second, s, toAdd.P.gens.keySet());
                equations1.add(new Pair<>(lhs1, rhs1));
            }
        }
        // OplPres<String, String, String, String> pres = new OplPres(prec, "_temp" + temp, sig, gens, equations2);
        OplPres<String, String, String, String> pres = new OplPres(prec, e.base, sig, gens, equations1);
        if (DefunctGlobalOptions.debug.opl.opl_prover_simplify_instances) {
            pres = pres.simplify();
        }
        // temp++;
        OplInst0 ret = new OplInst0<>(pres);
        OplObject x = (OplObject) ret.accept(env, this);
        return x;
    }
}
Also used : OplSchema(catdata.opl.OplExp.OplSchema) HashMap(java.util.HashMap) OplInst(catdata.opl.OplExp.OplInst) OplPres(catdata.opl.OplExp.OplPres) HashSet(java.util.HashSet) Pair(catdata.Pair) OplInst0(catdata.opl.OplExp.OplInst0) OplSig(catdata.opl.OplExp.OplSig) LinkedList(java.util.LinkedList) OplSCHEMA0(catdata.opl.OplExp.OplSCHEMA0) Triple(catdata.Triple)

Example 39 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class OplOptions method display.

@Override
public Pair<JComponent, Function<Unit, Unit>> display() {
    JPanel opl1 = new JPanel(new GridLayout(Options.biggestSize, 1));
    JPanel opl2 = new JPanel(new GridLayout(Options.biggestSize, 1));
    JSplitPane oplsplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    oplsplit.add(opl1);
    oplsplit.add(opl2);
    JCheckBox opl_validate_box = new JCheckBox("", opl_validate);
    JLabel opl_validate_label = new JLabel("Validate mappings:");
    opl1.add(opl_validate_label);
    opl2.add(opl_validate_box);
    JCheckBox opl_unfailing_box = new JCheckBox("", opl_prover_unfailing);
    JLabel opl_unfailing_label = new JLabel("Allow unorientable equations:");
    opl1.add(opl_unfailing_label);
    opl2.add(opl_unfailing_box);
    JCheckBox opl_const_box = new JCheckBox("", opl_prover_require_const);
    JLabel opl_const_label = new JLabel("Require a constant at each sort (false=dangerous):");
    opl2.add(opl_const_box);
    opl1.add(opl_const_label);
    JCheckBox opl_reorder_box = new JCheckBox("", opl_reorder_joins);
    JLabel opl_reorder_label = new JLabel("Reorder joins:");
    opl2.add(opl_reorder_box);
    opl1.add(opl_reorder_label);
    JCheckBox opl_semantic_ac_box = new JCheckBox("", opl_prover_ac);
    JLabel opl_semantic_ac_label = new JLabel("Enable Semantic AC optimization in Knuth-Bendix:");
    opl2.add(opl_semantic_ac_box);
    opl1.add(opl_semantic_ac_label);
    JTextField opl_iterations_box = new JTextField(Integer.toString(opl_prover_timeout), 12);
    JLabel opl_iterations_label = new JLabel("Knuth-Bendix timeout (ms)");
    opl2.add(wrap(opl_iterations_box));
    opl1.add(opl_iterations_label);
    JTextField opl_homit_box = new JTextField(Integer.toString(opl_saturate_timeout), 12);
    JLabel opl_homit_label = new JLabel("Saturation timeout (ms)");
    opl2.add(wrap(opl_homit_box));
    opl1.add(opl_homit_label);
    JTextField opl_red_box = new JTextField(Integer.toString(opl_prover_reduction_limit), 12);
    JLabel opl_red_label = new JLabel("Reduction iterations maximum");
    opl2.add(wrap(opl_red_box));
    opl1.add(opl_red_label);
    JCheckBox opl_pretty_box = new JCheckBox("", opl_pretty_print);
    JLabel opl_pretty_label = new JLabel("Pretty Print terms:");
    opl2.add(opl_pretty_box);
    opl1.add(opl_pretty_label);
    JCheckBox opl_suppress_box = new JCheckBox("", opl_suppress_dom);
    JLabel opl_suppress_label = new JLabel("Supress instance domains:");
    opl2.add(opl_suppress_box);
    opl1.add(opl_suppress_label);
    JCheckBox opl_horn_box = new JCheckBox("", opl_allow_horn);
    JLabel opl_horn_label = new JLabel("Allow implications in theories (dangerous, also can't check mappings):");
    opl2.add(opl_horn_box);
    opl1.add(opl_horn_label);
    JCheckBox opl_eqs_box = new JCheckBox("", opl_query_check_eqs);
    JLabel opl_eqs_label = new JLabel("Check that queries preserve equalities:");
    opl2.add(opl_eqs_box);
    opl1.add(opl_eqs_label);
    JCheckBox opl_simpl_box = new JCheckBox("", opl_pushout_simpl);
    JLabel opl_simpl_label = new JLabel("Simplify pushout schemas:");
    opl2.add(opl_simpl_box);
    opl1.add(opl_simpl_label);
    JCheckBox opl_lazy_box = new JCheckBox("", opl_lazy_gui);
    JLabel opl_lazy_label = new JLabel("Lazily compute gui:");
    opl2.add(opl_lazy_box);
    opl1.add(opl_lazy_label);
    JCheckBox opl_sort_box = new JCheckBox("", opl_prover_sort);
    JLabel opl_sort_label = new JLabel("In prover, sort critical pairs by length:");
    opl2.add(opl_sort_box);
    opl1.add(opl_sort_label);
    JCheckBox opl_selfsub_box = new JCheckBox("", opl_prover_filter_subsumed);
    JLabel opl_selfsub_label = new JLabel("In prover, filter self-subsumed equations:");
    opl2.add(opl_selfsub_box);
    opl1.add(opl_selfsub_label);
    JCheckBox opl_compose_box = new JCheckBox("", opl_prover_compose);
    JLabel opl_compose_label = new JLabel("In prover, compose equations:");
    opl2.add(opl_compose_box);
    opl1.add(opl_compose_label);
    JCheckBox opl_prec_box = new JCheckBox("", opl_prover_force_prec);
    JLabel opl_prec_label = new JLabel("In prover, force gens < consts < atts < fkeys precedence:");
    opl2.add(opl_prec_box);
    opl1.add(opl_prec_label);
    JCheckBox opl_cache_box = new JCheckBox("", opl_cache_gui);
    JLabel opl_cache_label = new JLabel("Cache artifacts between runs (true=not tested thoroughly):");
    opl2.add(opl_cache_box);
    opl1.add(opl_cache_label);
    JCheckBox opl_consistency_box = new JCheckBox("", opl_require_consistency);
    JLabel opl_consistency_label = new JLabel("Ensure consistency by requiring free type algebras:");
    opl2.add(opl_consistency_box);
    opl1.add(opl_consistency_label);
    JCheckBox opl_nat_sugar_box = new JCheckBox("", opl_desugar_nat);
    JLabel opl_nat_sugar_label = new JLabel("When possible desugar numerals into zero:Nat and succ:Nat->Nat:");
    opl2.add(opl_nat_sugar_box);
    opl1.add(opl_nat_sugar_label);
    JCheckBox opl_print_simpl_pres_box = new JCheckBox("", opl_print_simplified_presentations);
    JLabel opl_print_simpl_pres_label = new JLabel("Print simplified presentations (true=not canonical):");
    opl2.add(opl_print_simpl_pres_box);
    opl1.add(opl_print_simpl_pres_label);
    JCheckBox opl_fresh_ids_box = new JCheckBox("", opl_display_fresh_ids);
    JLabel opl_fresh_ids_label = new JLabel("Display fresh IDs:");
    opl2.add(opl_fresh_ids_box);
    opl1.add(opl_fresh_ids_label);
    JCheckBox opl_simplify_box = new JCheckBox("", opl_prover_simplify_instances);
    JLabel opl_simplify_label = new JLabel("Simplify instances before doing theorem proving:");
    opl2.add(opl_simplify_box);
    opl1.add(opl_simplify_label);
    JCheckBox opl_safejava_box = new JCheckBox("", opl_safe_java);
    JLabel opl_safejava_label = new JLabel("Require use of java typesides to be complete (false=dangerous):");
    opl2.add(opl_safejava_box);
    opl1.add(opl_safejava_label);
    JCheckBox opl_agg_box = new JCheckBox("", opl_secret_agg);
    JLabel opl_agg_label = new JLabel("Allow ad-hoc aggregation (true=dangerous):");
    opl2.add(opl_agg_box);
    opl1.add(opl_agg_label);
    for (int i = 0; i < Options.biggestSize - size(); i++) {
        opl1.add(new JLabel());
        opl2.add(new JLabel());
    }
    Function<Unit, Unit> fn = (Unit t) -> {
        try {
            int opl = opl_prover_timeout;
            int opl_h = opl_saturate_timeout;
            int opl_r = opl_prover_reduction_limit;
            try {
                opl = Integer.parseInt(opl_iterations_box.getText());
                opl_h = Integer.parseInt(opl_homit_box.getText());
                opl_r = Integer.parseInt(opl_red_box.getText());
            } catch (NumberFormatException nfe) {
            }
            opl_prover_timeout = opl;
            opl_saturate_timeout = opl_h;
            opl_prover_reduction_limit = opl_r;
        } catch (NumberFormatException nfe) {
        }
        opl_prover_require_const = opl_const_box.isSelected();
        opl_prover_sort = opl_sort_box.isSelected();
        opl_prover_unfailing = opl_unfailing_box.isSelected();
        opl_validate = opl_validate_box.isSelected();
        opl_pretty_print = opl_pretty_box.isSelected();
        opl_reorder_joins = opl_reorder_box.isSelected();
        opl_suppress_dom = opl_suppress_box.isSelected();
        opl_allow_horn = opl_horn_box.isSelected();
        opl_prover_ac = opl_semantic_ac_box.isSelected();
        opl_query_check_eqs = opl_eqs_box.isSelected();
        opl_pushout_simpl = opl_simpl_box.isSelected();
        opl_lazy_gui = opl_lazy_box.isSelected();
        opl_prover_filter_subsumed = opl_selfsub_box.isSelected();
        // simplify = opl_simplify_box.isSelected();
        opl_prover_compose = opl_compose_box.isSelected();
        opl_cache_gui = opl_cache_box.isSelected();
        opl_prover_force_prec = opl_prec_box.isSelected();
        opl_require_consistency = opl_consistency_box.isSelected();
        opl_desugar_nat = opl_nat_sugar_box.isSelected();
        opl_print_simplified_presentations = opl_print_simpl_pres_box.isSelected();
        opl_display_fresh_ids = opl_fresh_ids_box.isSelected();
        opl_prover_simplify_instances = opl_simplify_box.isSelected();
        opl_safe_java = opl_safejava_box.isSelected();
        opl_secret_agg = opl_agg_box.isSelected();
        return new Unit();
    };
    return new Pair<>(oplsplit, fn);
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JLabel(javax.swing.JLabel) JSplitPane(javax.swing.JSplitPane) JTextField(javax.swing.JTextField) Unit(catdata.Unit) Pair(catdata.Pair)

Example 40 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class OplParser method toPresentation.

private static OplPres toPresentation(Object o) {
    Tuple4 t = (Tuple4) o;
    Tuple3 e = (Tuple3) t.b;
    // List<String> imports = e.a == null ? new LinkedList<>() : (List<String>) ((Tuple3)e.a).b;
    String yyy = (String) t.d;
    org.jparsec.functors.Pair b = (org.jparsec.functors.Pair) e.b;
    org.jparsec.functors.Pair c = (org.jparsec.functors.Pair) e.c;
    List<Tuple3> symbols0 = (List<Tuple3>) b.b;
    List<Tuple4> equations0 = (List<Tuple4>) c.b;
    Map<String, String> symbols = new HashMap<>();
    Map<String, Integer> prec = new HashMap<>();
    for (Tuple3 x : symbols0) {
        String dom = (String) x.c;
        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 (symbols.containsKey(name)) {
                throw new DoNotIgnore("Duplicate symbol " + name);
            }
            symbols.put(name, dom);
        }
    }
    List<Pair<OplTerm<Chc<String, String>, String>, OplTerm<Chc<String, String>, String>>> equations = new LinkedList<>();
    for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equations0) {
        if (x.a != null) {
            throw new DoNotIgnore("Cannot have universally quantified equations in presentations");
        }
        List<Tuple3> fa = new LinkedList<>();
        OplCtx<String, String> ctx = toCtx(fa);
        Tuple3 eq = x.b;
        OplTerm lhs = toTerm(ctx.names(), symbols.keySet(), eq.a, true);
        OplTerm rhs = toTerm(ctx.names(), symbols.keySet(), eq.c, true);
        equations.add(new Pair<>(lhs, rhs));
    }
    OplPres ret = new OplPres<>(prec, yyy, null, symbols, equations);
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OplPres(catdata.opl.OplExp.OplPres) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) Chc(catdata.Chc)

Aggregations

Pair (catdata.Pair)305 LinkedList (java.util.LinkedList)169 HashMap (java.util.HashMap)144 List (java.util.List)127 HashSet (java.util.HashSet)101 Triple (catdata.Triple)98 Map (java.util.Map)94 LinkedHashMap (java.util.LinkedHashMap)82 Set (java.util.Set)70 Tuple3 (org.jparsec.functors.Tuple3)46 Node (catdata.fql.decl.Node)38 JPanel (javax.swing.JPanel)37 GridLayout (java.awt.GridLayout)32 FQLException (catdata.fql.FQLException)31 Paint (java.awt.Paint)29 Chc (catdata.Chc)28 Util (catdata.Util)27 En (catdata.aql.exp.SchExpRaw.En)26 Tuple5 (org.jparsec.functors.Tuple5)26 Ty (catdata.aql.exp.TyExpRaw.Ty)25