use of catdata.fql.decl.Attribute in project fql by CategoricalData.
the class FinCat method toSig.
/**
* Converts a category to a signature.
*
* @return a signature and isomorphism
* @throws FQLException
*/
public Quad<Signature, Pair<Map<Obj, String>, Map<String, Obj>>, Pair<Map<Arr<Obj, Arrow>, String>, Map<String, Arr<Obj, Arrow>>>, Pair<Map<Attribute<Obj>, String>, Map<String, Attribute<Obj>>>> toSig(Map<String, Type> types) throws FQLException {
Map<Attribute<Obj>, String> attM = new HashMap<>();
Map<String, Attribute<Obj>> attM2 = new HashMap<>();
int ax = 0;
List<String> objs = new LinkedList<>();
List<Triple<String, String, String>> attrs0 = new LinkedList<>();
int i = 0;
Map<String, Obj> objM = new HashMap<>();
Map<Obj, String> objM2 = new HashMap<>();
for (Obj o : objects) {
objM2.put(o, "obj" + i);
objM.put("obj" + i, o);
objs.add("obj" + i);
i++;
}
if (attrs != null) {
for (Attribute<Obj> att : attrs) {
attM.put(att, "attrib" + ax);
attM2.put("attrib" + ax, att);
attrs0.add(new Triple<>("attrib" + ax++, objM2.get(att.source), att.target.toString()));
}
}
List<Triple<String, String, String>> arrs = new LinkedList<>();
int j = 0;
Map<String, Arr<Obj, Arrow>> arrM = new HashMap<>();
Map<Arr<Obj, Arrow>, String> arrM2 = new HashMap<>();
for (Arr<Obj, Arrow> a : arrows) {
if (isId(a)) {
continue;
}
arrM.put("arrow" + j, a);
arrM2.put(a, "arrow" + j);
arrs.add(new Triple<>(arrM2.get(a), objM2.get(a.src), objM2.get(a.dst)));
j++;
}
LinkedList<Pair<List<String>, List<String>>> eqs = new LinkedList<>();
for (Pair<Arr<Obj, Arrow>, Arr<Obj, Arrow>> k : composition.keySet()) {
Arr<Obj, Arrow> v = composition.get(k);
String s = arrM2.get(k.first);
String t = arrM2.get(k.second);
String u = arrM2.get(v);
String ob = objM2.get(v.src);
List<String> lhs = new LinkedList<>();
List<String> rhs = new LinkedList<>();
lhs.add(ob);
rhs.add(ob);
if (s != null) {
lhs.add(s);
}
if (t != null) {
lhs.add(t);
}
if (u != null) {
rhs.add(u);
}
if (!lhs.equals(rhs)) {
eqs.add(new Pair<>(lhs, rhs));
}
}
Signature ret2 = new Signature(types, objs, attrs0, arrs, eqs);
Quad<Signature, Pair<Map<Obj, String>, Map<String, Obj>>, Pair<Map<Arr<Obj, Arrow>, String>, Map<String, Arr<Obj, Arrow>>>, Pair<Map<Attribute<Obj>, String>, Map<String, Attribute<Obj>>>> retret = new Quad<>(ret2, new Pair<>(objM2, objM), new Pair<>(arrM2, arrM), new Pair<>(attM, attM2));
return retret;
}
Aggregations