Search in sources :

Example 41 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class OplParser method toTheory.

private static OplExp toTheory(Object o) {
    Tuple5 t = (Tuple5) o;
    List<String> imports = t.a == null ? new LinkedList<>() : (List<String>) ((org.jparsec.functors.Pair) t.a).b;
    Tuple3 a = (Tuple3) t.b;
    Tuple3 b = (Tuple3) t.c;
    Tuple3 c = (Tuple3) t.d;
    Tuple3 d = (Tuple3) t.e;
    Set<String> sorts = a == null ? new HashSet<>() : new HashSet<>((Collection<String>) a.b);
    List<Tuple3> symbols0 = b == null ? new LinkedList<>() : (List<Tuple3>) b.b;
    List<org.jparsec.functors.Pair> equations0 = c == null ? new LinkedList<>() : (List<org.jparsec.functors.Pair>) c.b;
    List<org.jparsec.functors.Pair> implications0 = new LinkedList<>();
    if (d != null) {
        implications0 = (List<org.jparsec.functors.Pair>) d.b;
    }
    Map<String, Pair<List<String>, String>> symbols = new HashMap<>();
    Map<String, Integer> prec = new HashMap<>();
    for (Tuple3 x : symbols0) {
        String dom;
        List<String> args;
        if (x.c instanceof Tuple3) {
            Tuple3 zzz = (Tuple3) x.c;
            args = (List<String>) zzz.a;
            dom = (String) zzz.c;
        } else {
            dom = (String) x.c;
            args = new LinkedList<>();
        }
        List<org.jparsec.functors.Pair> name0s = (List<org.jparsec.functors.Pair>) x.a;
        for (org.jparsec.functors.Pair name0 : name0s) {
            // org.jparsec.functors.Pair name0 =
            // (org.jparsec.functors.Pair) x.a;
            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, new Pair<>(args, dom));
        }
    }
    if (sorts.contains("Nat") && symbols.keySet().contains("zero") && symbols.keySet().contains("succ") && DefunctGlobalOptions.debug.opl.opl_desugar_nat) {
        sugarForNat = true;
    }
    List<Triple<OplCtx<String, String>, OplTerm<String, String>, OplTerm<String, String>>> equations = new LinkedList<>();
    for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : equations0) {
        List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
        OplCtx<String, String> ctx = toCtx(fa);
        Tuple3 eq = x.b;
        OplTerm lhs = toTerm(ctx.names(), consts(symbols), eq.a, false);
        OplTerm rhs = toTerm(ctx.names(), consts(symbols), eq.c, false);
        equations.add(new Triple<>(ctx, lhs, rhs));
    }
    List<Triple<OplCtx<String, String>, List<Pair<OplTerm<String, String>, OplTerm<String, String>>>, List<Pair<OplTerm<String, String>, OplTerm<String, String>>>>> implications = new LinkedList<>();
    for (org.jparsec.functors.Pair<Tuple3, Tuple3> x : implications0) {
        List<Tuple3> fa = x.a == null ? new LinkedList<>() : (List<Tuple3>) x.a.b;
        OplCtx<String, String> ctx = toCtx(fa);
        Tuple3 eq = x.b;
        List<Tuple3> lhs0 = (List<Tuple3>) eq.a;
        List<Tuple3> rhs0 = (List<Tuple3>) eq.c;
        List<Pair<OplTerm<String, String>, OplTerm<String, String>>> lhs = new LinkedList<>();
        List<Pair<OplTerm<String, String>, OplTerm<String, String>>> rhs = new LinkedList<>();
        for (Tuple3 obj : lhs0) {
            OplTerm lhsX = toTerm(ctx.names(), consts(symbols), obj.a, false);
            OplTerm rhsX = toTerm(ctx.names(), consts(symbols), obj.c, false);
            lhs.add(new Pair<>(lhsX, rhsX));
        }
        for (Tuple3 obj : rhs0) {
            OplTerm lhsX = toTerm(ctx.names(), consts(symbols), obj.a, false);
            OplTerm rhsX = toTerm(ctx.names(), consts(symbols), obj.c, false);
            rhs.add(new Pair<>(lhsX, rhsX));
        }
        implications.add(new Triple<>(ctx, lhs, rhs));
    }
    OplSig ret = new OplSig<>(new VIt(), prec, sorts, symbols, equations, implications);
    ret.imports = new HashSet<>(imports);
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) OplSig(catdata.opl.OplExp.OplSig) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Collection(java.util.Collection)

Example 42 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class OplParser method fromBlocks2.

private static Map<Object, Pair<String, Block<String, String, String, String, String, String>>> fromBlocks2(List l) {
    Map<Object, Pair<String, Block<String, String, String, String, String, String>>> ret = new HashMap<>();
    for (Object o : l) {
        Tuple4 t = (Tuple4) o;
        Block<String, String, String, String, String, String> b = fromBlock2(t.d);
        ret.put(t.c.toString(), new Pair<>(t.c.toString(), b));
    }
    return ret;
}
Also used : Tuple4(org.jparsec.functors.Tuple4) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair)

Example 43 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class OplParser method fromAgg.

