Search in sources :

Example 1 with Signature

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

the class PSMGen method findEquiv.

private static Path findEquiv(Node c, Mapping f, Edge e) throws FQLException {
    Signature C = f.source;
    Signature D = f.target;
    FinCat<Node, Path> C0 = C.toCategory2().first;
    for (Arr<Node, Path> peqc : C0.arrows) {
        Path path = peqc.arr;
        // Path path = new Path(f.source, p);
        if (!path.source.equals(c)) {
            continue;
        }
        Path path_f = f.appy(D, path);
        Fn<Path, Arr<Node, Path>> F = D.toCategory2().second;
        if (F.of(path_f).equals(F.of(new Path(D, e)))) {
            return path;
        }
    }
    throw new FQLException("Could not find path mapping to " + e);
}
Also used : Path(catdata.fql.decl.Path) Arr(catdata.fql.cat.Arr) FQLException(catdata.fql.FQLException) Signature(catdata.fql.decl.Signature) Node(catdata.fql.decl.Node)

Example 2 with Signature

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

the class PSMGen method sigma.

public static List<PSM> sigma(Mapping F, String pre, String inst) throws FQLException {
    Signature C = F.source;
    Signature D = F.target;
    List<PSM> ret = new LinkedList<>();
    if (!FinFunctor.isDiscreteOpFib(F.toFunctor2().first)) {
        throw new FQLException("Not a discrete op-fibration");
    }
    for (Node d : D.nodes) {
        List<Flower> tn = new LinkedList<>();
        for (Node c : C.nodes) {
            if (F.nm.get(c).equals(d)) {
                tn.add(new CopyFlower(inst + "_" + c.string, "c0", "c1"));
            }
        }
        if (tn.isEmpty()) {
            continue;
        }
        SQL y = foldUnion(tn);
        ret.add(new InsertSQL(pre + "_" + d.string, y, "c0", "c1"));
    }
    for (Edge e : D.edges) {
        Node d = e.source;
        // Node d0 = e.target;
        List<Flower> tn = new LinkedList<>();
        for (Node c : C.nodes) {
            if (F.nm.get(c).equals(d)) {
                Path pc = findEquiv(c, F, e);
                Flower q = compose(inst, pc);
                tn.add(q);
            }
        }
        if (tn.isEmpty()) {
            continue;
        }
        SQL y = foldUnion(tn);
        ret.add(new InsertSQL(pre + "_" + e.name, y, "c0", "c1"));
    }
    for (Attribute<Node> a : D.attrs) {
        Node d = a.source;
        // Node d0 = e.target;
        List<Flower> tn = new LinkedList<>();
        for (Node c : C.nodes) {
            if (F.nm.get(c).equals(d)) {
                Attribute<Node> pc = findEquiv(c, F, a);
                Flower q = new CopyFlower(inst + "_" + pc.name, "c0", "c1");
                tn.add(q);
            }
        }
        if (tn.isEmpty()) {
            continue;
        }
        SQL y = foldUnion(tn);
        ret.add(new InsertSQL(pre + "_" + a.name, y, "c0", "c1"));
    }
    return ret;
}
Also used : Path(catdata.fql.decl.Path) Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) FQLException(catdata.fql.FQLException) Signature(catdata.fql.decl.Signature) Edge(catdata.fql.decl.Edge)

Example 3 with Signature

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

