Search in sources :

Example 36 with Node

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

the class PSMAnd method isect.

private static Instance isect(Instance a, Instance b) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
    for (Node n : a.thesig.nodes) {
        Set<Pair<Object, Object>> set = new HashSet<>();
        for (Pair<Object, Object> p : a.data.get(n.string)) {
            if (b.data.get(n.string).contains(p)) {
                set.add(p);
            }
        }
        data.put(n.string, set);
    }
    for (Edge n : a.thesig.edges) {
        Set<Pair<Object, Object>> set = new HashSet<>();
        for (Pair<Object, Object> p : a.data.get(n.name)) {
            if (b.data.get(n.name).contains(p)) {
                set.add(p);
            }
        }
        data.put(n.name, set);
    }
    return new Instance(a.thesig, data);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 37 with Node

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

the class PSMAnd 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 old = H2.first;
        Instance prp = new Instance(sig, PSMGen.gather(prop, sig, state));
        Instance prd = new Instance(sig, PSMGen.gather(prod, sig, state));
        Transform fst = new Transform(prd, prp, PSMGen.gather(prod + "_fst", sig, state));
        Transform snd = new Transform(prd, prp, PSMGen.gather(prod + "_snd", 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 idp : prd.getNode(c)) {
                Object id0 = lookup(fst.data.get(c.string), idp);
                Object id1 = lookup(snd.data.get(c.string), idp);
                Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> idl = I1.get(c).get(id0);
                Instance A = H2.second.get(c).first.get(idl.first);
                Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> idr = I1.get(c).get(id1);
                Instance B = H2.second.get(c).first.get(idr.first);
                if (!idl.second.equals(idr.second)) {
                    throw new RuntimeException("bad");
                }
                Instance nA;
                switch(kind) {
                    case "and":
                        nA = isect(A, B);
                        break;
                    case "or":
                        nA = union(A, B);
                        break;
                    case "implies":
                        nA = implies(sig0, H1, Hc, A, B);
                        break;
                    default:
                        throw new RuntimeException();
                }
                Object notId = H2.second.get(c).second.get(nA);
                Object x = I2.get(c).get(new Pair<>(notId, idl.second));
                data0.add(new Pair<>(idp, x));
            }
            data.add(new Pair<>(c.string, data0));
        }
        Transform ret = new Transform(prd, 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 38 with Node

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

the class PSMAnd method implies.

private Instance implies(Signature sig0, Pair<Map<Node, Triple<Instance, Map<Object, Path>, Map<Path, Object>>>, Map<Edge, Transform>> H1, Triple<Instance, Map<Object, Path>, Map<Path, Object>> Hc, Instance A, Instance B) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> notA_data = new HashMap<>();
    for (Node d : sig.nodes) {
        Set<Pair<Object, Object>> dd = new HashSet<>();
        xxx: for (Object f : Hc.first.getNode(d)) {
            Path ff = Hc.second.get(f);
            for (Node d0 : sig.nodes) {
                for (Arr<Node, Path> g : sig.toCategory2().first.hom(d, d0)) {
                    Arr<Node, Path> fg = sig.toCategory2().first.compose(sig.toCategory2().second.of(ff), g);
                    Object xxx = H1.first.get(d0).third.get(fg.arr);
                    if (xxx == null) {
                        throw new RuntimeException();
                    }
                    if (!A.getNode(d0).contains(xxx) || B.getNode(d0).contains(xxx)) {
                    } else {
                        continue xxx;
                    }
                }
            }
            dd.add(new Pair<>(f, f));
        }
        notA_data.put(d.string, dd);
    }
    for (Edge h : sig.edges) {
        Set<Pair<Object, Object>> dd = new HashSet<>();
        for (Object f : notA_data.get(h.source.string)) {
            Path ff = Hc.second.get(f);
            Arr<Node, Path> fg = sig.toCategory2().first.compose(sig.toCategory2().second.of(ff), sig.toCategory2().second.of(new Path(sig, h)));
            Object xxx = Hc.third.get(fg.arr);
            dd.add(new Pair<>(f, xxx));
        }
        notA_data.put(h.name, dd);
    }
    Instance notA = new Instance(sig0, notA_data);
    return notA;
}
Also used : Path(catdata.fql.decl.Path) 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) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 39 with Node

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

the class PSMBool 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);
        Instance unitI = new Instance(sig, PSMGen.gather(unit, sig, state));
        Instance propI = new Instance(sig, PSMGen.gather(prop, sig, state));
        Map<Node, Map<Object, Object>> subst_inv = new HashMap<>();
        for (Node n : sig.nodes) {
            Map<Object, Object> m = new HashMap<>();
            Set<Map<Object, Object>> g = state.get(unit + "_" + n + "_subst_inv");
            for (Map<Object, Object> j : g) {
                m.put(j.get("c0"), j.get("c1"));
            }
            subst_inv.put(n, m);
        }
        List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
        for (Node n : sig.nodes) {
            List<Pair<Object, Object>> set = new LinkedList<>();
            for (Pair<Object, Object> k : unitI.data.get(n.string)) {
                Object k0 = subst_inv.get(n).get(k.first);
                if (k0 == null) {
                    throw new RuntimeException();
                }
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> v = m1.get(n).get(k0);
                Instance tofind = bool ? interp.prop1.get(prop).first.get(n).first : new Instance(sig0);
                Object found = interp.prop2.get(prop).second.get(n).second.get(tofind);
                Object r = interp.prop4.get(prop).get(n).get(new Pair<>(found, v));
                set.add(new Pair<>(k.first, r));
            }
            data.add(new Pair<>(n.string, set));
        }
        Transform ret = new Transform(unitI, propI, data);
        PSMGen.shred(pre, ret, state);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : Path(catdata.fql.decl.Path) Instance(catdata.fql.decl.Instance) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) 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 40 with Node

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

