Search in sources :

Example 21 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class LeftKanSigma method reAttr.

private static Instance reAttr(Map<Node, Map<Object, Integer>> D, Signature thesig, Instance i, Map<Attribute<Node>, Map<Object, Object>> map0) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> d = new HashMap<>();
    for (Node k : i.thesig.nodes) {
        d.put(k.string, i.data.get(k.string));
    }
    for (Edge k : thesig.edges) {
        d.put(k.name, i.data.get(k.name));
    }
    Map<Object, Object> map = new HashMap<>();
    for (Attribute<Node> k : map0.keySet()) {
        Map<Object, Object> v = map0.get(k);
        for (Object k0 : v.keySet()) {
            Object v0 = v.get(k0);
            if (map.containsKey(k0)) {
                throw new RuntimeException();
            }
            map.put(k0, v0);
        }
    }
    for (Attribute<Node> k : thesig.attrs) {
        Set<Pair<Object, Object>> t = new HashSet<>();
        for (Pair<Object, Object> v : i.data.get(k.name + "_edge")) {
            Object v1 = getFrom(k, D, map, /* ().get(k) */
            v.second.toString());
            t.add(new Pair<>(v.first, v1));
        }
        d.put(k.name, t);
    }
    return new Instance(thesig, d);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 22 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class LeftKanSigma method deAttr.

private static Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> deAttr(PSMInterp inter, Instance i, Signature sig) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> d = new HashMap<>();
    Map<Attribute<Node>, Map<Object, Object>> ret = new HashMap<>();
    for (Node k : i.thesig.nodes) {
        d.put(k.string, i.data.get(k.string));
    }
    for (Edge k : i.thesig.edges) {
        d.put(k.name, i.data.get(k.name));
    }
    for (Attribute<Node> k : i.thesig.attrs) {
        Map<Object, Object> ret0 = new HashMap<>();
        Set<Pair<Object, Object>> tn = new HashSet<>();
        Set<Pair<Object, Object>> te = new HashSet<>();
        for (Pair<Object, Object> v : i.data.get(k.name)) {
            Object x = revLookup(ret0, v.second);
            if (x == null) {
                x = ++inter.guid;
                ret0.put(x.toString(), v.second);
            }
            tn.add(new Pair<>(x.toString(), x.toString()));
            te.add(new Pair<>(v.first, x.toString()));
        }
        ret.put(k, ret0);
        d.put(k.name, tn);
        d.put(k.name + "_edge", te);
    }
    return new Pair<>(new Instance(sig, d), ret);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Attribute(catdata.fql.decl.Attribute) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) HashMap(java.util.HashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 23 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class LeftKanSigma method deAttr.

private static void deAttr(Signature source) {
    for (Attribute<Node> a : source.attrs) {
        Node dst = new Node(a.name);
        source.nodes.add(dst);
        source.edges.add(new Edge(a.name + "_edge", a.source, dst));
    }
    source.attrs.clear();
// source.doColors();
}
Also used : Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge)

Example 24 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class Inst method stuff.

