Search in sources :

Example 1 with Sigma

use of catdata.fql.decl.FullQueryExp.Sigma in project fql by CategoricalData.

the class Driver method validateWithEds.

private static void validateWithEds(FQLProgram prog, Map<String, Instance> insts) throws FQLException {
    for (String k : prog.insts.keySet()) {
        InstExp v = prog.insts.get(k);
        if (v instanceof FullSigma) {
            FullSigma v0 = (FullSigma) v;
            Instance x = Chase.sigma(v0.F.toMap(prog), insts.get(v0.I));
            if (!Instance.quickCompare(x, insts.get(k))) {
                throw new RuntimeException("Bad sigma ED compare: ED gives\n\n" + x + "\n\nbut SIGMA gives\n\n" + insts.get(k));
            }
        }
        if (v instanceof InstExp.Sigma) {
            InstExp.Sigma v0 = (InstExp.Sigma) v;
            Instance x = Chase.sigma(v0.F.toMap(prog), insts.get(v0.I));
            if (!Instance.quickCompare(x, insts.get(k))) {
                throw new RuntimeException("Bad sigma ED compare: ED gives\n\n" + x + "\n\nbut SIGMA gives\n\n" + insts.get(k));
            }
        }
        if (v instanceof InstExp.Delta) {
            InstExp.Delta v0 = (InstExp.Delta) v;
            Instance x = Chase.delta(v0.F.toMap(prog), insts.get(v0.I));
            if (!Instance.quickCompare(x, insts.get(k))) {
                throw new RuntimeException("Bad sigma ED compare: ED gives\n\n" + x + "\n\nbut SIGMA gives\n\n" + insts.get(k));
            }
        }
    }
}
Also used : Delta(catdata.fql.decl.FullQueryExp.Delta) Sigma(catdata.fql.decl.FullQueryExp.Sigma) FullSigma(catdata.fql.decl.InstExp.FullSigma) FullSigma(catdata.fql.decl.InstExp.FullSigma)

Example 2 with Sigma

use of catdata.fql.decl.FullQueryExp.Sigma in project fql by CategoricalData.

the class ToFullQueryExp method visit.

