use of catdata.fql.decl.Attribute 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.Attribute 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.Attribute in project fql by CategoricalData.
the class Chase method sigma.
public static Instance sigma(Mapping m, Instance i) throws FQLException {
Triple<Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>> kkk = m.toEDs();
Signature cd = kkk.second.first;
Map<String, Set<Pair<Object, Object>>> I = new HashMap<>();
for (Node n : cd.nodes) {
I.put(n.string, new HashSet<>());
}
for (Edge n : cd.edges) {
I.put(n.name, new HashSet<>());
}
for (Attribute<Node> n : cd.attrs) {
I.put(n.name, new HashSet<>());
}
for (String k : i.data.keySet()) {
I.put("src_" + k, i.data.get(k));
}
List<EmbeddedDependency> eds0 = Signature.toED("", kkk.second);
Pair<List<Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>>>, List<Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>>>> zzz = split(eds0);
Set<String> keys = new HashSet<>();
for (Node n : m.target.nodes) {
keys.add("dst_" + n.string);
}
for (Edge n : m.target.edges) {
keys.add("dst_" + n.name);
}
for (Attribute<Node> n : m.target.attrs) {
keys.add("dst_" + n.name);
}
Map<String, Set<Pair<Object, Object>>> res = chase(keys, zzz, I, KIND.PARALLEL);
Map<String, Set<Pair<Object, Object>>> res0 = new HashMap<>();
for (Node n : m.target.nodes) {
res0.put(n.string, res.get("dst_" + n.string));
}
for (Edge n : m.target.edges) {
res0.put(n.name, res.get("dst_" + n.name));
}
for (Attribute<Node> n : m.target.attrs) {
res0.put(n.name, res.get("dst_" + n.name));
}
Instance ret = new Instance(m.target, res0);
return ret;
}
use of catdata.fql.decl.Attribute in project fql by CategoricalData.
the class Chase method delta.
public static Instance delta(Mapping m, Instance i) throws FQLException {
Triple<Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>> kkk = m.toEDs();
Signature cd = m.toEDs().first.first;
Map<String, Set<Pair<Object, Object>>> I = new HashMap<>();
for (Node n : cd.nodes) {
I.put(n.string, new HashSet<>());
}
for (Edge n : cd.edges) {
I.put(n.name, new HashSet<>());
}
for (Attribute<Node> n : cd.attrs) {
I.put(n.name, new HashSet<>());
}
for (String k : i.data.keySet()) {
I.put("dst_" + k, i.data.get(k));
}
List<EmbeddedDependency> eds0 = Signature.toED("", kkk.first);
Pair<List<Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>>>, List<Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>>>> zzz = split(eds0);
Set<String> keys = new HashSet<>();
for (Node n : m.target.nodes) {
keys.add("src_" + n.string);
}
for (Edge n : m.target.edges) {
keys.add("src_" + n.name);
}
for (Attribute<Node> n : m.target.attrs) {
keys.add("src_" + n.name);
}
// changed
Map<String, Set<Pair<Object, Object>>> res = chase(keys, zzz, I, KIND.HYBRID);
Map<String, Set<Pair<Object, Object>>> res0 = new HashMap<>();
for (Node n : m.source.nodes) {
res0.put(n.string, res.get("src_" + n.string));
}
for (Edge n : m.source.edges) {
res0.put(n.name, res.get("src_" + n.name));
}
for (Attribute<Node> n : m.source.attrs) {
res0.put(n.name, res.get("src_" + n.name));
}
Instance ret = new Instance(m.source, res0);
return ret;
}
use of catdata.fql.decl.Attribute in project fql by CategoricalData.
the class CategoryOfElements method build.
private static Pair<Graph<Pair<Node, Object>, Pair<Path, Integer>>, HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>>> build(Instance i) throws FQLException {
FinCat<Node, Path> c = i.thesig.toCategory2().first;
HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>> map = new HashMap<>();
Graph<Pair<Node, Object>, Pair<Path, Integer>> g2 = new DirectedSparseMultigraph<>();
for (Node n : c.objects) {
for (Pair<Object, Object> o : i.data.get(n.string)) {
Pair<Node, Object> xx = new Pair<>(n, o.first);
g2.addVertex(xx);
List<Attribute<Node>> attrs = i.thesig.attrsFor(n);
Map<Attribute<Node>, Object> m = new HashMap<>();
for (Attribute<Node> attr : attrs) {
Object a = lookup(i.data.get(attr.name), o.first);
m.put(attr, a);
}
map.put(xx, m);
}
}
int j = 0;
for (Pair<Node, Object> x : g2.getVertices()) {
for (Pair<Node, Object> y : g2.getVertices()) {
Set<Arr<Node, Path>> h = c.hom(x.first, y.first);
for (Arr<Node, Path> arr : h) {
if (c.isId(arr)) {
continue;
}
if (!DefunctGlobalOptions.debug.fql.ALL_GR_PATHS && arr.arr.path.size() != 1) {
continue;
}
if (doLookup(i, arr.arr, x.second, y.second)) {
g2.addEdge(new Pair<>(arr.arr, j++), x, y);
}
}
}
}
return new Pair<>(g2, map);
}
Aggregations