@SuppressWarnings("unused")
private static Agg<String, String, String, String, String, String> fromAgg(Collection vars, Collection consts, Object o, boolean suppressError) {
    Tuple5<Tuple4<?, String, String, ?>, List<Tuple3<String, ?, String>>, List<Tuple3<?, ?, ?>>, org.jparsec.functors.Pair<?, ?>, ?> t = (Tuple5<Tuple4<?, String, String, ?>, List<Tuple3<String, ?, String>>, List<Tuple3<?, ?, ?>>, org.jparsec.functors.Pair<?, ?>, ?>) o;
    LinkedHashMap<String, String> from = new LinkedHashMap<>();
    Set<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new HashSet<>();
    for (Object x : t.b) {
        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());
    }
    Set<String> allVars = new HashSet<>();
    allVars.addAll(vars);
    allVars.addAll(from.keySet());
    for (Object x : t.c) {
        Tuple3 l = (Tuple3) x;
        where.add(new Pair(toTerm(allVars, null, l.a, true), toTerm(allVars, null, l.c, true)));
    }
    OplTerm<String, String> att = toTerm(allVars, null, t.d.b, true);
    return new Agg<>(t.a.b, t.a.c, from, where, att);
}
Also used : Agg(catdata.opl.OplQuery.Agg) LinkedHashMap(java.util.LinkedHashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 44 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class OplParser method fromBlock.

private static Block<String, String, String, String, String, String> fromBlock(Object o) {
    Tuple4<List, List, List, List> t = (Tuple4<List, List, List, List>) o;
    LinkedHashMap<String, String> from = new LinkedHashMap<>();
    Set<Pair<OplTerm<String, String>, OplTerm<String, String>>> where = new HashSet<>();
    Map<String, Chc<Agg<String, String, String, String, String, String>, OplTerm<String, String>>> attrs = new HashMap<>();
    Map<String, Pair<Object, Map<String, OplTerm<String, String>>>> 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(toTerm(from.keySet(), null, l.a, true), toTerm(from.keySet(), null, l.c, true)));
    }
    for (Object x : t.c) {
        Tuple3 l = (Tuple3) x;
        if (attrs.containsKey(l.a.toString())) {
            throw new RuntimeException("Duplicate for: " + l.a);
        }
        if (l.c.toString().contains("agg") && l.c.toString().contains("{") && l.c.toString().contains("return") && l.c.toString().contains("}")) {
            attrs.put(l.a.toString(), Chc.inLeft(fromAgg(from.keySet(), null, l.c, true)));
        } else {
            attrs.put(l.a.toString(), Chc.inRight(toTerm(from.keySet(), null, l.c, true)));
        }
    }
    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(from.keySet(), l.c)));
    }
    Block bl = new Block<>(from, where, attrs, edges);
    return bl;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) Tuple3(org.jparsec.functors.Tuple3) Block(catdata.opl.OplQuery.Block) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) HashSet(java.util.HashSet) Chc(catdata.Chc)

Example 45 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class OplParser method toCatConst.

public static XSchema toCatConst(Object y) {
    List<String> nodes = new LinkedList<>();
    List<Triple<String, String, String>> arrows = new LinkedList<>();
    List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
    Tuple3 s = (Tuple3) y;
    Tuple3 nodes0 = (Tuple3) s.a;
    Tuple3 arrows0 = (Tuple3) s.b;
    Tuple3 eqs0 = (Tuple3) s.c;
    List nodes1 = (List) nodes0.b;
    List arrows1 = (List) arrows0.b;
    List eqs1 = (List) eqs0.b;
    for (Object o : nodes1) {
        nodes.add((String) o);
    }
    for (Object o : arrows1) {
        Tuple5 x = (Tuple5) o;
        arrows.add(new Triple<>((String) x.a, (String) x.c, (String) x.e));
    }
    for (Object o : eqs1) {
        Tuple3 x = (Tuple3) o;
        List<String> l1 = (List<String>) x.a;
        List<String> l2 = (List<String>) x.c;
        eqs.add(new Pair<>(l1, l2));
    }
    XSchema c = new XSchema(nodes, arrows, eqs);
    return c;
}
Also used : LinkedList(java.util.LinkedList) Triple(catdata.Triple) Tuple5(org.jparsec.functors.Tuple5) XSchema(catdata.fpql.XExp.XSchema) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Aggregations

Pair (catdata.Pair)305 LinkedList (java.util.LinkedList)169 HashMap (java.util.HashMap)144 List (java.util.List)127 HashSet (java.util.HashSet)101 Triple (catdata.Triple)98 Map (java.util.Map)94 LinkedHashMap (java.util.LinkedHashMap)82 Set (java.util.Set)70 Tuple3 (org.jparsec.functors.Tuple3)46 Node (catdata.fql.decl.Node)38 JPanel (javax.swing.JPanel)37 GridLayout (java.awt.GridLayout)32 FQLException (catdata.fql.FQLException)31 Paint (java.awt.Paint)29 Chc (catdata.Chc)28 Util (catdata.Util)27 En (catdata.aql.exp.SchExpRaw.En)26 Tuple5 (org.jparsec.functors.Tuple5)26 Ty (catdata.aql.exp.TyExpRaw.Ty)25