Search in sources :

Example 71 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class XMapping method counit.

@SuppressWarnings({ "rawtypes", "unchecked" })
public XMapping<Pair<Triple<D, D, List<D>>, C>, D> counit(XCtx<D> I) {
    XCtx<Pair<Triple<D, D, List<D>>, C>> FI = delta(I);
    XMapping<Pair<Triple<D, D, List<D>>, C>, Pair<Triple<D, D, List<D>>, C>> f = (XMapping<Pair<Triple<D, D, List<D>>, C>, Pair<Triple<D, D, List<D>>, C>>) this;
    XCtx<Pair<Triple<D, D, List<D>>, C>> FFI = f.apply0(FI);
    Map m = new HashMap<>();
    for (Pair<Triple<D, D, List<D>>, C> c : FFI.terms()) {
        List<D> l = new LinkedList<>(c.first.third);
        l.add(0, c.first.first);
        m.put(c, l);
    }
    for (Object o : FFI.allTerms()) {
        if (m.containsKey(o)) {
            continue;
        }
        List l = new LinkedList();
        l.add(o);
        m.put(o, l);
    }
    return new XMapping<>(FFI, I, m, "homomorphism");
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedList(java.util.LinkedList) Triple(catdata.Triple) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pair(catdata.Pair)

Example 72 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class XNeo4jToFQL method trans0.

private static String trans0(Map<String, Map<String, Object>> properties, Map<String, Set<Pair<String, String>>> edges) {
    labelForProperty(properties);
    Map<String, Set<String>> pfl = propsForLabels(properties);
    Map<String, Pair<String, String>> sfe = sortsForEges(edges, properties);
    XSchema xxx = toSchema(pfl, sfe);
    XInst yyy = toInst(properties, edges);
    return "dom : type\n" + Util.sep(adom(properties), " ") + " : dom\n\nS = " + xxx + "\n\nI = " + yyy + " : S\n";
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) XSchema(catdata.fpql.XExp.XSchema) XInst(catdata.fpql.XExp.XInst) Pair(catdata.Pair)

Example 73 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class XNeo4jToFQL method fromEdges.

/*		Parser<?> n = ident().between(term("("), term(")"));
		Parser<?> e = Parsers.tuple(term("["), term(":"), ident(), term("]"));
		Parser<?> p = Parsers.tuple(n, term("-"), e, term("->"), n);
		return Parsers.tuple(term("CREATE"), p.sepBy(term(","))); */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static Map<String, Set<Pair<String, String>>> fromEdges(Object oo) {
    Map<String, Set<Pair<String, String>>> ret = new HashMap<>();
    org.jparsec.functors.Pair o = (org.jparsec.functors.Pair) oo;
    List<Tuple5> xx = (List<Tuple5>) o.b;
    for (Tuple5 tt : xx) {
        String s = (String) tt.a;
        String t = (String) tt.e;
        Tuple4 e0 = (Tuple4) tt.c;
        String e = (String) e0.c;
        Set<Pair<String, String>> set = ret.computeIfAbsent(e, k -> new HashSet<>());
        set.add(new Pair<>(s, t));
    }
    return ret;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Tuple4(org.jparsec.functors.Tuple4) Tuple5(org.jparsec.functors.Tuple5) LinkedList(java.util.LinkedList) List(java.util.List) Pair(catdata.Pair)

Example 74 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class XOps method visit.

@Override
public XObject visit(XProgram env, XSOED e) {
    XExp src0 = env.exps.get(e.src);
    if (src0 == null) {
        throw new RuntimeException("Missing: " + e.src);
    }
    if (!(src0 instanceof XSchema)) {
        throw new RuntimeException("Not a schema: " + e.src);
    }
    XSchema src = (XSchema) src0;
    XCtx src1 = (XCtx) ENV.objs.get(e.src);
    XExp dst0 = env.exps.get(e.dst);
    if (dst0 == null) {
        throw new RuntimeException("Missing: " + e.dst);
    }
    if (!(dst0 instanceof XSchema)) {
        throw new RuntimeException("Not a schema: " + e.dst);
    }
    XSchema dst = (XSchema) dst0;
    XCtx dst1 = (XCtx) ENV.objs.get(e.dst);
    XObject I0 = ENV.objs.get(e.I);
    if (I0 == null) {
        throw new RuntimeException("Missing: " + e.I);
    }
    if (!(I0 instanceof XCtx)) {
        throw new RuntimeException("Not an instance: " + e.I);
    }
    XCtx I = (XCtx) I0;
    if (!src1.equals(I.schema)) {
        throw new RuntimeException("Instance schema does not match source");
    }
    List<String> nodes = new LinkedList<>();
    List<Triple<String, String, String>> arrows = new LinkedList<>();
    List<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
    Map em_s = new HashMap();
    Map em_t = new HashMap();
    nodes.addAll(src.nodes);
    nodes.addAll(dst.nodes);
    arrows.addAll(src.arrows);
    arrows.addAll(dst.arrows);
    arrows.addAll(e.es);
    eqs.addAll(src.eqs);
    eqs.addAll(dst.eqs);
    for (FOED k : e.as) {
        for (Pair<List<String>, List<String>> v : k.eqs) {
            List<String> l = new LinkedList<>(v.first);
            List<String> r = new LinkedList<>(v.second);
            l.removeAll(Util.singList(k.a));
            r.removeAll(Util.singList(k.a));
            eqs.add(new Pair<>(l, r));
        }
    }
    for (String n : src.nodes) {
        em_s.put(n, Util.singList(n));
    }
    for (String n : dst.nodes) {
        em_t.put(n, Util.singList(n));
    }
    for (Triple<String, String, String> n : src.arrows) {
        em_s.put(n.first, Util.singList(n.first));
    }
    for (Triple<String, String, String> n : dst.arrows) {
        em_t.put(n.first, Util.singList(n.first));
    }
    for (Object n : src1.allTerms()) {
        if (em_s.containsKey(n)) {
            continue;
        }
        em_s.put(n, Util.singList(n));
    }
    for (Object n : dst1.allTerms()) {
        if (em_t.containsKey(n)) {
            continue;
        }
        em_t.put(n, Util.singList(n));
    }
    XSchema X = new XSchema(nodes, arrows, eqs);
    XCtx Y = (XCtx) X.accept(env, this);
    XMapping F = new XMapping(src1, Y, em_s, "mapping");
    XMapping G = new XMapping(dst1, Y, em_t, "mapping");
    XCtx J = F.apply0(I);
    return G.delta(J);
}
Also used : HashMap(java.util.HashMap) FOED(catdata.fpql.XExp.XSOED.FOED) LinkedList(java.util.LinkedList) Triple(catdata.Triple) XSchema(catdata.fpql.XExp.XSchema) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) Pair(catdata.Pair) XPair(catdata.fpql.XExp.XPair)

Example 75 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class XOps method visit.

@Override
public XObject visit(XProgram env, XToQuery e) {
    Object o = e.inst.accept(env, this);
    if (!(o instanceof XCtx)) {
        throw new RuntimeException("Not instance: " + o);
    }
    XCtx c = (XCtx) o;
    int i = 0;
    // Map m1 = new HashMap();
    Map m2 = new HashMap();
    // Map mty = new HashMap();
    Map from = new HashMap<>();
    for (Object t : c.terms()) {
        // m1.put("v_v"+i, t);
        m2.put(t, "v_v" + i);
        from.put("v_v" + i, c.type(t).second);
        // from.put("v"+i, c.type(((Pair)t).second);
        i++;
    }
    List where = new LinkedList<>();
    Function f = x -> {
        Object j = m2.get(x);
        if (j == null) {
            return x;
        }
        return j;
    };
    for (Object k : c.eqs) {
        List l = (List) ((Pair) k).first;
        List r = (List) ((Pair) k).second;
        // lookup m2
        where.add(new Pair<>(l.stream().map(f).collect(Collectors.toList()), r.stream().map(f).collect(Collectors.toList())));
    }
    Flower iii = new Flower(new HashMap<>(), from, where, e.applyTo);
    return iii.accept(env, this);
}
Also used : Var(catdata.fpql.XExp.Var) XCoApply(catdata.fpql.XExp.XCoApply) XToQuery(catdata.fpql.XExp.XToQuery) XTy(catdata.fpql.XExp.XTy) XRel(catdata.fpql.XExp.XRel) XInst(catdata.fpql.XExp.XInst) Map(java.util.Map) XPi(catdata.fpql.XExp.XPi) Pair(catdata.Pair) XPushout(catdata.fpql.XExp.XPushout) XGrothLabels(catdata.fpql.XExp.XGrothLabels) XLabel(catdata.fpql.XExp.XLabel) XExpVisitor(catdata.fpql.XExp.XExpVisitor) XSigma(catdata.fpql.XExp.XSigma) Collectors(java.util.stream.Collectors) Apply(catdata.fpql.XExp.Apply) List(java.util.List) XTT(catdata.fpql.XExp.XTT) Flower(catdata.fpql.XExp.Flower) Triple(catdata.Triple) XSchema(catdata.fpql.XExp.XSchema) XCoprod(catdata.fpql.XExp.XCoprod) XOne(catdata.fpql.XExp.XOne) XSuperED(catdata.fpql.XExp.XSuperED) FLOWER2(catdata.fpql.XExp.FLOWER2) XInj(catdata.fpql.XExp.XInj) XUnit(catdata.fpql.XExp.XUnit) XMapConst(catdata.fpql.XExp.XMapConst) HashMap(java.util.HashMap) Function(java.util.function.Function) Compose(catdata.fpql.XExp.Compose) XConst(catdata.fpql.XExp.XConst) XFn(catdata.fpql.XExp.XFn) XCounit(catdata.fpql.XExp.XCounit) XIdPoly(catdata.fpql.XExp.XIdPoly) XVoid(catdata.fpql.XExp.XVoid) LinkedList(java.util.LinkedList) XMatch(catdata.fpql.XExp.XMatch) XProj(catdata.fpql.XExp.XProj) XPair(catdata.fpql.XExp.XPair) XSOED(catdata.fpql.XExp.XSOED) XTransConst(catdata.fpql.XExp.XTransConst) Util(catdata.Util) XEq(catdata.fpql.XExp.XEq) Id(catdata.fpql.XExp.Id) Iter(catdata.fpql.XExp.Iter) FOED(catdata.fpql.XExp.XSOED.FOED) XDelta(catdata.fpql.XExp.XDelta) XUberPi(catdata.fpql.XExp.XUberPi) XFF(catdata.fpql.XExp.XFF) XTimes(catdata.fpql.XExp.XTimes) Flower(catdata.fpql.XExp.Flower) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Function(java.util.function.Function) List(java.util.List) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap)

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