// base^exp
public static FinCat<Mapping, Map<Node, Path>> stuff(Signature base, Signature exp) throws FQLException {
    Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> xxx = base.toCategory2();
    FinCat<Node, Path> base0 = xxx.first;
    Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> yyy = exp.toCategory2();
    FinCat<Node, Path> exp0 = yyy.first;
    List<LinkedHashMap<Node, Node>> nms = homomorphs(exp.nodes, base.nodes);
    List<Mapping> mappings = new LinkedList<>();
    for (LinkedHashMap<Node, Node> nm : nms) {
        LinkedHashMap<Attribute<Node>, List<Attribute<Node>>> ams = new LinkedHashMap<>();
        for (Attribute<Node> a : exp.attrs) {
            ams.put(a, base.attrsFor(nm.get(a.source)));
        }
        LinkedHashMap<Edge, List<Path>> ems = new LinkedHashMap<>();
        for (Edge e : exp.edges) {
            Set<Arr<Node, Path>> s = base0.hom(nm.get(e.source), nm.get(e.target));
            List<Path> p = new LinkedList<>();
            for (Arr<Node, Path> sx : s) {
                p.add(sx.arr);
            }
            ems.put(e, p);
        }
        List<LinkedHashMap<Attribute<Node>, Attribute<Node>>> ams0 = homomorphs(ams);
        List<LinkedHashMap<Edge, Path>> ems0 = homomorphs(ems);
        for (LinkedHashMap<Attribute<Node>, Attribute<Node>> am : ams0) {
            for (LinkedHashMap<Edge, Path> em : ems0) {
                try {
                    Mapping m = new Mapping(true, exp, base, nm, em, am);
                    mappings.add(m);
                } catch (Exception e) {
                }
            }
        }
    }
    List<Arr<Mapping, Map<Node, Path>>> arrows = new LinkedList<>();
    for (Mapping s : mappings) {
        for (Mapping t : mappings) {
            Map<Node, List<Path>> map = new HashMap<>();
            for (Node n : exp.nodes) {
                List<Path> p = new LinkedList<>();
                for (Arr<Node, Path> k : base0.hom(s.nm.get(n), t.nm.get(n))) {
                    p.add(k.arr);
                }
                map.put(n, p);
            }
            List<LinkedHashMap<Node, Path>> map0 = homomorphs(map);
            outer: for (Map<Node, Path> k : map0) {
                for (Node x : k.keySet()) {
                    for (Node y : k.keySet()) {
                        for (Arr<Node, Path> f : exp0.hom(x, y)) {
                            Path lhs = Path.append(base, k.get(x), t.appy(base, f.arr));
                            Path rhs = Path.append(base, s.appy(base, f.arr), k.get(y));
                            if (!xxx.second.of(lhs).equals(xxx.second.of(rhs))) {
                                continue outer;
                            }
                        }
                    }
                }
                arrows.add(new Arr<>(k, s, t));
            }
        }
    }
    Map<Mapping, Arr<Mapping, Map<Node, Path>>> identities = new HashMap<>();
    for (Mapping m : mappings) {
        Map<Node, Path> map = new HashMap<>();
        for (Node n : m.source.nodes) {
            map.put(n, new Path(m.target, m.nm.get(n)));
        }
        Arr<Mapping, Map<Node, Path>> uuu = new Arr<>(map, m, m);
        identities.put(m, new Arr<>(map, m, m));
        if (!arrows.contains(uuu)) {
            arrows.add(uuu);
        }
    }
    Map<Pair<Arr<Mapping, Map<Node, Path>>, Arr<Mapping, Map<Node, Path>>>, Arr<Mapping, Map<Node, Path>>> composition = new HashMap<>();
    for (Arr<Mapping, Map<Node, Path>> a1 : arrows) {
        for (Arr<Mapping, Map<Node, Path>> a2 : arrows) {
            if (!a1.dst.equals(a2.src)) {
                continue;
            }
            Map<Node, Path> m = new HashMap<>();
            for (Node n : exp.nodes) {
                m.put(n, xxx.second.of(Path.append(base, a1.arr.get(n), a2.arr.get(n))).arr);
            }
            composition.put(new Pair<>(a1, a2), new Arr<>(m, a1.src, a2.dst));
        }
    }
    return new FinCat<>(mappings, arrows, composition, identities);
}
Also used : Attribute(catdata.fql.decl.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(catdata.fql.decl.Node) Mapping(catdata.fql.decl.Mapping) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Path(catdata.fql.decl.Path) Fn(catdata.fql.Fn) LinkedList(java.util.LinkedList) FQLException(catdata.fql.FQLException) Edge(catdata.fql.decl.Edge) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 25 with Node

use of catdata.fql.decl.Node in project fql by CategoricalData.

the class Inst method hom.

/*
	private static List<Mapping> bistuff(Signature base, Signature exp)
			throws FQLException {

		if (base.nodes.size() != exp.nodes.size()) {
			return null;
		}
		if (base.attrs.size() != exp.attrs.size()) {
			return null;
		}

		Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> xxx = base
				.toCategory2();
		FinCat<Node, Path> base0 = xxx.first;
		Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> yyy = exp
				.toCategory2();
		FinCat<Node, Path> exp0 = yyy.first;

		if (xxx.first.arrows.size() != yyy.first.arrows.size()) {
			return null;
		}

		List<LinkedHashMap<Node, Node>> nms = bijections(exp.nodes, base.nodes);

		List<Mapping> ret = new LinkedList<>();
		outmost: for (LinkedHashMap<Node, Node> nm : nms) {
			Map<Pair<Node, Node>, List<LinkedHashMap<Arr<Node, Path>, Arr<Node, Path>>>> bijm = new HashMap<>();
			Map<Node, List<LinkedHashMap<Attribute<Node>, Attribute<Node>>>> atm = new HashMap<>();
			for (Node s : nm.keySet()) {
				List<Attribute<Node>> sa = exp.attrsFor(s);
				List<Attribute<Node>> ta = base.attrsFor(nm.get(s));
				if (sa.size() != ta.size()) {
					continue outmost;
				}
				List<LinkedHashMap<Attribute<Node>, Attribute<Node>>> am = bijections(
						sa, ta);
				Iterator<LinkedHashMap<Attribute<Node>, Attribute<Node>>> it = am
						.iterator();
				outer: while (it.hasNext()) {
					Map<Attribute<Node>, Attribute<Node>> k = it.next();
					for (Entry<Attribute<Node>, Attribute<Node>> v : k
							.entrySet()) {
						if (!v.getKey().target.equals(v.getValue().target)) {
							it.remove();
							continue outer;
						}
					}
				}
				if (am.isEmpty() && !sa.isEmpty()) {
					continue outmost;
				}
				atm.put(s, am);
				Node sx = nm.get(s);
				for (Node t : nm.keySet()) {
					Set<Arr<Node, Path>> h1 = exp0.hom(s, t);
					Node st = nm.get(t);
					Set<Arr<Node, Path>> h2 = base0.hom(sx, st);
					if (h1.size() != h2.size()) {
						continue outmost;
					}
					List<LinkedHashMap<Arr<Node, Path>, Arr<Node, Path>>> bij = bijections(
							new LinkedList<>(h1), new LinkedList<>(h2));
					if (!bij.isEmpty()) {
						bijm.put(new Pair<>(s, t), bij);
					}
				}
			}

			List<LinkedHashMap<Pair<Node, Node>, LinkedHashMap<Arr<Node, Path>, Arr<Node, Path>>>> bijmX = homomorphs(bijm);
			List<LinkedHashMap<Node, LinkedHashMap<Attribute<Node>, Attribute<Node>>>> atmX = homomorphs(atm);
	
			List<LinkedHashMap<Arr<Node, Path>, Arr<Node, Path>>> bijmZ = new LinkedList<>();
			for (LinkedHashMap<Pair<Node, Node>, LinkedHashMap<Arr<Node, Path>, Arr<Node, Path>>> k : bijmX) {
				LinkedHashMap<Arr<Node, Path>, Arr<Node, Path>> bijmY = new LinkedHashMap<>();
				for (Entry<Pair<Node, Node>, LinkedHashMap<Arr<Node, Path>, Arr<Node, Path>>> v : k
						.entrySet()) {
					bijmY.putAll(v.getValue());
				}
				bijmZ.add(bijmY);
			}

			List<LinkedHashMap<Attribute<Node>, Attribute<Node>>> atmZ = new LinkedList<>();
			for (LinkedHashMap<Node, LinkedHashMap<Attribute<Node>, Attribute<Node>>> k : atmX) {
				LinkedHashMap<Attribute<Node>, Attribute<Node>> atmY = new LinkedHashMap<>();
				for (Entry<Node, LinkedHashMap<Attribute<Node>, Attribute<Node>>> v : k
						.entrySet()) {
					atmY.putAll(v.getValue());
				}
				atmZ.add(atmY);
			}
			if (exp.attrs.isEmpty()) {
				atmZ.add(new LinkedHashMap<>());
			}
			if (exp.edges.isEmpty()) {
				bijmZ.add(new LinkedHashMap<>());
			}

			for (Map<Arr<Node, Path>, Arr<Node, Path>> f : bijmZ) {
				LinkedHashMap<Edge, Path> em = new LinkedHashMap<>();
				for (Edge e : exp.edges) {
					em.put(e, f.get(yyy.second.of(new Path(exp, e))).arr);
				}
				for (LinkedHashMap<Attribute<Node>, Attribute<Node>> g : atmZ) {
					try {
						Mapping m = new Mapping(true, exp, base, nm, em, g);
						ret.add(m);
					} catch (FQLException fe) {
						// fe.printStackTrace();
					}
				}
			}
			// break;
		}

		return ret;
	}
*/
// I => J
public static List<Transform> hom(Instance I, Instance J) {
    if (!I.thesig.equals(J.thesig)) {
        throw new RuntimeException();
    }
    List<Transform> ret = new LinkedList<>();
    Map<Node, List<LinkedHashMap<Pair<Object, Object>, Pair<Object, Object>>>> m = new HashMap<>();
    for (Node n : I.thesig.nodes) {
        List<Pair<Object, Object>> src = new LinkedList<>(I.data.get(n.string));
        List<Pair<Object, Object>> dst = new LinkedList<>(J.data.get(n.string));
        List<LinkedHashMap<Pair<Object, Object>, Pair<Object, Object>>> h = homomorphs(src, dst);
        m.put(n, h);
    }
    List<LinkedHashMap<Node, LinkedHashMap<Pair<Object, Object>, Pair<Object, Object>>>> map = homomorphs(m);
    for (LinkedHashMap<Node, LinkedHashMap<Pair<Object, Object>, Pair<Object, Object>>> t : map) {
        try {
            List<Pair<String, List<Pair<Object, Object>>>> l = new LinkedList<>();
            for (Entry<Node, LinkedHashMap<Pair<Object, Object>, Pair<Object, Object>>> u : t.entrySet()) {
                l.add(new Pair<>(u.getKey().string, conv(u.getValue())));
            }
            Transform tr = new Transform(I, J, l);
            ret.add(tr);
        } catch (Exception e) {
        }
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) FQLException(catdata.fql.FQLException) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) LinkedList(java.util.LinkedList) Transform(catdata.fql.decl.Transform) Pair(catdata.Pair)

Aggregations

Node (catdata.fql.decl.Node)51 Pair (catdata.Pair)38 HashMap (java.util.HashMap)36 Edge (catdata.fql.decl.Edge)33 LinkedList (java.util.LinkedList)26 LinkedHashMap (java.util.LinkedHashMap)25 Instance (catdata.fql.decl.Instance)22 Path (catdata.fql.decl.Path)21 Map (java.util.Map)21 FQLException (catdata.fql.FQLException)20 Attribute (catdata.fql.decl.Attribute)19 HashSet (java.util.HashSet)19 Arr (catdata.fql.cat.Arr)14 Signature (catdata.fql.decl.Signature)13 Set (java.util.Set)13 Transform (catdata.fql.decl.Transform)11 List (java.util.List)10 Triple (catdata.Triple)5 Fn (catdata.fql.Fn)4 FinCat (catdata.fql.cat.FinCat)3