@Override
public FullQueryExp visit(FQLProgram env, Match e) {
    try {
        Const s = e.src.typeOf(env).toConst(env);
        Const t = e.dst.typeOf(env).toConst(env);
        Pair<Map<Set<Pair<String, String>>, String>, Map<Set<Pair<String, String>>, String>> xxx = computeEqCs(s, t, e.rel);
        Map<Set<Pair<String, String>>, String> node_map = xxx.first;
        Map<Set<Pair<String, String>>, String> attr_map = xxx.second;
        Set<Pair<List<String>, List<String>>> eqs = new HashSet<>();
        Set<Triple<String, String, String>> arrows = new HashSet<>();
        Set<String> nodes = new HashSet<>();
        Set<Triple<String, String, String>> attrs = new HashSet<>();
        List<Pair<String, String>> inj1Node = new LinkedList<>();
        List<Pair<String, String>> inj1Attrs = new LinkedList<>();
        List<Pair<String, String>> inj2Node = new LinkedList<>();
        List<Pair<String, String>> inj2Attrs = new LinkedList<>();
        List<Pair<String, List<String>>> inj2Arrows = new LinkedList<>();
        List<Pair<String, List<String>>> inj1Arrows = new LinkedList<>();
        for (Triple<String, String, String> att : s.attrs) {
            String eqc = lookupAttr("left", att, attr_map);
            attrs.add(new Triple<>(eqc, lookupNode("left", att.second, node_map), att.third));
            inj1Attrs.add(new Pair<>(att.first, eqc));
        }
        for (Triple<String, String, String> att : t.attrs) {
            String eqc = lookupAttr("right", att, attr_map);
            attrs.add(new Triple<>(eqc, lookupNode("right", att.second, node_map), att.third));
            inj2Attrs.add(new Pair<>(att.first, eqc));
        }
        for (String n : s.nodes) {
            String eqc = lookupNode("left", n, node_map);
            nodes.add(eqc);
            inj1Node.add(new Pair<>(n, eqc));
        }
        for (String n : t.nodes) {
            String eqc = lookupNode("right", n, node_map);
            nodes.add(eqc);
            inj2Node.add(new Pair<>(n, eqc));
        }
        for (Triple<String, String, String> n : s.arrows) {
            String eqc1 = lookupNode("left", n.second, node_map);
            String eqc2 = lookupNode("left", n.third, node_map);
            arrows.add(new Triple<>("left_" + n.first, eqc1, eqc2));
            List<String> l = new LinkedList<>();
            l.add(eqc1);
            l.add("left_" + n.first);
            inj1Arrows.add(new Pair<>(n.first, l));
        }
        for (Triple<String, String, String> n : t.arrows) {
            String eqc1 = lookupNode("right", n.second, node_map);
            String eqc2 = lookupNode("right", n.third, node_map);
            arrows.add(new Triple<>("right_" + n.first, eqc1, eqc2));
            List<String> l = new LinkedList<>();
            l.add(eqc1);
            l.add("right_" + n.first);
            inj2Arrows.add(new Pair<>(n.first, l));
        }
        for (Pair<List<String>, List<String>> eq : s.eqs) {
            List<String> lhs = new LinkedList<>();
            lhs.add(lookupNode("left", eq.first.get(0), node_map));
            for (int i = 1; i < eq.first.size(); i++) {
                lhs.add("left_" + eq.first.get(i));
            }
            List<String> rhs = new LinkedList<>();
            rhs.add(lookupNode("left", eq.second.get(0), node_map));
            for (int i = 1; i < eq.second.size(); i++) {
                rhs.add("left_" + eq.second.get(i));
            }
            eqs.add(new Pair<>(lhs, rhs));
        }
        for (Pair<List<String>, List<String>> eq : t.eqs) {
            List<String> lhs = new LinkedList<>();
            lhs.add(lookupNode("right", eq.first.get(0), node_map));
            for (int i = 1; i < eq.first.size(); i++) {
                lhs.add("right_" + eq.first.get(i));
            }
            List<String> rhs = new LinkedList<>();
            rhs.add(lookupNode("right", eq.second.get(0), node_map));
            for (int i = 1; i < eq.second.size(); i++) {
                rhs.add("right_" + eq.second.get(i));
            }
            eqs.add(new Pair<>(lhs, rhs));
        }
        Const x = new Const(new LinkedList<>(nodes), new LinkedList<>(attrs), new LinkedList<>(arrows), new LinkedList<>(eqs));
        MapExp.Const inj1 = new MapExp.Const(inj1Node, inj1Attrs, inj1Arrows, s, x);
        MapExp.Const inj2 = new MapExp.Const(inj2Node, inj2Attrs, inj2Arrows, t, x);
        switch(e.kind) {
            case "delta sigma forward":
                {
                    FullQueryExp q = new Comp(new Sigma(inj2), new Delta(inj1));
                    return q;
                }
            case "delta pi forward":
                {
                    FullQueryExp q = new Comp(new Pi(inj2), new Delta(inj1));
                    return q;
                }
            case "delta sigma backward":
                {
                    FullQueryExp q = new Comp(new Sigma(inj1), new Delta(inj2));
                    return q;
                }
            case "delta pi backward":
                FullQueryExp q = new Comp(new Pi(inj1), new Delta(inj2));
                return q;
            default:
                break;
        }
        throw new RuntimeException("Unknown kind: " + e.kind);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException(ex.getLocalizedMessage());
    }
}
Also used : Sigma(catdata.fql.decl.FullQueryExp.Sigma) Comp(catdata.fql.decl.FullQueryExp.Comp) Pi(catdata.fql.decl.FullQueryExp.Pi) Pair(catdata.Pair) Const(catdata.fql.decl.SigExp.Const) Triple(catdata.Triple) Delta(catdata.fql.decl.FullQueryExp.Delta)

