Search in sources :

Example 86 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class XParser method program.

public static XProgram program(String s) {
    List<Triple<String, Integer, XExp>> ret = new LinkedList<>();
    List decls = (List) program.parse(s);
    for (Object d : decls) {
        org.jparsec.functors.Pair pr = (org.jparsec.functors.Pair) d;
        Tuple3 decl = (Tuple3) pr.b;
        if (decl.a instanceof List) {
            List l = (List) decl.a;
            for (Object o : l) {
                toProgHelper(pr.a.toString(), s, ret, new Tuple3(o, decl.b, decl.c));
            }
        } else {
            toProgHelper(pr.a.toString(), s, ret, decl);
        }
    }
    return new XProgram(ret);
}
Also used : Triple(catdata.Triple) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Pair(catdata.Pair) XPair(catdata.fpql.XExp.XPair)

Example 87 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class XParser method fromBulb.

private static Triple<String, List<List<String>>, List<String>> fromBulb(Object o) {
    try {
        Tuple3 t = (Tuple3) o;
        Tuple3 a = (Tuple3) t.a;
        Tuple3 b = (Tuple3) a.c;
        return new Triple<>((String) a.b, (List<List<String>>) b.b, (List<String>) t.c);
    } catch (Exception ee) {
    }
    try {
        Tuple3 a = (Tuple3) o;
        Tuple3 b = (Tuple3) a.c;
        return new Triple<>((String) a.b, (List<List<String>>) b.b, null);
    } catch (Exception ee) {
    }
    return new Triple<>(null, null, (List<String>) o);
}
Also used : Triple(catdata.Triple) Tuple3(org.jparsec.functors.Tuple3) List(java.util.List) LinkedList(java.util.LinkedList)

Example 88 with Triple

use of catdata.Triple 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 89 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class XProd method snd.

public static <X> XMapping snd(XCtx<X> I, XCtx<X> J) {
    XCtx<Pair<Triple<X, X, List<X>>, Triple<X, X, List<X>>>> IJ = prod(I, J);
    Map em = new HashMap<>();
    for (Pair<Triple<X, X, List<X>>, Triple<X, X, List<X>>> x : IJ.types.keySet()) {
        List l = new LinkedList<>();
        l.add(x.second.first);
        l.addAll(x.second.third);
        em.put(x, l);
    }
    for (Object x : IJ.allTerms()) {
        if (em.containsKey(x)) {
            continue;
        }
        List l = new LinkedList<>();
        l.add(x);
        em.put(x, l);
    }
    return new XMapping<>(IJ, J, em, "homomorphism");
}
Also used : Triple(catdata.Triple) HashMap(java.util.HashMap) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList) Pair(catdata.Pair)

Example 90 with Triple

use of catdata.Triple in project fql by CategoricalData.

the class XProd method pair.

public static <A> XMapping<A, ?> pair(XMapping<A, A> l, XMapping<A, A> r) {
    if (!l.src.equals(r.src)) {
        throw new RuntimeException();
    }
    XCtx<Pair<Triple<A, A, List<A>>, Triple<A, A, List<A>>>> dst = prod(l.dst, r.dst);
    Map em = new HashMap<>();
    for (A x : l.src.terms()) {
        List<A> x1 = l.em.get(x);
        Triple t1 = l.dst.find_fast(new Triple<>((A) "_1", l.dst.type(x1).second, x1));
        List<A> x2 = r.em.get(x);
        Triple t2 = r.dst.find_fast(new Triple<>((A) "_1", r.dst.type(x2).second, x2));
        List xl = new LinkedList();
        xl.add(new Pair<>(t1, t2));
        em.put(x, xl);
    }
    for (Object x : l.src.allTerms()) {
        if (em.containsKey(x)) {
            continue;
        }
        List z = new LinkedList<>();
        z.add(x);
        em.put(x, z);
    }
    return new XMapping(l.src, dst, em, "homomorphism");
}
Also used : HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Triple(catdata.Triple) List(java.util.List) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) Pair(catdata.Pair)

Aggregations

Triple (catdata.Triple)116 Pair (catdata.Pair)93 LinkedList (java.util.LinkedList)84 List (java.util.List)75 HashMap (java.util.HashMap)65 Map (java.util.Map)49 HashSet (java.util.HashSet)47 LinkedHashMap (java.util.LinkedHashMap)36 Set (java.util.Set)28 Chc (catdata.Chc)22 Util (catdata.Util)18 En (catdata.aql.exp.SchExpRaw.En)18 Ty (catdata.aql.exp.TyExpRaw.Ty)18 Ctx (catdata.Ctx)17 Sym (catdata.aql.exp.TyExpRaw.Sym)17 Collectors (java.util.stream.Collectors)17 Att (catdata.aql.exp.SchExpRaw.Att)16 Fk (catdata.aql.exp.SchExpRaw.Fk)16 Tuple3 (org.jparsec.functors.Tuple3)16 Quad (catdata.Quad)13