示例#1
0
文件: CatOps.java 项目: epost/fql2
  @Override
  public Transform visit(FQLProgram env, ToMap e) {
    Functor s = e.src.accept(env, this);
    Functor t = e.dst.accept(env, this);
    CatExp scat = resolve(env, e.s);
    if (!(scat instanceof CatExp.Const)) {
      throw new RuntimeException("Source category of " + e + " is not a constant.");
    }
    // CatExp.Const scon = (CatExp.Const) scat;
    CatExp tcat = resolve(env, e.t);
    if (!(tcat instanceof CatExp.Const)) {
      throw new RuntimeException("Target category of " + e + " is not a constant.");
    }
    CatExp.Const tcon = (CatExp.Const) tcat;

    // Signature ssig = new Signature(scon.nodes, scon.arrows, scon.eqs);
    Signature<String, String> tsig =
        new Signature<String, String>(tcon.nodes, tcon.arrows, tcon.eqs);

    FUNCTION o =
        x -> {
          Node n = (Node) x;
          // Set src = (Set) s.applyO(n);
          // Set dst = (Set) t.applyO(n);
          Pair<String, List<String>> k = e.fun.get(n.name);
          Signature<String, String>.Path fun = tsig.path(k.first, k.second);
          return fun; // new Fn(src, dst, fun);
        };

    return new Transform(s, t, o);
  }
示例#2
0
文件: CatOps.java 项目: epost/fql2
 @Override
 public Transform visit(FQLProgram env, ApplyPath e) {
   Functor F = e.F.accept(env, this);
   CatExp c = resolve(env, e.cat);
   if (!(c instanceof CatExp.Const)) {
     throw new RuntimeException("Can only take paths in constant categories.");
   }
   CatExp.Const C = (CatExp.Const) c;
   Signature s = new Signature(C.nodes, C.arrows, C.eqs);
   Signature.Path n = s.path(e.node, e.edges);
   return (Transform) F.applyA(n);
 }
示例#3
0
文件: CatOps.java 项目: epost/fql2
  public Pair<Category, Instance<String, String>> toInstance(FQLProgram env, InstConst ic) {
    CatExp e = resolve(env, ic.sig);
    if (!(e instanceof Const)) {
      throw new RuntimeException("Can only create instances for finitely-presented categories.");
    }
    Const c = (Const) e;

    Category src = c.accept(env, this);
    Signature<String, String> sig = new Signature<>(c.nodes, c.arrows, c.eqs);

    Map<Node, Set> nm = new HashMap<>();
    for (String n0 : ic.nm.keySet()) {
      Node n = sig.getNode(n0);
      SetExp kkk = ic.nm.get(n.name);
      if (kkk == null) {
        throw new RuntimeException("Missing node mapping from " + n);
      }
      nm.put(n, kkk.accept(env, new SetOps(ENV)));
    }
    Map<Edge, Map> em = new HashMap<>();
    for (String n0 : ic.em.keySet()) {
      Edge n = sig.getEdge(n0);
      Chc<FnExp, SetExp> chc = ic.em.get(n.name);
      if (chc == null) {
        throw new RuntimeException("Missing edge mapping from " + n);
      }
      if (chc.left) {
        FnExp kkk = chc.l;
        em.put(n, kkk.accept(env, new SetOps(ENV)).toMap());
      } else {
        SetExp sss = chc.r;
        Set vvv = sss.accept(env, new SetOps(ENV));
        Map<Object, Object> uuu = new HashMap<>();
        for (Object o : vvv) {
          if (!(o instanceof Pair)) {
            throw new RuntimeException("Not a pair: " + o);
          }
          Pair oo = (Pair) o;
          if (uuu.containsKey(oo.first)) {
            throw new RuntimeException("Duplicate domain entry: " + o + " in " + ic);
          }
          uuu.put(oo.first, oo.second);
        }
        FnExp kkk =
            new FnExp.Const(x -> uuu.get(x), ic.nm.get(n.source.name), ic.nm.get(n.target.name));
        em.put(n, kkk.accept(env, new SetOps(ENV)).toMap());
      }
    }

    return new Pair<>(src, new Instance(nm, em, sig));
  }
示例#4
0
文件: CatOps.java 项目: epost/fql2
  private Triple<Category, Category, Mapping<String, String, String, String>> toMapping(
      FQLProgram env, MapConst ic) {
    CatExp src0 = resolve(env, ic.src);
    if (src0 == null) {
      throw new RuntimeException("Missing category: " + ic.src);
    }
    if (!(src0 instanceof Const)) {
      throw new RuntimeException("Can only create mappings for finitely-presented categories.");
    }
    Const src = (Const) src0;

    CatExp dst0 = resolve(env, ic.dst);
    if (!(dst0 instanceof Const)) {
      throw new RuntimeException("Can only create mappings for finitely-presented categories.");
    }
    Const dst = (Const) dst0;

    Category srcX = src.accept(env, this);
    Category dstX = dst.accept(env, this);

    Signature<String, String> srcY = new Signature<>(src.nodes, src.arrows, src.eqs);
    Signature<String, String> dstY = new Signature<>(dst.nodes, dst.arrows, dst.eqs);

    Map<Node, Node> nm = new HashMap<>();
    for (String n0 : ic.nm.keySet()) {
      Signature<String, String>.Node n = srcY.getNode(n0);
      String v = ic.nm.get(n.name);
      if (v == null) {
        throw new RuntimeException("Missing object mapping for " + n.name);
      }
      nm.put(n, dstY.getNode(v));
    }
    Map<Edge, Path> em = new HashMap<>();
    for (String n0 : ic.em.keySet()) {
      Signature<String, String>.Edge n = srcY.getEdge(n0);
      Pair<String, List<String>> k = ic.em.get(n.name);
      if (k == null) {
        throw new RuntimeException("Missing arrow mapping for " + n.name);
      }
      em.put(n, dstY.path(k.first, k.second));
    }

    Mapping<String, String, String, String> I = new Mapping(nm, em, srcY, dstY);

    return new Triple<>(srcX, dstX, I);
  }
示例#5
0
文件: CatOps.java 项目: epost/fql2
 @Override
 public Category visit(FQLProgram env, fql_lib.decl.CatExp.Const e) {
   Signature<String, String> s = new Signature<>(e.nodes, e.arrows, e.eqs);
   //		s.KB();
   return s.toCat();
 }