Search in sources :

Example 11 with Arr

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

the class PSMGen method deltaX.

private static List<PSM> deltaX(String pre, Map<Triple<Node, Node, Arr<Node, Path>>, String> ob, Map<Pair<Arr<Node, Path>, Arr<Node, Path>>, String> ar, FinFunctor<Triple<Node, Node, Arr<Node, Path>>, Pair<Arr<Node, Path>, Arr<Node, Path>>, Node, Path> projB) {
    Map<String, String> twocol_attrs = new HashMap<>();
    twocol_attrs.put("c0", PSM.VARCHAR());
    twocol_attrs.put("c1", PSM.VARCHAR());
    List<PSM> ret = new LinkedList<>();
    for (Entry<Triple<Node, Node, Arr<Node, Path>>, Node> p : projB.objMapping.entrySet()) {
        ob.put(p.getKey(), pre + "_" + p.getKey().second.string);
    }
    for (Entry<Arr<Triple<Node, Node, Arr<Node, Path>>, Pair<Arr<Node, Path>, Arr<Node, Path>>>, Arr<Node, Path>> p : projB.arrowMapping.entrySet()) {
        Path x = p.getKey().arr.second.arr;
        ret.add(new CreateTable("temp" + tempTables, twocol_attrs, false));
        ret.add(new InsertSQL("temp" + tempTables, compose(pre, x), "c0", "c1"));
        ar.put(p.getKey().arr, "temp" + tempTables++);
    }
    return ret;
}
Also used : Path(catdata.fql.decl.Path) Arr(catdata.fql.cat.Arr) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(catdata.fql.decl.Node) LinkedList(java.util.LinkedList) Triple(catdata.Triple)

Example 12 with Arr

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

the class PSMNot method calcSub.

private Instance calcSub(Signature sig0, Triple<Instance, Map<Object, Path>, Map<Path, Object>> Hc, Instance A) 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);
            // boolean b = true;
            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 = Hc.third.get(fg.arr);
                    if (xxx == null) {
                        throw new RuntimeException();
                    }
                    if (A.getNode(d0).contains(xxx)) {
                        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 (Pair<Object, Object> oo : notA_data.get(h.source.string)) {
            Object f = oo.first;
            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 13 with Arr

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

Example 14 with Arr

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

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

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