Search in sources :

Example 31 with Tuple4

use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.

the class SqlChecker method toEdge.

@SuppressWarnings("rawtypes")
private static Pair<String, List<Pair<String, String>>> toEdge(Object a) {
    Tuple4 t = (Tuple4) a;
    String n = (String) t.b;
    List z = (List) t.d;
    List<Pair<String, String>> y = new LinkedList<>();
    for (Object q : z) {
        Tuple3 q2 = (Tuple3) q;
        Pair<String, String> pair = new Pair<>(((String) q2.a).toUpperCase(), ((String) q2.c).toUpperCase());
        y.add(pair);
    }
    Pair<String, List<Pair<String, String>>> u = new Pair<>(n.toUpperCase(), y);
    return u;
}
Also used : Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) JList(javax.swing.JList) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 32 with Tuple4

use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.

the class XParser method toExp.

private static XExp toExp(Object c) {
    if (c instanceof String) {
        return new Var((String) c);
    }
    try {
        return fromPoly((Tuple4) c);
    } catch (Exception e) {
    }
    try {
        return fromSoed(c);
    } catch (Exception e) {
    }
    try {
        return toCatConst(c);
    } catch (Exception e) {
    }
    try {
        if (c.toString().contains("variables")) {
            return toInstConst(c);
        }
    } catch (Exception e) {
    }
    try {
        return toMapping(c);
    } catch (Exception e) {
    }
    try {
        return toTrans(c);
    } catch (Exception e) {
    }
    if (c instanceof Tuple5) {
        Tuple5 p = (Tuple5) c;
        if (p.c.toString().equals("+")) {
            return new XCoprod(toExp(p.b), toExp(p.d));
        }
        if (p.c.toString().equals("*")) {
            return new XTimes(toExp(p.b), toExp(p.d));
        }
        if (p.c.toString().equals(";")) {
            return new Compose(toExp(p.b), toExp(p.d));
        }
        if (p.a.toString().equals("return") && p.b.toString().equals("sigma")) {
            return new XUnit("sigma", toExp(p.d), toExp(p.e));
        }
        if (p.a.toString().equals("coreturn") && p.b.toString().equals("sigma")) {
            return new XCounit("sigma", toExp(p.d), toExp(p.e));
        }
        if (p.a.toString().equals("return") && p.b.toString().equals("delta")) {
            return new XUnit("pi", toExp(p.d), toExp(p.e));
        }
        if (p.a.toString().equals("coreturn") && p.b.toString().equals("delta")) {
            return new XCounit("pi", toExp(p.d), toExp(p.e));
        }
        return new XFn((String) p.b, (String) p.d, (String) p.e);
    }
    if (c instanceof Tuple4) {
        Tuple4 p = (Tuple4) c;
        return new XEq((List<String>) p.b, (List<String>) p.d);
    }
    if (c instanceof Tuple3) {
        Tuple3 p = (Tuple3) c;
        if (p.a.toString().equals("flower")) {
            XExp I = toExp(p.c);
            Tuple3 q = (Tuple3) p.b;
            // list of tuple3 of (path, string)
            List s = (List) ((org.jparsec.functors.Pair) q.a).b;
            // list of tuple3 of (string, string)
            List f = (List) ((org.jparsec.functors.Pair) q.b).b;
            // list of tuple3 of (path, path)
            List w = (List) ((org.jparsec.functors.Pair) q.c).b;
            Map<Object, List<Object>> select = new HashMap<>();
            Map<Object, Object> from = new HashMap<>();
            List<Pair<List<Object>, List<Object>>> where = new LinkedList<>();
            Set<String> seen = new HashSet<>();
            for (Object o : w) {
                Tuple3 t = (Tuple3) o;
                List lhs = (List) t.a;
                List rhs = (List) t.c;
                where.add(new Pair<>(rhs, lhs));
            }
            for (Object o : s) {
                Tuple3 t = (Tuple3) o;
                List lhs = (List) t.a;
                String rhs = t.c.toString();
                if (seen.contains(rhs)) {
                    throw new RuntimeException("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
                }
                seen.add(rhs);
                select.put(rhs, lhs);
            }
            for (Object o : f) {
                Tuple3 t = (Tuple3) o;
                String lhs = t.a.toString();
                String rhs = t.c.toString();
                if (seen.contains(rhs)) {
                    throw new RuntimeException("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
                }
                seen.add(rhs);
                from.put(rhs, lhs);
            }
            return new Flower(select, from, where, I);
        }
        if (p.a.toString().equals("FLOWER")) {
            XExp I = toExp(p.c);
            Tuple3 q = (Tuple3) p.b;
            // list of tuple3 of (path, string)
            List s = (List) ((org.jparsec.functors.Pair) q.a).b;
            // list of tuple3 of (string, string)
            List f = (List) ((org.jparsec.functors.Pair) q.b).b;
            // list of tuple3 of (path, path)
            Object w = ((org.jparsec.functors.Pair) q.c).b;
            Map<Object, List<Object>> select = new HashMap<>();
            Map<Object, Object> from = new HashMap<>();
            // List<Pair<List<String>, List<String>>> where = new LinkedList<>();
            Set<String> seen = new HashSet<>();
            for (Object o : s) {
                Tuple3 t = (Tuple3) o;
                List lhs = (List) t.a;
                String rhs = t.c.toString();
                if (seen.contains(rhs)) {
                    throw new RuntimeException("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
                }
                seen.add(rhs);
                select.put(rhs, lhs);
            }
            for (Object o : f) {
                Tuple3 t = (Tuple3) o;
                String lhs = t.a.toString();
                String rhs = t.c.toString();
                if (seen.contains(rhs)) {
                    throw new RuntimeException("Duplicate AS name: " + rhs + " (note: AS names can't be used in the schema either)");
                }
                seen.add(rhs);
                from.put(rhs, lhs);
            }
            return new FLOWER2(select, from, toWhere(w), I);
        }
        if (p.a.toString().equals("pushout")) {
            return new XPushout(toExp(p.b), toExp(p.c));
        }
        if (p.a.toString().equals("hom")) {
            return new XToQuery(toExp(p.b), toExp(p.c));
        }
        if (p.a.toString().equals("sigma")) {
            return new XSigma(toExp(p.b), toExp(p.c));
        }
        if (p.a.toString().equals("delta")) {
            return new XDelta(toExp(p.b), toExp(p.c));
        }
        if (p.a.toString().equals("pi")) {
            return new XPi(toExp(p.b), toExp(p.c));
        }
        if (p.a.toString().equals("inl")) {
            return new XInj(toExp(p.b), toExp(p.c), true);
        }
        if (p.a.toString().equals("inr")) {
            return new XInj(toExp(p.b), toExp(p.c), false);
        }
        if (p.a.toString().equals("case")) {
            return new XMatch(toExp(p.b), toExp(p.c));
        }
        if (p.a.toString().equals("fst")) {
            return new XProj(toExp(p.b), toExp(p.c), true);
        }
        if (p.a.toString().equals("snd")) {
            return new XProj(toExp(p.b), toExp(p.c), false);
        }
        if (p.a.toString().equals("pair")) {
            return new XPair(toExp(p.b), toExp(p.c));
        }
        if (p.a.toString().equals("apply")) {
            return new Apply(toExp(p.b), toExp(p.c));
        }
        if (p.a.toString().equals("coapply")) {
            return new XCoApply(toExp(p.b), toExp(p.c));
        }
        return new XConst((String) p.b, (String) p.c);
    }
    if (c instanceof org.jparsec.functors.Pair) {
        org.jparsec.functors.Pair p = (org.jparsec.functors.Pair) c;
        if (p.a.toString().equals("idpoly")) {
            return new XIdPoly(toExp(p.b));
        }
        if (p.a.toString().equals("uberpi")) {
            return new XUberPi(toExp(p.b));
        }
        if (p.a.toString().equals("labels")) {
            return new XLabel(toExp(p.b));
        }
        if (p.a.toString().equals("grothlabels")) {
            return new XGrothLabels(toExp(p.b));
        }
        if (p.a.toString().equals("relationalize")) {
            return new XRel(toExp(p.b));
        }
        if (p.a.toString().equals("void")) {
            return new XVoid(toExp(p.b));
        }
        if (p.a.toString().equals("ff")) {
            return new XFF(toExp(p.b));
        }
        if (p.a.toString().equals("unit")) {
            return new XOne(toExp(p.b));
        }
        if (p.a.toString().equals("tt")) {
            return new XTT(toExp(p.b));
        }
        if (p.a.toString().equals("id")) {
            return new Id(false, toExp(p.b));
        }
        if (p.a.toString().equals("ID")) {
            return new Id(true, toExp(p.b));
        } else // if (p.a.toString().equals("query")) {
        // Tuple3 t = (Tuple3) p.b;
        // return new XExp.XQueryExp(toExp(t.a), toExp(t.b), toExp(t.c));
        // }
        {
            try {
                return fromSuperSoed(c);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return new XTy((String) p.b);
        }
    }
    throw new RuntimeException("x: " + c.getClass() + " " + c);
}
Also used : HashMap(java.util.HashMap) Var(catdata.fpql.XExp.Var) XCoApply(catdata.fpql.XExp.XCoApply) Apply(catdata.fpql.XExp.Apply) XRel(catdata.fpql.XExp.XRel) XVoid(catdata.fpql.XExp.XVoid) FLOWER2(catdata.fpql.XExp.FLOWER2) Compose(catdata.fpql.XExp.Compose) XFF(catdata.fpql.XExp.XFF) List(java.util.List) LinkedList(java.util.LinkedList) XToQuery(catdata.fpql.XExp.XToQuery) HashSet(java.util.HashSet) XIdPoly(catdata.fpql.XExp.XIdPoly) XCounit(catdata.fpql.XExp.XCounit) XEq(catdata.fpql.XExp.XEq) XProj(catdata.fpql.XExp.XProj) LinkedList(java.util.LinkedList) XPair(catdata.fpql.XExp.XPair) XCoApply(catdata.fpql.XExp.XCoApply) XTimes(catdata.fpql.XExp.XTimes) Id(catdata.fpql.XExp.Id) XSigma(catdata.fpql.XExp.XSigma) XFn(catdata.fpql.XExp.XFn) XInj(catdata.fpql.XExp.XInj) XOne(catdata.fpql.XExp.XOne) XUberPi(catdata.fpql.XExp.XUberPi) XDelta(catdata.fpql.XExp.XDelta) XMatch(catdata.fpql.XExp.XMatch) XTT(catdata.fpql.XExp.XTT) XGrothLabels(catdata.fpql.XExp.XGrothLabels) Pair(catdata.Pair) XPair(catdata.fpql.XExp.XPair) Flower(catdata.fpql.XExp.Flower) XConst(catdata.fpql.XExp.XConst) Tuple4(org.jparsec.functors.Tuple4) XPi(catdata.fpql.XExp.XPi) Tuple5(org.jparsec.functors.Tuple5) XCoprod(catdata.fpql.XExp.XCoprod) Tuple3(org.jparsec.functors.Tuple3) XPushout(catdata.fpql.XExp.XPushout) XLabel(catdata.fpql.XExp.XLabel) XUnit(catdata.fpql.XExp.XUnit) XTy(catdata.fpql.XExp.XTy)

Example 33 with Tuple4

use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.

the class XParser method fromBlock.

private static Block<String, String> fromBlock(Object o) {
    Tuple4<List, List, List, List> t = (Tuple4<List, List, List, List>) o;
    Map<Object, String> from = new HashMap<>();
    Set<Pair<List<Object>, List<Object>>> where = new HashSet<>();
    Map<String, List<Object>> attrs = new HashMap<>();
    Map<String, Pair<Object, Map<Object, List<Object>>>> edges = new HashMap<>();
    for (Object x : t.a) {
        Tuple3 l = (Tuple3) x;
        if (from.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        from.put(l.a.toString(), l.c.toString());
    }
    for (Object x : t.b) {
        Tuple3 l = (Tuple3) x;
        where.add(new Pair(l.a, l.c));
    }
    for (Object x : t.c) {
        Tuple3 l = (Tuple3) x;
        if (attrs.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        attrs.put(l.a.toString(), (List<Object>) l.c);
    }
    for (Object x : t.d) {
        Tuple5 l = (Tuple5) x;
        if (from.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        edges.put(l.a.toString(), new Pair(l.e.toString(), fromBlockHelper(l.c)));
    }
    return new Block<>(from, where, attrs, edges);
}
Also used : HashMap(java.util.HashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Block(catdata.fpql.XPoly.Block) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) XPair(catdata.fpql.XExp.XPair) HashSet(java.util.HashSet)

Example 34 with Tuple4

use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.

the class XParser method fromSoed.

/*
J = soed {
	exists f:A->B, g:C->D;
	forall a:A, a.f = p.q, a.g = p.f;
	forall b:B, p = q; 
} : X -> Y on I
	 */
private static XSOED fromSoed(Object ooo) {
    org.jparsec.functors.Pair ooo1 = (org.jparsec.functors.Pair) ooo;
    Tuple4 a = (Tuple4) ooo1.a;
    List<Triple<String, String, String>> es = new LinkedList<>();
    List<FOED> as = new LinkedList<>();
    List<Tuple5> es0 = (List<Tuple5>) a.b;
    for (Tuple5 t : es0) {
        es.add(new Triple(t.a, t.c, t.e));
    }
    List<Tuple4> as0 = (List<Tuple4>) a.d;
    for (Tuple4 t : as0) {
        List<Tuple3> eqs = (List<Tuple3>) t.d;
        List<Pair<List<String>, List<String>>> eqs0 = new LinkedList<>();
        for (Tuple3 x : eqs) {
            eqs0.add(new Pair(x.a, x.c));
        }
        as.add(new FOED((String) t.b, (String) t.c, eqs0));
    }
    Tuple4 b = (Tuple4) ooo1.b;
    String src = (String) b.b;
    String dst = (String) b.c;
    String i = (String) b.d;
    XSOED ret = new XSOED(es, as, src, dst, i);
    return ret;
}
Also used : FOED(catdata.fpql.XExp.XSOED.FOED) SuperFOED(catdata.fpql.XExp.XSuperED.SuperFOED) XSOED(catdata.fpql.XExp.XSOED) LinkedList(java.util.LinkedList) Tuple4(org.jparsec.functors.Tuple4) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) XPair(catdata.fpql.XExp.XPair)

Example 35 with Tuple4

use of org.jparsec.functors.Tuple4 in project fql by CategoricalData.

the class RaToFql method toEd.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static EED toEd(Object decl) {
    Map<String, String> from1 = new LinkedHashMap<>();
    Map<String, String> from2 = new LinkedHashMap<>();
    List<Pair<Pair<String, String>, Pair<String, String>>> where1 = new LinkedList<>();
    List<Pair<Pair<String, String>, Pair<String, String>>> where2 = new LinkedList<>();
    Tuple4 o = (Tuple4) decl;
    org.jparsec.functors.Pair from10 = (org.jparsec.functors.Pair) o.a;
    org.jparsec.functors.Pair where10 = (org.jparsec.functors.Pair) o.b;
    org.jparsec.functors.Pair from11 = (org.jparsec.functors.Pair) o.c;
    org.jparsec.functors.Pair where11 = (org.jparsec.functors.Pair) o.d;
    List<Tuple3> from10x = (List<Tuple3>) from10.b;
    for (Tuple3 k : from10x) {
        from1.put(k.c.toString(), k.a.toString());
    }
    List<Tuple3> where10x = (List<Tuple3>) where10.b;
    for (Tuple3 k : where10x) {
        Tuple3 l = (Tuple3) k.a;
        Tuple3 r = (Tuple3) k.c;
        where1.add(new Pair<>(new Pair<>(l.a.toString(), l.c.toString()), new Pair<>(r.a.toString(), r.c.toString())));
    }
    List<Tuple3> from11x = (List<Tuple3>) from11.b;
    for (Tuple3 k : from11x) {
        from2.put(k.c.toString(), k.a.toString());
    }
    List<Tuple3> where11x = (List<Tuple3>) where11.b;
    for (Tuple3 k : where11x) {
        Tuple3 l = (Tuple3) k.a;
        Tuple3 r = (Tuple3) k.c;
        where2.add(new Pair<>(new Pair<>(l.a.toString(), l.c.toString()), new Pair<>(r.a.toString(), r.c.toString())));
    }
    return new EED(from1, from2, where1, where2);
}
Also used : Tuple4(org.jparsec.functors.Tuple4) Tuple3(org.jparsec.functors.Tuple3) Pair(catdata.Pair)

Aggregations

Tuple4 (org.jparsec.functors.Tuple4)36 Pair (catdata.Pair)30 Tuple3 (org.jparsec.functors.Tuple3)30 List (java.util.List)25 LinkedList (java.util.LinkedList)24 Tuple5 (org.jparsec.functors.Tuple5)18 HashMap (java.util.HashMap)14 LinkedHashMap (java.util.LinkedHashMap)8 HashSet (java.util.HashSet)6 XPair (catdata.fpql.XExp.XPair)5 Map (java.util.Map)4 Triple (catdata.Triple)3 Pair (org.jparsec.functors.Pair)3 Chc (catdata.Chc)2 RawTerm (catdata.aql.RawTerm)2 ColimSchExpRaw (catdata.aql.exp.ColimSchExp.ColimSchExpRaw)2 Delta (catdata.fql.decl.FullQueryExp.Delta)2 Pi (catdata.fql.decl.FullQueryExp.Pi)2 Sigma (catdata.fql.decl.FullQueryExp.Sigma)2 External (catdata.fql.decl.InstExp.External)2