Search in sources :

Example 1 with Transform

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

the class PSMIso method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    // throw new RuntimeException("Iso finder is not working right now");
    try {
        Instance li = new Instance(sig, PSMGen.gather(l, sig, state));
        Instance ri = new Instance(sig, PSMGen.gather(r, sig, state));
        Pair<Transform, Transform> k = Inst.iso(li, ri);
        if (k == null) {
            throw new RuntimeException("Cannot find iso between " + l + " and " + r);
        }
        if (lToR) {
            PSMGen.shred(pre, k.first, state);
        } else {
            PSMGen.shred(pre, k.second, state);
        }
    } catch (FQLException fe) {
        fe.printStackTrace();
        throw new RuntimeException(fe.getMessage());
    }
}
Also used : FQLException(catdata.fql.FQLException) Instance(catdata.fql.decl.Instance) Transform(catdata.fql.decl.Transform)

Example 2 with Transform

use of catdata.fql.decl.Transform 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 Transform

use of catdata.fql.decl.Transform 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 Transform

use of catdata.fql.decl.Transform 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 5 with Transform

use of catdata.fql.decl.Transform 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)

Aggregations

Transform (catdata.fql.decl.Transform)13 Pair (catdata.Pair)12 FQLException (catdata.fql.FQLException)12 Instance (catdata.fql.decl.Instance)12 Node (catdata.fql.decl.Node)11 LinkedList (java.util.LinkedList)10 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)9 Map (java.util.Map)8 Arr (catdata.fql.cat.Arr)6 Attribute (catdata.fql.decl.Attribute)6 Signature (catdata.fql.decl.Signature)6 Path (catdata.fql.decl.Path)5 Edge (catdata.fql.decl.Edge)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Set (java.util.Set)3 Triple (catdata.Triple)2 IntRef (catdata.IntRef)1 Quad (catdata.Quad)1