Search in sources :

Example 6 with OplPres

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

Example 7 with OplPres

use of catdata.opl.OplExp.OplPres in project fql by CategoricalData.

the class OplWarehouse method addBlanks.

// TODO aql alphabetize tabs
// TODO aql  heuristic: if something already there, leave it.  otherwise, create new
private void addBlanks() {
    switch(state) {
        case INITIAL:
            if (!bindings.containsKey(THEORY)) {
                bindings.put(THEORY, new OplSig<>(new VIt(), new HashMap<>(), new HashSet<>(), new HashMap<>(), new LinkedList<>()));
            }
            break;
        case THEORY:
            if (!bindings.containsKey(SHAPE)) {
                bindings.put(SHAPE, new OplGraph<String, String>(new HashSet<>(), new HashMap<>()));
            }
            break;
        case SHAPE:
            {
                OplGraph<String, String> shape = (OplGraph<String, String>) bindings.get(SHAPE);
                for (String en : shape.nodes) {
                    if (bindings.containsKey(SCHEMA + "_" + en)) {
                        // TODO: aql false
                        continue;
                    }
                    bindings.put(SCHEMA + "_" + en, new OplSCHEMA0<String, String, String>(new HashMap<>(), new HashSet<>(), new HashMap<>(), new HashMap<>(), new LinkedList<>(), new LinkedList<>(), THEORY));
                }
                break;
            }
        case SCHEMA:
            {
                OplGraph<String, String> shape = (OplGraph<String, String>) bindings.get(SHAPE);
                for (String ed : shape.edges.keySet()) {
                    if (bindings.containsKey(MAPPING + "_" + ed)) {
                        continue;
                    }
                    String src = SCHEMA + "_" + shape.edges.get(ed).first;
                    // String dst = SCHEMA + "_" + shape.edges.get(ed).second;
                    OplSCHEMA0<String, String, String> src0 = (OplSCHEMA0<String, String, String>) bindings.get(src);
                    Map<String, String> sorts = new HashMap<>();
                    for (String x : src0.entities) {
                        sorts.put(x, "?");
                    }
                    Map<String, Pair<OplCtx<String, String>, OplTerm<String, String>>> symbols = new HashMap<>();
                    for (String g : src0.attrs.keySet()) {
                        OplCtx<String, String> ctx = new OplCtx<>(Util.singList(new Pair<>("x", "?")));
                        OplTerm<String, String> term = new OplTerm<>("?");
                        symbols.put(g, new Pair<>(ctx, term));
                    }
                    for (String g : src0.edges.keySet()) {
                        OplCtx<String, String> ctx = new OplCtx<>(Util.singList(new Pair<>("t", "?")));
                        OplTerm<String, String> term = new OplTerm<>("?");
                        symbols.put(g, new Pair<>(ctx, term));
                    }
                    bindings.put(MAPPING + "_" + ed, new OplMapping<>(sorts, symbols, src, SCHEMA + "_" + shape.edges.get(ed).second));
                }
                break;
            }
        case MAPPING:
            {
                OplGraph<String, String> shape = (OplGraph<String, String>) bindings.get(SHAPE);
                Set<String> en2 = shape.nodes.stream().map(x -> SCHEMA + "_" + x).collect(Collectors.toSet());
                Map<String, Pair<String, String>> ed2 = new HashMap<>();
                for (String e : shape.edges.keySet()) {
                    Pair<String, String> x = shape.edges.get(e);
                    String l = SCHEMA + "_" + x.first;
                    ed2.put(MAPPING + "_" + e, new Pair<>(l, SCHEMA + "_" + x.second));
                }
                OplGraph<String, String> shape2 = new OplGraph<>(en2, ed2);
                // TODO: aql needs to compile to here
                computeColimit(bindings, shape2, THEORY);
                for (String en : shape.nodes) {
                    if (bindings.containsKey(INSTANCE + "_" + en)) {
                        // TODO aql false
                        continue;
                    }
                    bindings.put(INSTANCE + "_" + en, new OplInst0<>(new OplPres<>(new HashMap<>(), SCHEMA + "_" + en, null, new HashMap<>(), new LinkedList<>())));
                }
                break;
            }
        case INSTANCE:
            {
                OplGraph<String, String> shape = (OplGraph<String, String>) bindings.get(SHAPE);
                for (String ed : shape.edges.keySet()) {
                    String en = shape.edges.get(ed).first;
                    String en2 = shape.edges.get(ed).second;
                    String src = INSTANCE + "_" + ed + "_forward";
                    bindings.put(src, new OplSigma(MAPPING + "_" + ed, INSTANCE + "_" + en));
                    if (bindings.containsKey(TRANSFORM + "_" + ed + "_forward")) {
                        continue;
                    }
                    OplMapping<String, String, String, String, String> mmm = (OplMapping<String, String, String, String, String>) bindings.get(MAPPING + "_" + ed);
                    // TODO: aql factor getting into separate method, or use compiler
                    OplInst0<String, String, String, String> src1 = (OplInst0<String, String, String, String>) bindings.get(INSTANCE + "_" + en);
                    OplInst0<String, String, String, String> src0 = (OplInst0<String, String, String, String>) bindings.get(INSTANCE + "_" + en2);
                    OplSCHEMA0<String, String, String> src0_sch = (OplSCHEMA0<String, String, String>) bindings.get(src0.P.S);
                    OplSCHEMA0<String, String, String> src1_sch = (OplSCHEMA0<String, String, String>) bindings.get(src1.P.S);
                    Map<String, Map<String, OplTerm<Object, String>>> sorts = new HashMap<>();
                    for (String x : src0_sch.entities) {
                        sorts.put(x, new HashMap<>());
                    }
                    for (String g : src1.P.gens.keySet()) {
                        String gty = src1.P.gens.get(g);
                        String s2 = mmm.sorts.get(gty);
                        if (s2 == null) {
                            continue;
                        }
                        Map<String, OplTerm<Object, String>> symbols = sorts.get(s2);
                        if (symbols != null) {
                            symbols.put(g, new OplTerm<>("?"));
                        }
                    }
                    bindings.put(TRANSFORM + "_" + ed + "_forward", new OplPresTrans<String, String, String, String, String>(sorts, src, INSTANCE + "_" + shape.edges.get(ed).second));
                }
                break;
            }
        case TRANSFORM:
            OplGraph<String, String> shape = (OplGraph<String, String>) bindings.get(SHAPE);
            for (String en : shape.nodes) {
                bindings.put(INSTANCE + "_" + en + "_colimit", new OplSigma(MAPPING + "_" + SCHEMA + "_" + en + "_colimit", INSTANCE + "_" + en));
            }
            Map<String, Pair<String, String>> ed2 = new HashMap<>();
            for (String e : shape.edges.keySet()) {
                Pair<String, String> x = shape.edges.get(e);
                String l = INSTANCE + "_" + x.first + "_colimit";
                // String en = x.first.get(0);
                String en = x.second;
                bindings.put(TRANSFORM + "_" + e + "_colimit", new OplSigma(MAPPING + "_" + SCHEMA + "_" + en + "_colimit", TRANSFORM + "_" + e + "_forward"));
                ed2.put(TRANSFORM + "_" + e + "_colimit", new Pair<>(l, INSTANCE + "_" + x.second + "_colimit"));
            }
            Set<String> en2 = shape.nodes.stream().map(x -> INSTANCE + "_" + x + "_colimit").collect(Collectors.toSet());
            OplGraph<String, String> shape2 = new OplGraph<>(en2, ed2);
            bindings.put(SCHEMA + "_for_result", shape2);
            bindings.put(FINISHED, new OplExp.OplString("colimit " + SCHEMA + "_Colimit" + " " + SCHEMA + "_for_result"));
            // bindings.put(FINISHED + " all", new OplExp.OplString(complete().toString()));
            break;
        default:
            break;
    }
}
Also used : OplPres(catdata.opl.OplExp.OplPres) JSplitPane(javax.swing.JSplitPane) HashMap(java.util.HashMap) Function(java.util.function.Function) OplSig(catdata.opl.OplExp.OplSig) GridLayout(java.awt.GridLayout) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) WizardModel(catdata.ide.WizardModel) OplPresTrans(catdata.opl.OplExp.OplPresTrans) Map(java.util.Map) JTabbedPane(javax.swing.JTabbedPane) VIt(catdata.opl.OplParser.VIt) ChangeListener(javax.swing.event.ChangeListener) LinkedList(java.util.LinkedList) JComboBox(javax.swing.JComboBox) Pair(catdata.Pair) ChangeEvent(javax.swing.event.ChangeEvent) CodeTextPanel(catdata.ide.CodeTextPanel) Util(catdata.Util) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) Collectors(java.util.stream.Collectors) OplSCHEMA0(catdata.opl.OplExp.OplSCHEMA0) List(java.util.List) OplUnion(catdata.opl.OplExp.OplUnion) OplGraph(catdata.opl.OplExp.OplGraph) Program(catdata.Program) Triple(catdata.Triple) OplInst0(catdata.opl.OplExp.OplInst0) OplSigma(catdata.opl.OplExp.OplSigma) OplMapping(catdata.opl.OplExp.OplMapping) JPanel(javax.swing.JPanel) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OplGraph(catdata.opl.OplExp.OplGraph) HashSet(java.util.HashSet) Pair(catdata.Pair) OplSigma(catdata.opl.OplExp.OplSigma) VIt(catdata.opl.OplParser.VIt) OplPresTrans(catdata.opl.OplExp.OplPresTrans) OplInst0(catdata.opl.OplExp.OplInst0) LinkedList(java.util.LinkedList) OplSCHEMA0(catdata.opl.OplExp.OplSCHEMA0) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) OplMapping(catdata.opl.OplExp.OplMapping)

