Search in sources :

Example 6 with InstExp

use of catdata.fql.decl.InstExp in project fql by CategoricalData.

the class TransChecker method visit.

@Override
public Pair<String, String> visit(FQLProgram env, Prod e) {
    InstExp x = env.insts.get(e.obj);
    if (x == null) {
        throw new RuntimeException("Missing " + e.obj + " in " + e);
    }
    if (!(x instanceof Times)) {
        throw new RuntimeException(e.obj + " is not a times: " + x);
    }
    // InstExp.Times y = (InstExp.Times) x;
    Pair<String, String> a = e.l.accept(env, this);
    Pair<String, String> b = e.r.accept(env, this);
    if (!a.first.equals(b.first)) {
        throw new RuntimeException("Domain mismatch: " + e + " with " + a.first + " and " + b.first);
    }
    return new Pair<>(a.first, e.obj);
}
Also used : InstExp(catdata.fql.decl.InstExp) Times(catdata.fql.decl.InstExp.Times) Pair(catdata.Pair)

Example 7 with InstExp

use of catdata.fql.decl.InstExp in project fql by CategoricalData.

the class TransChecker method visit.

@Override
public Pair<String, String> visit(FQLProgram env, TransCurry e) {
    InstExp inst = env.insts.get(e.inst);
    if (inst == null) {
        throw new RuntimeException("Missing instance: " + e.inst);
    }
    if (!(inst instanceof Exp)) {
        throw new RuntimeException("Instance is not an exponential");
    }
    Exp i = (Exp) inst;
    if (seen.contains(e.trans)) {
        throw new RuntimeException("Circular transform " + e);
    }
    seen.add(e.trans);
    Pair<String, String> k = env.transforms.get(e.trans).accept(env, this);
    InstExp ab = env.insts.get(k.first);
    if (!(ab instanceof Times)) {
        throw new RuntimeException("Source is not a product");
    }
    Times t = (Times) ab;
    if (!i.a.equals(k.second)) {
        throw new RuntimeException("Bases do not match");
    }
    if (!i.b.equals(t.b)) {
        throw new RuntimeException("Exponents do not match");
    }
    return new Pair<>(t.a, e.inst);
}
Also used : InstExp(catdata.fql.decl.InstExp) Times(catdata.fql.decl.InstExp.Times) Exp(catdata.fql.decl.InstExp.Exp) TransExp(catdata.fql.decl.TransExp) SigExp(catdata.fql.decl.SigExp) InstExp(catdata.fql.decl.InstExp) Pair(catdata.Pair)

Example 8 with InstExp

use of catdata.fql.decl.InstExp in project fql by CategoricalData.

the class TransChecker method visit.

@Override
public Pair<String, String> visit(FQLProgram env, Squash e) {
    InstExp s = env.insts.get(e.src);
    if (!(s instanceof InstExp.Relationalize)) {
        throw new RuntimeException("Not a relationalize: " + e);
    }
    InstExp.Relationalize xxx = (InstExp.Relationalize) s;
    return new Pair<>(xxx.I, e.src);
}
Also used : Relationalize(catdata.fql.decl.TransExp.Relationalize) InstExp(catdata.fql.decl.InstExp) Pair(catdata.Pair)

Example 9 with InstExp

use of catdata.fql.decl.InstExp in project fql by CategoricalData.

the class TransChecker method visit.

@Override
public Pair<String, String> visit(FQLProgram env, Snd e) {
    InstExp x = env.insts.get(e.obj);
    if (x == null) {
        throw new RuntimeException("Missing " + e.obj + " in " + e);
    }
    if (!(x instanceof Times)) {
        throw new RuntimeException(e.obj + " is not a times: " + x);
    }
    Times y = (Times) x;
    return new Pair<>(e.obj, y.b);
}
Also used : InstExp(catdata.fql.decl.InstExp) Times(catdata.fql.decl.InstExp.Times) Pair(catdata.Pair)

Example 10 with InstExp

use of catdata.fql.decl.InstExp in project fql by CategoricalData.

the class FQLParser method toInstConst.