the class PSMNot method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        Signature sig0 = new Signature(sig.nodes, sig.edges, new LinkedList<>(), sig.eqs);
        Pair<Map<Node, Triple<Instance, Map<Object, Path>, Map<Path, Object>>>, Map<Edge, Transform>> H1 = interp.prop1.get(prop);
        Pair<Instance, Map<Node, Pair<Map<Object, Instance>, Map<Instance, Object>>>> H2 = interp.prop2.get(prop);
        Instance prp = new Instance(sig, PSMGen.gather(prop, sig, state));
        Map<Node, Map<Object, Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>> I1 = interp.prop3.get(prop);
        Map<Node, Map<Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Object>> I2 = interp.prop4.get(prop);
        List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
        for (Node c : sig.nodes) {
            List<Pair<Object, Object>> data0 = new LinkedList<>();
            Triple<Instance, Map<Object, Path>, Map<Path, Object>> Hc = H1.first.get(c);
            for (Object id : prp.getNode(c)) {
                Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> id0 = I1.get(c).get(id);
                Instance A = H2.second.get(c).first.get(id0.first);
                Instance notA = calcSub(sig0, /*H1, */
                Hc, A);
                Object notId = H2.second.get(c).second.get(notA);
                Object x = I2.get(c).get(new Pair<>(notId, id0.second));
                data0.add(new Pair<>(id, x));
            }
            data.add(new Pair<>(c.string, data0));
        }
        Transform ret = new Transform(prp, prp, data);
        PSMGen.shred(pre, ret, state);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Instance(catdata.fql.decl.Instance) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Signature(catdata.fql.decl.Signature) Transform(catdata.fql.decl.Transform) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pair(catdata.Pair)

Example 4 with Signature

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

the class Relationalizer method terminal.