Example 8 with OplPres

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

Example 9 with OplPres

use of catdata.opl.OplExp.OplPres in project fql by CategoricalData.

the class OplOps method visit.

@Override
public OplObject visit(Program<OplExp> env, OplPres e) {
    OplObject i = ENV.get(e.S);
    if (i instanceof OplSig) {
        OplSig S = (OplSig) i;
        OplPres ret = OplPres.OplPres0(e.prec, e.S, S, e.gens, e.equations);
        ret.toSig();
        return ret;
    } else if (i instanceof OplSchema) {
        OplSchema S = (OplSchema) i;
        OplPres ret = OplPres.OplPres0(e.prec, e.S, S.sig, e.gens, e.equations);
        ret.toSig();
        return ret;
    } else {
        throw new RuntimeException("Not a presentation or schema: " + e.S);
    }
}
Also used : OplSchema(catdata.opl.OplExp.OplSchema) OplPres(catdata.opl.OplExp.OplPres) OplSig(catdata.opl.OplExp.OplSig)

Example 10 with OplPres

use of catdata.opl.OplExp.OplPres in project fql by CategoricalData.

the class OplOps method visit.

@Override
public OplObject visit(Program<OplExp> env, OplSat e) {
    OplObject i = ENV.get(e.I);
    if (i instanceof OplPres) {
        OplPres S = (OplPres) i;
        OplObject ob = OplSat.saturate(S);
        return ob;
    }
    if (i instanceof OplSig) {
        OplSig S = (OplSig) i;
        OplObject ob = S.saturate(e.I);
        return ob;
    }
    throw new RuntimeException("Not a presentation or theory");
}
Also used : OplPres(catdata.opl.OplExp.OplPres) OplSig(catdata.opl.OplExp.OplSig)

Aggregations

OplPres (catdata.opl.OplExp.OplPres)14 Pair (catdata.Pair)7 OplInst (catdata.opl.OplExp.OplInst)7 OplSchema (catdata.opl.OplExp.OplSchema)7 OplSig (catdata.opl.OplExp.OplSig)7 HashMap (java.util.HashMap)7 LinkedList (java.util.LinkedList)6 Triple (catdata.Triple)5 OplInst0 (catdata.opl.OplExp.OplInst0)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 Chc (catdata.Chc)4 OplPresTrans (catdata.opl.OplExp.OplPresTrans)4 OplJavaInst (catdata.opl.OplExp.OplJavaInst)3 OplMapping (catdata.opl.OplExp.OplMapping)3 OplSCHEMA0 (catdata.opl.OplExp.OplSCHEMA0)3 List (java.util.List)3 Program (catdata.Program)2 Util (catdata.Util)2 OplGraph (catdata.opl.OplExp.OplGraph)2