Example 3 with Sigma

use of catdata.fql.decl.FullQueryExp.Sigma in project fql by CategoricalData.

the class FQLParser method toInst.

@SuppressWarnings("rawtypes")
private static InstExp toInst(Object o) {
    try {
        Tuple4 t = (Tuple4) o;
        Token z = (Token) t.a;
        String y = z.toString();
        if (y.equals("step")) {
            return new Step(t.d.toString(), toMapping(t.b), toMapping(t.c));
        }
    } catch (RuntimeException cce) {
    }
    try {
        Tuple3 t = (Tuple3) o;
        Token z = (Token) t.a;
        String y = z.toString();
        switch(y) {
            case "delta":
                return new InstExp.Delta(toMapping(t.b), t.c.toString());
            case "sigma":
                return new InstExp.Sigma(toMapping(t.b), t.c.toString());
            case "SIGMA":
                return new FullSigma(toMapping(t.b), t.c.toString());
            case "pi":
                return new InstExp.Pi(toMapping(t.b), t.c.toString());
            case "external":
                return new External(toSchema(t.b), t.c.toString());
            case "eval":
                return new Eval(toQuery(t.b), t.c.toString());
            case "EVAL":
                return new FullEval(toFullQuery(t.b), t.c.toString());
            default:
                break;
        }
    } catch (RuntimeException cce) {
    }
    try {
        Tuple3 t = (Tuple3) o;
        Token z = (Token) t.b;
        String y = z.toString();
        if (y.equals("+")) {
            return new Plus(t.a.toString(), t.c.toString());
        } else if (y.equals("*")) {
            return new Times(t.a.toString(), t.c.toString());
        }
        if (y.equals("^")) {
            return new Exp(t.a.toString(), (t.c).toString());
        }
    } catch (RuntimeException cce) {
    }
    try {
        org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) o;
        if (pr.a.toString().equals("unit")) {
            return new One(toSchema(pr.b));
        } else if (pr.a.toString().equals("void")) {
            return new Zero(toSchema(pr.b));
        } else if (pr.a.toString().equals("prop")) {
            return new Two(toSchema(pr.b));
        } else if (pr.a.toString().equals("relationalize")) {
            return new Relationalize(pr.b.toString());
        } else if (pr.a.toString().equals("kernel")) {
            return new Kernel(pr.b.toString());
        }
        throw new RuntimeException();
    } catch (RuntimeException cce) {
    }
    return toInstConst(o);
}
Also used : FullEval(catdata.fql.decl.InstExp.FullEval) Sigma(catdata.fql.decl.FullQueryExp.Sigma) FullSigma(catdata.fql.decl.InstExp.FullSigma) One(catdata.fql.decl.InstExp.One) Token(org.jparsec.Token) Step(catdata.fql.decl.InstExp.Step) Pi(catdata.fql.decl.FullQueryExp.Pi) Plus(catdata.fql.decl.InstExp.Plus) TransEval(catdata.fql.decl.TransExp.TransEval) FullEval(catdata.fql.decl.InstExp.FullEval) Eval(catdata.fql.decl.InstExp.Eval) Kernel(catdata.fql.decl.InstExp.Kernel) Pair(catdata.Pair) Relationalize(catdata.fql.decl.InstExp.Relationalize) Zero(catdata.fql.decl.InstExp.Zero) Two(catdata.fql.decl.InstExp.Two) Tuple4(org.jparsec.functors.Tuple4) Delta(catdata.fql.decl.FullQueryExp.Delta) Tuple3(org.jparsec.functors.Tuple3) Times(catdata.fql.decl.InstExp.Times) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.decl.InstExp.FullSigma) FullQueryExp(catdata.fql.decl.FullQueryExp) Exp(catdata.fql.decl.InstExp.Exp) MapExp(catdata.fql.decl.MapExp) TransExp(catdata.fql.decl.TransExp) QueryExp(catdata.fql.decl.QueryExp) SigExp(catdata.fql.decl.SigExp) InstExp(catdata.fql.decl.InstExp)