@SuppressWarnings("rawtypes")
private static InstExp toInstConst(Object decl) {
    Tuple3 y = (Tuple3) decl;
    Tuple3 x = (Tuple3) y.a;
    // List<Pair<String, List<Pair<Object, Object>>>> data = new
    // LinkedList<>();
    Tuple3 nodes = (Tuple3) x.a;
    Tuple3 arrows = (Tuple3) x.c;
    Tuple3 attrs = (Tuple3) x.b;
    List nodes0 = (List) nodes.b;
    List arrows0 = (List) arrows.b;
    // List<Object> seen = new LinkedList<>();
    List<Pair<String, List<Pair<Object, Object>>>> nodesX = new LinkedList<>();
    for (Object o : nodes0) {
        Tuple3 u = (Tuple3) o;
        String n = (String) u.a;
        List m = (List) u.c;
        List<Pair<Object, Object>> l = new LinkedList<>();
        for (Object h : m) {
            l.add(new Pair<>(h, h));
        }
        // if (seen.contains(n)) {
        // throw new RuntimeException("duplicate field: " + o);
        // }
        // seen.add(n);
        nodesX.add(new Pair<>(n, l));
    }
    // RuntimeException toThrow = null;
    List<Pair<String, List<Pair<Object, Object>>>> attrsX = new LinkedList<>();
    if (attrs.b.toString().equals("ASWRITTEN")) {
        for (Pair<String, List<Pair<Object, Object>>> k : nodesX) {
            attrsX.add(new Pair<>(k.first + "_att", k.second));
        }
    } else {
        List attrs0 = (List) attrs.b;
        for (Object o : attrs0) {
            Tuple3 u = (Tuple3) o;
            String n = (String) u.a;
            List m = (List) u.c;
            List<Pair<Object, Object>> l = new LinkedList<>();
            for (Object h : m) {
                Tuple3 k = (Tuple3) h;
                l.add(new Pair<>(k.a, k.c));
            }
            // if (seen.contains(n)) {
            // toThrow = new RuntimeException("duplicate field: " + n );
            // throw toThrow;
            // }
            // seen.add(n);
            attrsX.add(new Pair<>(n, l));
        }
    }
    List<Pair<String, List<Pair<Object, Object>>>> arrowsX = new LinkedList<>();
    for (Object o : arrows0) {
        Tuple3 u = (Tuple3) o;
        String n = (String) u.a;
        List m = (List) u.c;
        List<Pair<Object, Object>> l = new LinkedList<>();
        for (Object h : m) {
            Tuple3 k = (Tuple3) h;
            l.add(new Pair<>(k.a, k.c));
        }
        // if (seen.contains(n)) {
        // throw new RuntimeException("duplicate field: " + o);
        // }
        // seen.add(n);
        arrowsX.add(new Pair<>(n, l));
    }
    InstExp.Const ret = new InstExp.Const(nodesX, attrsX, arrowsX, toSchema(y.c));
    return ret;
}
Also used : Const(catdata.fql.decl.SigExp.Const) InstExp(catdata.fql.decl.InstExp) Tuple3(org.jparsec.functors.Tuple3) Pair(catdata.Pair)

Aggregations

InstExp (catdata.fql.decl.InstExp)30 Pair (catdata.Pair)24 Times (catdata.fql.decl.InstExp.Times)9 SigExp (catdata.fql.decl.SigExp)8 TransExp (catdata.fql.decl.TransExp)8 Two (catdata.fql.decl.InstExp.Two)6 Exp (catdata.fql.decl.InstExp.Exp)5 One (catdata.fql.decl.InstExp.One)5 Plus (catdata.fql.decl.InstExp.Plus)5 Kernel (catdata.fql.decl.InstExp.Kernel)4 External (catdata.fql.decl.InstExp.External)3 Zero (catdata.fql.decl.InstExp.Zero)3 Signature (catdata.fql.decl.Signature)3 ExpPSM (catdata.fql.sql.ExpPSM)3 PSM (catdata.fql.sql.PSM)3 PropPSM (catdata.fql.sql.PropPSM)3 LinkedList (java.util.LinkedList)3 FQLException (catdata.fql.FQLException)2 FullQueryExp (catdata.fql.decl.FullQueryExp)2 Delta (catdata.fql.decl.InstExp.Delta)2