Search in sources :

Example 1 with Arr

use of catdata.fql.cat.Arr 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 Arr

use of catdata.fql.cat.Arr 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 3 with Arr

use of catdata.fql.cat.Arr in project fql by CategoricalData.

the class PSMUnChi method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        Map<Object, Object> m1 = new HashMap<>();
        Map<Object, Object> m2 = new HashMap<>();
        Instance B = new Instance(sig, PSMGen.gather(b, sig, state));
        Instance P = new Instance(sig, PSMGen.gather(prop, sig, state));
        // Instance P = interp.prop2.get(prop).first;
        Transform F = new Transform(B, P, PSMGen.gather(f, sig, state));
        Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
        List<Pair<String, List<Pair<Object, Object>>>> data2 = new LinkedList<>();
        for (Node d : sig.nodes) {
            Instance tofind = interp.prop1.get(prop).first.get(d).first;
            Object found = interp.prop2.get(prop).second.get(d).second.get(tofind);
            Set<Pair<Object, Object>> dta = new HashSet<>();
            List<Pair<Object, Object>> dta2 = new LinkedList<>();
            for (Pair<Object, Object> k : B.data.get(d.string)) {
                Object v = lookup(F.data.get(d.string), k.first);
                Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> vv = interp.prop3.get(prop).get(d).get(v);
                if (vv.first.equals(found)) {
                    Object u = Integer.toString(++interp.guid);
                    m1.put(u, k.first);
                    m2.put(k.first, u);
                    dta.add(new Pair<>(u, u));
                    dta2.add(new Pair<>(u, k.first));
                }
            }
            data.put(d.string, dta);
            data2.add(new Pair<>(d.string, dta2));
        }
        for (Edge e : sig.edges) {
            Set<Pair<Object, Object>> dta = new HashSet<>();
            for (Pair<Object, Object> k : data.get(e.source.string)) {
                Object v = m1.get(k.first);
                Object vx = lookup(B.data.get(e.name), v);
                Object vz = m2.get(vx);
                dta.add(new Pair<>(k.first, vz));
            }
            data.put(e.name, dta);
        }
        for (Attribute<Node> e : sig.attrs) {
            Set<Pair<Object, Object>> dta = new HashSet<>();
            for (Pair<Object, Object> k : data.get(e.source.string)) {
                Object v = m1.get(k.first);
                Object vx = lookup(B.data.get(e.name), v);
                dta.add(new Pair<>(k.first, vx));
            }
            data.put(e.name, dta);
        }
        Instance A = new Instance(sig, data);
        Transform T = new Transform(A, B, data2);
        PSMGen.shred(pre, A, state);
        PSMGen.shred(pre + "_trans", T, state);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Instance(catdata.fql.decl.Instance) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Pair(catdata.Pair) HashSet(java.util.HashSet) LinkedList(java.util.LinkedList) Transform(catdata.fql.decl.Transform) Edge(catdata.fql.decl.Edge)

Example 4 with Arr

use of catdata.fql.cat.Arr 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 Arr

use of catdata.fql.cat.Arr in project fql by CategoricalData.

the class ExpPSM method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        Instance Ix = new Instance(sig, PSMGen.gather(I, sig, state));
        Instance Jx = new Instance(sig, PSMGen.gather(J, sig, state));
        IntRef idx = new IntRef(interp.guid);
        Quad<Instance, Map<Pair<Node, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>>>, Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>>, Map<Node, Map<Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>, Object>>> ret = Instance.exp2(idx, Ix, Jx);
        interp.guid = idx.i;
        interp.exps2.put(pre, ret);
        PSMGen.shred(pre, ret.first, state);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getLocalizedMessage());
    }
}
Also used : Arr(catdata.fql.cat.Arr) Path(catdata.fql.decl.Path) Instance(catdata.fql.decl.Instance) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) LinkedHashMap(java.util.LinkedHashMap) IntRef(catdata.IntRef) FQLException(catdata.fql.FQLException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pair(catdata.Pair)

Aggregations

Arr (catdata.fql.cat.Arr)24 Pair (catdata.Pair)21 LinkedHashMap (java.util.LinkedHashMap)20 HashMap (java.util.HashMap)19 FQLException (catdata.fql.FQLException)17 LinkedList (java.util.LinkedList)16 Map (java.util.Map)15 Node (catdata.fql.decl.Node)14 Triple (catdata.Triple)11 Path (catdata.fql.decl.Path)11 Attribute (catdata.fql.decl.Attribute)10 Instance (catdata.fql.decl.Instance)9 HashSet (java.util.HashSet)7 Set (java.util.Set)7 Fn (catdata.fql.Fn)6 Edge (catdata.fql.decl.Edge)6 Signature (catdata.fql.decl.Signature)6 Transform (catdata.fql.decl.Transform)6 PSM (catdata.fql.sql.PSM)6 List (java.util.List)6