the class PSMChi method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        Instance I = new Instance(sig, PSMGen.gather(a, sig, state));
        Instance Jfull = new Instance(fullSig, PSMGen.gather(b, fullSig, state));
        Instance J = new Instance(sig, PSMGen.gather(b, sig, state));
        Instance Pfull = new Instance(fullSig, PSMGen.gather(prop, fullSig, state));
        Instance P = interp.prop2.get(prop).first;
        Transform t = new Transform(I, J, PSMGen.gather(f, sig, state));
        List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
        for (Node c : sig.nodes) {
            List<Pair<Object, Object>> l = new LinkedList<>();
            Instance Hc = interp.prop1.get(prop).first.get(c).first;
            for (Pair<Object, Object> x : J.data.get(c.string)) {
                List<Pair<String, List<Pair<Object, Object>>>> z = new LinkedList<>();
                for (Node d : sig.nodes) {
                    List<Pair<Object, Object>> y = new LinkedList<>();
                    for (Pair<Object, Object> ff : Hc.data.get(d.string)) {
                        // c->d
                        Path f = interp.prop1.get(prop).first.get(c).second.get(ff.first);
                        Object xd = lookup(J.evaluate(f), x.first);
                        y.add(new Pair<>(ff.first, xd));
                    }
                    z.add(new Pair<>(d.string, y));
                }
                Transform xx = new Transform(Hc, J, z);
                Map<String, Set<Pair<Object, Object>>> q = new HashMap<>();
                for (Node d : sig.nodes) {
                    Set<Pair<Object, Object>> g = new HashSet<>();
                    for (Pair<Object, Object> y : Hc.data.get(d.string)) {
                        if (proj2(t.data.get(d.string)).contains(lookup(xx.data.get(d.string), y.first))) {
                            g.add(y);
                        }
                    }
                    q.put(d.string, g);
                }
                for (Edge e : sig.edges) {
                    Set<Pair<Object, Object>> set = new HashSet<>();
                    for (Pair<Object, Object> j : Hc.data.get(e.name)) {
                        if (proj1(q.get(e.source.string)).contains(j.first) && proj2(q.get(e.target.string)).contains(j.second)) {
                            set.add(j);
                        }
                    }
                    q.put(e.name, set);
                }
                // also do edges
                Instance pb = new Instance(sig, q);
                Object fnl = interp.prop2.get(prop).second.get(c).second.get(pb);
                l.add(new Pair<>(x.first, fnl));
            }
            data.add(new Pair<>(c.string, l));
        }
        Transform ret = new Transform(J, P, data);
        List<Pair<String, List<Pair<Object, Object>>>> dataFull = new LinkedList<>();
        for (Node n : sig.nodes) {
            List<Pair<Object, Object>> set = new LinkedList<>();
            for (Pair<Object, Object> k : ret.data.get(n.string)) {
                Object lhs = k.second;
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> rhs = Jfull.flag(n, k.first);
                Object xxx = interp.prop4.get(prop).get(n).get(new Pair<>(lhs, rhs));
                set.add(new Pair<>(k.first, xxx));
            }
            dataFull.add(new Pair<>(n.string, set));
        }
        Transform ret0 = new Transform(Jfull, Pfull, dataFull);
        PSMGen.shred(pre, ret0, state);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getLocalizedMessage());
    }
}
Also used : Path(catdata.fql.decl.Path) Set(java.util.Set) HashSet(java.util.HashSet) Instance(catdata.fql.decl.Instance) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) FQLException(catdata.fql.FQLException) Transform(catdata.fql.decl.Transform) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Aggregations

Node (catdata.fql.decl.Node)51 Pair (catdata.Pair)38 HashMap (java.util.HashMap)36 Edge (catdata.fql.decl.Edge)33 LinkedList (java.util.LinkedList)26 LinkedHashMap (java.util.LinkedHashMap)25 Instance (catdata.fql.decl.Instance)22 Path (catdata.fql.decl.Path)21 Map (java.util.Map)21 FQLException (catdata.fql.FQLException)20 Attribute (catdata.fql.decl.Attribute)19 HashSet (java.util.HashSet)19 Arr (catdata.fql.cat.Arr)14 Signature (catdata.fql.decl.Signature)13 Set (java.util.Set)13 Transform (catdata.fql.decl.Transform)11 List (java.util.List)10 Triple (catdata.Triple)5 Fn (catdata.fql.Fn)4 FinCat (catdata.fql.cat.FinCat)3