Example 4 with Sigma

use of catdata.fql.decl.FullQueryExp.Sigma in project fql by CategoricalData.

the class FQLParser method toTrans.

@SuppressWarnings("rawtypes")
private static TransExp toTrans(Object o) {
    try {
        Tuple4 p = (Tuple4) o;
        String src = p.b.toString();
        String dst = p.c.toString();
        TransExp h = toTrans(p.d);
        String kind = p.a.toString();
        switch(kind) {
            case "delta":
                return new TransExp.Delta(h, src, dst);
            case "pi":
                return new TransExp.Pi(h, src, dst);
            case "sigma":
                return new TransExp.Sigma(h, src, dst);
            case "relationalize":
                return new TransExp.Relationalize(h, src, dst);
            default:
                throw new RuntimeException(o.toString());
        }
    } catch (RuntimeException ex) {
    }
    try {
        Tuple4 p = (Tuple4) o;
        String src = p.b.toString();
        String dst = p.c.toString();
        String name = p.d.toString();
        String kind = p.a.toString();
        switch(kind) {
            case "external":
                return new TransExp.External(src, dst, name);
            case "SIGMA":
                return new TransExp.FullSigma(name, src, dst);
            default:
                throw new RuntimeException(o.toString());
        }
    } catch (RuntimeException ex) {
    }
    try {
        Tuple4 p = (Tuple4) o;
        String obj = p.a.toString();
        String dst = p.d.toString();
        if (p.c.toString().equals("void")) {
            return new TransExp.FF(obj, dst);
        } else if (p.c.toString().equals("unit")) {
            return new TransExp.TT(obj, dst);
        } else if (p.c.toString().equals("curry")) {
            return new TransCurry(obj, dst);
        } else if (p.c.toString().equals("true")) {
            return new Bool(true, dst, obj);
        } else if (p.c.toString().equals("false")) {
            return new Bool(false, dst, obj);
        } else if (p.c.toString().equals("char")) {
            return new Chi(obj, dst);
        }
    } catch (RuntimeException re) {
    }
    try {
        Tuple3 p = (Tuple3) o;
        Object p2 = p.b;
        Object p3 = p.c;
        Object o1 = p.a;
        String p1 = p.a.toString();
        if (p1.equals("iso1")) {
            return new TransIso(true, p2.toString(), p3.toString());
        } else if (p1.equals("iso2")) {
            return new TransIso(false, p2.toString(), p3.toString());
        } else if (p3.toString().equals("fst")) {
            return new TransExp.Fst(p1);
        } else if (p3.toString().equals("not")) {
            return new Not(p1);
        } else if (p3.toString().equals("and")) {
            return new And(p1);
        } else if (p3.toString().equals("or")) {
            return new Or(p1);
        } else if (p3.toString().equals("implies")) {
            return new Implies(p1);
        } else if (p3.toString().equals("eval")) {
            return new TransEval(p1);
        } else if (p3.toString().equals("relationalize")) {
            return new Squash(p1);
        } else if (p3.toString().equals("snd")) {
            return new TransExp.Snd(p1);
        } else if (p3.toString().equals("return")) {
            return new Return(p1);
        } else if (p3.toString().equals("coreturn")) {
            return new Coreturn(p1);
        } else if (p3.toString().equals("inl")) {
            return new TransExp.Inl(p1);
        } else if (p3.toString().equals("kernel")) {
            return new UnChi(p1);
        } else if (p3.toString().equals("inr")) {
            return new TransExp.Inr(p1);
        } else if (p2.toString().equals("then")) {
            return new TransExp.Comp(toTrans(o1), toTrans(p3));
        } else if (p3 instanceof Tuple3) {
            Tuple3 y = (Tuple3) p3;
            String x = y.b.toString();
            switch(x) {
                case "+":
                    return new TransExp.Case(p1, toTrans(y.a), toTrans(y.c));
                case "*":
                    return new TransExp.Prod(p1, toTrans(y.a), toTrans(y.c));
                // return new TransExp.(p1, toTrans(y.a), toTrans(y.c));
                default:
                    throw new RuntimeException("foo");
            }
        }
    } catch (RuntimeException re) {
    }
    try {
        Tuple5 p = (Tuple5) o;
        Object p2 = p.c;
        Object p3 = p.e;
        Object o1 = p.a;
        return toTransConst(o1, p2.toString(), p3.toString());
    } catch (RuntimeException re) {
    }
    try {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) o;
        String p1 = p.a.toString();
        Object p2 = p.b;
        if (p1.equals("id")) {
            return new TransExp.Id(p2.toString());
        }
    } catch (RuntimeException re) {
    }
    if (o instanceof String) {
        return new TransExp.Var(o.toString());
    }
    throw new RuntimeException();
}
Also used : FF(catdata.fql.decl.MapExp.FF) Or(catdata.fql.decl.TransExp.Or) Chi(catdata.fql.decl.TransExp.Chi) UnChi(catdata.fql.decl.TransExp.UnChi) Inl(catdata.fql.decl.MapExp.Inl) Var(catdata.fql.decl.FullQueryExp.Var) TransExp(catdata.fql.decl.TransExp) Sigma(catdata.fql.decl.FullQueryExp.Sigma) FullSigma(catdata.fql.decl.InstExp.FullSigma) UnChi(catdata.fql.decl.TransExp.UnChi) Inr(catdata.fql.decl.MapExp.Inr) Squash(catdata.fql.decl.TransExp.Squash) Case(catdata.fql.decl.MapExp.Case) Prod(catdata.fql.decl.MapExp.Prod) Implies(catdata.fql.decl.TransExp.Implies) Bool(catdata.fql.decl.TransExp.Bool) Pi(catdata.fql.decl.FullQueryExp.Pi) Pair(catdata.Pair) Relationalize(catdata.fql.decl.InstExp.Relationalize) Return(catdata.fql.decl.TransExp.Return) TransEval(catdata.fql.decl.TransExp.TransEval) Fst(catdata.fql.decl.MapExp.Fst) TransCurry(catdata.fql.decl.TransExp.TransCurry) Coreturn(catdata.fql.decl.TransExp.Coreturn) TransIso(catdata.fql.decl.TransExp.TransIso) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Not(catdata.fql.decl.TransExp.Not) Delta(catdata.fql.decl.FullQueryExp.Delta) And(catdata.fql.decl.TransExp.And) Tuple3(org.jparsec.functors.Tuple3) External(catdata.fql.decl.InstExp.External) FullSigma(catdata.fql.decl.InstExp.FullSigma) Id(catdata.fql.decl.MapExp.Id)

Aggregations

Delta (catdata.fql.decl.FullQueryExp.Delta)4 Sigma (catdata.fql.decl.FullQueryExp.Sigma)4 Pair (catdata.Pair)3 Pi (catdata.fql.decl.FullQueryExp.Pi)3 FullSigma (catdata.fql.decl.InstExp.FullSigma)3 External (catdata.fql.decl.InstExp.External)2 Relationalize (catdata.fql.decl.InstExp.Relationalize)2 TransExp (catdata.fql.decl.TransExp)2 TransEval (catdata.fql.decl.TransExp.TransEval)2 Tuple3 (org.jparsec.functors.Tuple3)2 Tuple4 (org.jparsec.functors.Tuple4)2 Triple (catdata.Triple)1 FullQueryExp (catdata.fql.decl.FullQueryExp)1 Comp (catdata.fql.decl.FullQueryExp.Comp)1 Var (catdata.fql.decl.FullQueryExp.Var)1 InstExp (catdata.fql.decl.InstExp)1 Eval (catdata.fql.decl.InstExp.Eval)1 Exp (catdata.fql.decl.InstExp.Exp)1 FullEval (catdata.fql.decl.InstExp.FullEval)1 Kernel (catdata.fql.decl.InstExp.Kernel)1