Search in sources :

Example 1 with IntRef

use of catdata.IntRef 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)

Example 2 with IntRef

use of catdata.IntRef in project fql by CategoricalData.

the class Signature method omega.

public Pair<Pair<Map<Node, Triple<Instance, Map<Object, Path>, Map<Path, Object>>>, Map<Edge, Transform>>, Pair<Instance, Map<Node, Pair<Map<Object, Instance>, Map<Instance, Object>>>>> omega(IntRef ref) throws FQLException {
    IntRef ix = new IntRef(0);
    Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
    Map<Node, Pair<Map<Object, Instance>, Map<Instance, Object>>> m = new HashMap<>();
    Pair<Map<Node, Triple<Instance, Map<Object, Path>, Map<Path, Object>>>, Map<Edge, Transform>> rx = repX(ix);
    for (Node n : nodes) {
        Set<Pair<Object, Object>> set = new HashSet<>();
        Map<Object, Instance> m1 = new HashMap<>();
        Map<Instance, Object> m2 = new HashMap<>();
        Triple<Instance, Map<Object, Path>, Map<Path, Object>> t = rx.first.get(n);
        List<Instance> l = t.first.subInstances();
        for (Instance i : l) {
            Object id = Integer.toString(++ref.i);
            set.add(new Pair<>(id, id));
            m1.put(id, i);
            m2.put(i, id);
        }
        data.put(n.string, set);
        m.put(n, new Pair<>(m1, m2));
    }
    for (Edge e : edges) {
        Set<Pair<Object, Object>> set = new HashSet<>();
        for (Pair<Object, Object> j : data.get(e.source.string)) {
            Instance u = m.get(e.source).first.get(j.first);
            Instance v = rx.second.get(e).preimage(u);
            Object o = m.get(e.target).second.get(v);
            set.add(new Pair<>(j.first, o));
        }
        data.put(e.name, set);
    }
    Instance omega = new Instance(this, data);
    return new Pair<>(rx, new Pair<>(omega, m));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IntRef(catdata.IntRef) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 3 with IntRef

use of catdata.IntRef in project fql by CategoricalData.

the class PropPSM method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        IntRef ref = new IntRef(interp.guid);
        Signature sigX = new Signature(sig.nodes, sig.edges, new LinkedList<>(), sig.eqs);
        Map<Node, List<Pair<Arr<Node, Path>, Attribute<Node>>>> obs = sig.obs();
        Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> ooo = sig.toCategory2();
        Fn<Path, Arr<Node, Path>> fn = ooo.second;
        Pair<Pair<Map<Node, Triple<Instance, Map<Object, Path>, Map<Path, Object>>>, Map<Edge, Transform>>, Pair<Instance, Map<Node, Pair<Map<Object, Instance>, Map<Instance, Object>>>>> xxx = sigX.omega(ref);
        interp.prop1.put(pre, xxx.first);
        interp.prop2.put(pre, xxx.second);
        Instance old = xxx.second.first;
        Map<Node, List<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> m = sig.obsbar();
        Map<String, Set<Pair<Object, Object>>> data = new HashMap<>();
        Map<Node, Map<Object, Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>>> m1 = new HashMap<>();
        Map<Node, Map<Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Object>> m2 = new HashMap<>();
        for (Node n : sig.nodes) {
            Map<Object, Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>> map1 = new HashMap<>();
            Map<Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>>, Object> map2 = new HashMap<>();
            Set<Pair<Object, Object>> set = new HashSet<>();
            m1.put(n, map1);
            m2.put(n, map2);
            for (Pair<Object, Object> i1 : old.data.get(n.string)) {
                for (LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> i2 : m.get(n)) {
                    Object o = Integer.toString(++ref.i);
                    map1.put(o, new Pair<>(i1.first, i2));
                    map2.put(new Pair<>(i1.first, i2), o);
                    set.add(new Pair<>(o, o));
                }
            }
            data.put(n.string, set);
        }
        for (Attribute<Node> a : sig.attrs) {
            Set<Pair<Object, Object>> set = new HashSet<>();
            for (Pair<Object, Object> k : data.get(a.source.string)) {
                Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> kk = m1.get(a.source).get(k.first);
                // Object old_id = kk.first;
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = kk.second;
                set.add(new Pair<>(k.first, new_id.get(new Pair<>(new Arr<>(new Path(sig, a.source), a.source, a.source), a))));
            }
            data.put(a.name, set);
        }
        for (Edge a : sig.edges) {
            Set<Pair<Object, Object>> set = new HashSet<>();
            for (Pair<Object, Object> k : data.get(a.source.string)) {
                Pair<Object, LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>> kk = m1.get(a.source).get(k.first);
                Object old_id = kk.first;
                Object old_id0 = lookup(old.data.get(a.name), old_id);
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id = kk.second;
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> new_id0 = truncate2(sig, new_id, fn.of(new Path(sig, a)), obs.get(a.target));
                Object o = m2.get(a.target).get(new Pair<>(old_id0, new_id0));
                set.add(new Pair<>(k.first, o));
            }
            data.put(a.name, set);
        }
        interp.prop3.put(pre, m1);
        interp.prop4.put(pre, m2);
        Instance ne = new Instance(sig, data);
        PSMGen.shred(pre, ne, state);
        interp.guid = ref.i;
    } 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) Attribute(catdata.fql.decl.Attribute) Instance(catdata.fql.decl.Instance) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FinCat(catdata.fql.cat.FinCat) Node(catdata.fql.decl.Node) LinkedHashMap(java.util.LinkedHashMap) IntRef(catdata.IntRef) FQLException(catdata.fql.FQLException) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) HashSet(java.util.HashSet) Path(catdata.fql.decl.Path) Fn(catdata.fql.Fn) Triple(catdata.Triple) Signature(catdata.fql.decl.Signature) Transform(catdata.fql.decl.Transform) Edge(catdata.fql.decl.Edge) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

IntRef (catdata.IntRef)3 Pair (catdata.Pair)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 FQLException (catdata.fql.FQLException)2 Arr (catdata.fql.cat.Arr)2 Attribute (catdata.fql.decl.Attribute)2 Instance (catdata.fql.decl.Instance)2 Node (catdata.fql.decl.Node)2 Path (catdata.fql.decl.Path)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Triple (catdata.Triple)1 Fn (catdata.fql.Fn)1 FinCat (catdata.fql.cat.FinCat)1 Edge (catdata.fql.decl.Edge)1 Signature (catdata.fql.decl.Signature)1 Transform (catdata.fql.decl.Transform)1 LinkedList (java.util.LinkedList)1