Search in sources :

Example 21 with Attribute

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;
}
Also used : Quad(catdata.Quad) Attribute(catdata.fql.decl.Attribute) HashMap(java.util.HashMap) Pair(catdata.Pair) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Signature(catdata.fql.decl.Signature)

Aggregations

Attribute (catdata.fql.decl.Attribute)21 Pair (catdata.Pair)20 Node (catdata.fql.decl.Node)19 HashMap (java.util.HashMap)15 LinkedList (java.util.LinkedList)15 Map (java.util.Map)12 FQLException (catdata.fql.FQLException)11 Instance (catdata.fql.decl.Instance)11 LinkedHashMap (java.util.LinkedHashMap)11 Arr (catdata.fql.cat.Arr)10 Edge (catdata.fql.decl.Edge)10 Path (catdata.fql.decl.Path)10 Signature (catdata.fql.decl.Signature)10 List (java.util.List)8 Triple (catdata.Triple)6 Transform (catdata.fql.decl.Transform)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Fn (catdata.fql.Fn)4 FinCat (catdata.fql.cat.FinCat)3