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);
}
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);
}
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();
}
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);
}
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;
}
Aggregations