public static Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> terminal(FQLProgram prog, SigExp.Const sig0) {
    Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> jjj = cache.get(new Pair<>(prog, sig0));
    if (jjj != null) {
        // so do not have to recompute when doing omega operations
        return jjj;
    }
    try {
        Signature sig = sig0.toSig(prog);
        Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> start = sig.toCategory2();
        // FinCat<Node, Path> cat = start.first;
        Fn<Path, Arr<Node, Path>> map = start.second;
        Map<Node, List<Pair<Arr<Node, Path>, Attribute<Node>>>> obs = sig.obs();
        Map<Node, List<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m = sig.obsbar();
        List<Pair<String, List<Pair<Object, Object>>>> nodes = new LinkedList<>();
        List<Pair<String, List<Pair<Object, Object>>>> attrs = new LinkedList<>();
        List<Pair<String, List<Pair<Object, Object>>>> arrows = new LinkedList<>();
        // Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
        Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m1 = new HashMap<>();
        Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>> m2 = new HashMap<>();
        int i = 0;
        for (Node n : sig.nodes) {
            Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> map1 = new HashMap<>();
            Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object> map2 = new HashMap<>();
            List<Pair<Object, Object>> set = new LinkedList<>();
            m1.put(n, map1);
            m2.put(n, map2);
            for (LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> i2 : m.get(n)) {
                Object o = Integer.toString(++i);
                map1.put(o, i2);
                map2.put(i2, o);
                set.add(new Pair<>(o, o));
            }
            nodes.add(new Pair<>(n.string, set));
        }
        for (Attribute<Node> a : sig.attrs) {
            List<Pair<Object, Object>> set = new LinkedList<>();
            for (Pair<Object, Object> k : PropPSM.lookup(nodes, a.source.string)) {
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = m1.get(a.source).get(k.first);
                set.add(new Pair<>(k.first, new_id.get(new Pair<>(map.of(new Path(sig, a.source)), a))));
            }
            attrs.add(new Pair<>(a.name, set));
        }
        for (Edge a : sig.edges) {
            List<Pair<Object, Object>> set = new LinkedList<>();
            for (Pair<Object, Object> k : PropPSM.lookup(nodes, a.source.string)) {
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = m1.get(a.source).get(k.first);
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = PropPSM.truncate2(sig, new_id, new Arr<>(new Path(sig, a), a.source, a.target), obs.get(a.target));
                // LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = PropPSM.truncate(sig, new_id, a, m.get(a.target));
                Object o = m2.get(a.target).get(new_id0);
                set.add(new Pair<>(k.first, o));
            }
            arrows.add(new Pair<>(a.name, set));
        }
        // Instance ret0 = new Instance(sig, data);
        Const retX = new Const(nodes, attrs, arrows, sig.toConst());
        Triple<Const, Map<Node, Map<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>, Map<Node, Map<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Object>>> ret = new Triple<>(retX, m1, m2);
        cache.put(new Pair<>(prog, sig0), ret);
        return ret;
    } catch (FQLException fe) {
        throw new RuntimeException(fe.getLocalizedMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Attribute(catdata.fql.decl.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FinCat(catdata.fql.cat.FinCat) Node(catdata.fql.decl.Node) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Path(catdata.fql.decl.Path) Const(catdata.fql.decl.InstExp.Const) Fn(catdata.fql.Fn) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Signature(catdata.fql.decl.Signature) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge)

Example 5 with Signature

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

the class FullSigma method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    Signature C = f.source;
    Signature D = f.target;
    List<Pair<String, List<Pair<Object, Object>>>> I0 = PSMGen.gather(inst, C, state);
    try {
        Instance I = new Instance(C, I0);
        interp.sigmas.put(pre, interp.guid);
        Quad<Instance, Map<Node, Map<Object, Integer>>, Map<Node, Map<Integer, Object>>, Map<Object, List<Pair<String, Object>>>> xxx = LeftKanSigma.fullSigmaWithAttrs(interp, f, I, null, null, null);
        interp.sigmas2.put(pre, interp.guid);
        Instance J = xxx.first;
        Map<Node, Map<Object, Integer>> yyy = xxx.second;
        for (Node n : C.nodes) {
            state.put(pre + "_" + n.string + "_e", conv2(yyy.get(n)));
        }
        for (Node n : D.nodes) {
            state.put(pre + "_" + n.string, conv(J.data.get(n.string)));
        }
        for (Edge n : D.edges) {
            state.put(pre + "_" + n.name, conv(J.data.get(n.name)));
        }
        for (Attribute<Node> n : D.attrs) {
            state.put(pre + "_" + n.name, conv(J.data.get(n.name)));
        }
        Set<Map<Object, Object>> l = new HashSet<>();
        for (Object k : xxx.fourth.keySet()) {
            List<Pair<String, Object>> v = xxx.fourth.get(k);
            if (v.isEmpty()) {
                continue;
            }
            Map<Object, Object> m = new HashMap<>();
            m.put("c0", k);
            boolean first = true;
            String rest = "";
            for (Pair<String, Object> p : v) {
                if (first) {
                    first = false;
                    m.put("c1", p.first);
                    m.put("c2", p.second);
                } else {
                    rest += p.first;
                }
            }
            m.put("c3", rest);
            l.add(m);
        }
        state.put(pre + "_lineage", l);
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException("Error in instance " + pre + ": " + e.getLocalizedMessage());
    }
}
Also used : Instance(catdata.fql.decl.Instance) HashMap(java.util.HashMap) Node(catdata.fql.decl.Node) Signature(catdata.fql.decl.Signature) HashMap(java.util.HashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Aggregations

Signature (catdata.fql.decl.Signature)19 LinkedList (java.util.LinkedList)14 Pair (catdata.Pair)13 Node (catdata.fql.decl.Node)13 FQLException (catdata.fql.FQLException)11 HashMap (java.util.HashMap)11 Attribute (catdata.fql.decl.Attribute)10 Instance (catdata.fql.decl.Instance)10 Edge (catdata.fql.decl.Edge)9 Map (java.util.Map)7 Arr (catdata.fql.cat.Arr)6 Path (catdata.fql.decl.Path)6 Transform (catdata.fql.decl.Transform)6 LinkedHashMap (java.util.LinkedHashMap)6 Triple (catdata.Triple)5 List (java.util.List)5 HashSet (java.util.HashSet)4 Fn (catdata.fql.Fn)3 FinCat (catdata.fql.cat.FinCat)3 InstExp (catdata.fql.decl.InstExp)3