Search in sources :

Example 6 with Instance

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

the class PSMAnd method union.

private static Instance union(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<>();
        set.addAll(a.data.get(n.string));
        set.addAll(b.data.get(n.string));
        data.put(n.string, set);
    }
    for (Edge n : a.thesig.edges) {
        Set<Pair<Object, Object>> set = new HashSet<>();
        set.addAll(a.data.get(n.name));
        set.addAll(b.data.get(n.name));
        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 7 with Instance

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

the class PSMEval method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    try {
        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>>> xxx = interp.exps2.get(AB);
        Instance Jw = xxx.first;
        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 = xxx.second;
        Map<Node, Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>>> map2 = xxx.third;
        FinCat<Node, Path> cat = Jw.thesig.toCategory2().first;
        Instance abb = new Instance(sig, PSMGen.gather(ABB, sig, state));
        // Instance ab = new Instance(sig, PSMGen.gather(AB, sig, state));
        // //already have in interp
        Instance a = new Instance(sig, PSMGen.gather(A, sig, state));
        Instance b = new Instance(sig, PSMGen.gather(B, sig, state));
        Transform fst = new Transform(abb, Jw, PSMGen.gather(ABB + "_fst", sig, state));
        Transform snd = new Transform(abb, b, PSMGen.gather(ABB + "_snd", sig, state));
        List<Pair<String, List<Pair<Object, Object>>>> data = new LinkedList<>();
        for (Node n : sig.nodes) {
            List<Pair<Object, Object>> d = new LinkedList<>();
            Map<Object, Pair<LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object>, Transform>> m2 = map2.get(n);
            for (Pair<Object, Object> id : abb.data.get(n.string)) {
                Object id_ab = lookup(fst.data.get(n.string), id.first);
                Object x = lookup(snd.data.get(n.string), id.first);
                Transform t = m2.get(id_ab).second;
                LinkedHashMap<Pair<Arr<Node, Path>, Attribute<Node>>, Object> w = m2.get(id_ab).first;
                Triple<Instance, Map<Node, Map<Object, Pair<Arr<Node, Path>, Object>>>, Map<Node, Map<Pair<Arr<Node, Path>, Object>, Object>>> m = map.get(new Pair<>(n, w));
                Object y = m.third.get(n).get(new Pair<>(cat.id(n), x));
                Object f = lookup(t.data.get(n.string), y);
                d.add(new Pair<>(id.first, f));
            }
            data.add(new Pair<>(n.string, d));
        }
        Transform curry = new Transform(abb, a, data);
        PSMGen.shred(pre, curry, 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) LinkedHashMap(java.util.LinkedHashMap) FQLException(catdata.fql.FQLException) Pair(catdata.Pair) Path(catdata.fql.decl.Path) LinkedList(java.util.LinkedList) Triple(catdata.Triple) Transform(catdata.fql.decl.Transform) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 8 with Instance

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

the class TransChecker method visit.

@SuppressWarnings("unused")
@Override
public Pair<String, String> visit(FQLProgram env, Const e) {
    InstExp src = env.insts.get(e.src);
    if (src == null) {
        throw new RuntimeException("Missing instance " + e.src);
    }
    InstExp dst = env.insts.get(e.dst);
    if (dst == null) {
        throw new RuntimeException("Missing instance " + e.src);
    }
    if (!(src instanceof InstExp.Const)) {
        throw new RuntimeException(e.src + " is not a constant.");
    }
    if (!(dst instanceof InstExp.Const)) {
        throw new RuntimeException(e.dst + " is not a constant.");
    }
    InstExp.Const src0 = (InstExp.Const) src;
    InstExp.Const dst0 = (InstExp.Const) dst;
    SigExp srct = src0.type(env);
    SigExp dstt = dst0.type(env);
    if (!srct.equals(dstt)) {
        throw new RuntimeException("Instances not of same type on " + e + " are " + srct + " and " + dstt);
    }
    Signature sig = srct.toSig(env);
    List<Pair<String, List<Pair<Object, Object>>>> bbb = e.objs;
    try {
        new Transform(new Instance(sig, src0.data), new Instance(sig, dst0.data), bbb);
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getLocalizedMessage());
    }
    return new Pair<>(e.src, e.dst);
}
Also used : InstExp(catdata.fql.decl.InstExp) FQLException(catdata.fql.FQLException) SigExp(catdata.fql.decl.SigExp) Instance(catdata.fql.decl.Instance) Const(catdata.fql.decl.TransExp.Const) Signature(catdata.fql.decl.Signature) Transform(catdata.fql.decl.Transform) Pair(catdata.Pair)

Example 9 with Instance

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

the class LeftKanSigma method reAttr.

private static Instance reAttr(Map<Node, Map<Object, Integer>> D, Signature thesig, Instance i, Map<Attribute<Node>, Map<Object, Object>> map0) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> d = new HashMap<>();
    for (Node k : i.thesig.nodes) {
        d.put(k.string, i.data.get(k.string));
    }
    for (Edge k : thesig.edges) {
        d.put(k.name, i.data.get(k.name));
    }
    Map<Object, Object> map = new HashMap<>();
    for (Attribute<Node> k : map0.keySet()) {
        Map<Object, Object> v = map0.get(k);
        for (Object k0 : v.keySet()) {
            Object v0 = v.get(k0);
            if (map.containsKey(k0)) {
                throw new RuntimeException();
            }
            map.put(k0, v0);
        }
    }
    for (Attribute<Node> k : thesig.attrs) {
        Set<Pair<Object, Object>> t = new HashSet<>();
        for (Pair<Object, Object> v : i.data.get(k.name + "_edge")) {
            Object v1 = getFrom(k, D, map, /* ().get(k) */
            v.second.toString());
            t.add(new Pair<>(v.first, v1));
        }
        d.put(k.name, t);
    }
    return new Instance(thesig, d);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 10 with Instance

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

the class LeftKanSigma method deAttr.

private static Pair<Instance, Map<Attribute<Node>, Map<Object, Object>>> deAttr(PSMInterp inter, Instance i, Signature sig) throws FQLException {
    Map<String, Set<Pair<Object, Object>>> d = new HashMap<>();
    Map<Attribute<Node>, Map<Object, Object>> ret = new HashMap<>();
    for (Node k : i.thesig.nodes) {
        d.put(k.string, i.data.get(k.string));
    }
    for (Edge k : i.thesig.edges) {
        d.put(k.name, i.data.get(k.name));
    }
    for (Attribute<Node> k : i.thesig.attrs) {
        Map<Object, Object> ret0 = new HashMap<>();
        Set<Pair<Object, Object>> tn = new HashSet<>();
        Set<Pair<Object, Object>> te = new HashSet<>();
        for (Pair<Object, Object> v : i.data.get(k.name)) {
            Object x = revLookup(ret0, v.second);
            if (x == null) {
                x = ++inter.guid;
                ret0.put(x.toString(), v.second);
            }
            tn.add(new Pair<>(x.toString(), x.toString()));
            te.add(new Pair<>(v.first, x.toString()));
        }
        ret.put(k, ret0);
        d.put(k.name, tn);
        d.put(k.name + "_edge", te);
    }
    return new Pair<>(new Instance(sig, d), ret);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Attribute(catdata.fql.decl.Attribute) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) HashMap(java.util.HashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Aggregations

Instance (catdata.fql.decl.Instance)25 Pair (catdata.Pair)23 Node (catdata.fql.decl.Node)22 HashMap (java.util.HashMap)19 Edge (catdata.fql.decl.Edge)15 FQLException (catdata.fql.FQLException)14 HashSet (java.util.HashSet)14 LinkedHashMap (java.util.LinkedHashMap)13 Set (java.util.Set)13 Transform (catdata.fql.decl.Transform)12 Map (java.util.Map)12 Attribute (catdata.fql.decl.Attribute)11 LinkedList (java.util.LinkedList)11 Signature (catdata.fql.decl.Signature)10 Arr (catdata.fql.cat.Arr)9 Path (catdata.fql.decl.Path)8 List (java.util.List)4 IntRef (catdata.IntRef)2 Triple (catdata.Triple)2 Mapping (catdata.fql.decl.Mapping)2