Search in sources :

Example 16 with Edge

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

Example 17 with Edge

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

the class LeftKanSigma method deAttr.

private static void deAttr(Signature source) {
    for (Attribute<Node> a : source.attrs) {
        Node dst = new Node(a.name);
        source.nodes.add(dst);
        source.edges.add(new Edge(a.name + "_edge", a.source, dst));
    }
    source.attrs.clear();
// source.doColors();
}
Also used : Node(catdata.fql.decl.Node) Edge(catdata.fql.decl.Edge)

Example 18 with Edge

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

the class Inst method stuff.

// base^exp
public static FinCat<Mapping, Map<Node, Path>> stuff(Signature base, Signature exp) throws FQLException {
    Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> xxx = base.toCategory2();
    FinCat<Node, Path> base0 = xxx.first;
    Pair<FinCat<Node, Path>, Fn<Path, Arr<Node, Path>>> yyy = exp.toCategory2();
    FinCat<Node, Path> exp0 = yyy.first;
    List<LinkedHashMap<Node, Node>> nms = homomorphs(exp.nodes, base.nodes);
    List<Mapping> mappings = new LinkedList<>();
    for (LinkedHashMap<Node, Node> nm : nms) {
        LinkedHashMap<Attribute<Node>, List<Attribute<Node>>> ams = new LinkedHashMap<>();
        for (Attribute<Node> a : exp.attrs) {
            ams.put(a, base.attrsFor(nm.get(a.source)));
        }
        LinkedHashMap<Edge, List<Path>> ems = new LinkedHashMap<>();
        for (Edge e : exp.edges) {
            Set<Arr<Node, Path>> s = base0.hom(nm.get(e.source), nm.get(e.target));
            List<Path> p = new LinkedList<>();
            for (Arr<Node, Path> sx : s) {
                p.add(sx.arr);
            }
            ems.put(e, p);
        }
        List<LinkedHashMap<Attribute<Node>, Attribute<Node>>> ams0 = homomorphs(ams);
        List<LinkedHashMap<Edge, Path>> ems0 = homomorphs(ems);
        for (LinkedHashMap<Attribute<Node>, Attribute<Node>> am : ams0) {
            for (LinkedHashMap<Edge, Path> em : ems0) {
                try {
                    Mapping m = new Mapping(true, exp, base, nm, em, am);
                    mappings.add(m);
                } catch (Exception e) {
                }
            }
        }
    }
    List<Arr<Mapping, Map<Node, Path>>> arrows = new LinkedList<>();
    for (Mapping s : mappings) {
        for (Mapping t : mappings) {
            Map<Node, List<Path>> map = new HashMap<>();
            for (Node n : exp.nodes) {
                List<Path> p = new LinkedList<>();
                for (Arr<Node, Path> k : base0.hom(s.nm.get(n), t.nm.get(n))) {
                    p.add(k.arr);
                }
                map.put(n, p);
            }
            List<LinkedHashMap<Node, Path>> map0 = homomorphs(map);
            outer: for (Map<Node, Path> k : map0) {
                for (Node x : k.keySet()) {
                    for (Node y : k.keySet()) {
                        for (Arr<Node, Path> f : exp0.hom(x, y)) {
                            Path lhs = Path.append(base, k.get(x), t.appy(base, f.arr));
                            Path rhs = Path.append(base, s.appy(base, f.arr), k.get(y));
                            if (!xxx.second.of(lhs).equals(xxx.second.of(rhs))) {
                                continue outer;
                            }
                        }
                    }
                }
                arrows.add(new Arr<>(k, s, t));
            }
        }
    }
    Map<Mapping, Arr<Mapping, Map<Node, Path>>> identities = new HashMap<>();
    for (Mapping m : mappings) {
        Map<Node, Path> map = new HashMap<>();
        for (Node n : m.source.nodes) {
            map.put(n, new Path(m.target, m.nm.get(n)));
        }
        Arr<Mapping, Map<Node, Path>> uuu = new Arr<>(map, m, m);
        identities.put(m, new Arr<>(map, m, m));
        if (!arrows.contains(uuu)) {
            arrows.add(uuu);
        }
    }
    Map<Pair<Arr<Mapping, Map<Node, Path>>, Arr<Mapping, Map<Node, Path>>>, Arr<Mapping, Map<Node, Path>>> composition = new HashMap<>();
    for (Arr<Mapping, Map<Node, Path>> a1 : arrows) {
        for (Arr<Mapping, Map<Node, Path>> a2 : arrows) {
            if (!a1.dst.equals(a2.src)) {
                continue;
            }
            Map<Node, Path> m = new HashMap<>();
            for (Node n : exp.nodes) {
                m.put(n, xxx.second.of(Path.append(base, a1.arr.get(n), a2.arr.get(n))).arr);
            }
            composition.put(new Pair<>(a1, a2), new Arr<>(m, a1.src, a2.dst));
        }
    }
    return new FinCat<>(mappings, arrows, composition, identities);
}
Also used : Attribute(catdata.fql.decl.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(catdata.fql.decl.Node) Mapping(catdata.fql.decl.Mapping) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) LinkedList(java.util.LinkedList) Pair(catdata.Pair) Path(catdata.fql.decl.Path) Fn(catdata.fql.Fn) LinkedList(java.util.LinkedList) FQLException(catdata.fql.FQLException) Edge(catdata.fql.decl.Edge) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 19 with Edge

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

the class Chase method sigma.

public static Instance sigma(Mapping m, Instance i) throws FQLException {
    Triple<Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>> kkk = m.toEDs();
    Signature cd = kkk.second.first;
    Map<String, Set<Pair<Object, Object>>> I = new HashMap<>();
    for (Node n : cd.nodes) {
        I.put(n.string, new HashSet<>());
    }
    for (Edge n : cd.edges) {
        I.put(n.name, new HashSet<>());
    }
    for (Attribute<Node> n : cd.attrs) {
        I.put(n.name, new HashSet<>());
    }
    for (String k : i.data.keySet()) {
        I.put("src_" + k, i.data.get(k));
    }
    List<EmbeddedDependency> eds0 = Signature.toED("", kkk.second);
    Pair<List<Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>>>, List<Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>>>> zzz = split(eds0);
    Set<String> keys = new HashSet<>();
    for (Node n : m.target.nodes) {
        keys.add("dst_" + n.string);
    }
    for (Edge n : m.target.edges) {
        keys.add("dst_" + n.name);
    }
    for (Attribute<Node> n : m.target.attrs) {
        keys.add("dst_" + n.name);
    }
    Map<String, Set<Pair<Object, Object>>> res = chase(keys, zzz, I, KIND.PARALLEL);
    Map<String, Set<Pair<Object, Object>>> res0 = new HashMap<>();
    for (Node n : m.target.nodes) {
        res0.put(n.string, res.get("dst_" + n.string));
    }
    for (Edge n : m.target.edges) {
        res0.put(n.name, res.get("dst_" + n.name));
    }
    for (Attribute<Node> n : m.target.attrs) {
        res0.put(n.name, res.get("dst_" + n.name));
    }
    Instance ret = new Instance(m.target, res0);
    return ret;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Attribute(catdata.fql.decl.Attribute) HashMap(java.util.HashMap) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Signature(catdata.fql.decl.Signature) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Edge(catdata.fql.decl.Edge) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 20 with Edge

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

the class Chase method delta.

public static Instance delta(Mapping m, Instance i) throws FQLException {
    Triple<Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>> kkk = m.toEDs();
    Signature cd = m.toEDs().first.first;
    Map<String, Set<Pair<Object, Object>>> I = new HashMap<>();
    for (Node n : cd.nodes) {
        I.put(n.string, new HashSet<>());
    }
    for (Edge n : cd.edges) {
        I.put(n.name, new HashSet<>());
    }
    for (Attribute<Node> n : cd.attrs) {
        I.put(n.name, new HashSet<>());
    }
    for (String k : i.data.keySet()) {
        I.put("dst_" + k, i.data.get(k));
    }
    List<EmbeddedDependency> eds0 = Signature.toED("", kkk.first);
    Pair<List<Triple<List<String>, List<Triple<String, String, String>>, List<Triple<String, String, String>>>>, List<Triple<List<String>, List<Triple<String, String, String>>, List<Pair<String, String>>>>> zzz = split(eds0);
    Set<String> keys = new HashSet<>();
    for (Node n : m.target.nodes) {
        keys.add("src_" + n.string);
    }
    for (Edge n : m.target.edges) {
        keys.add("src_" + n.name);
    }
    for (Attribute<Node> n : m.target.attrs) {
        keys.add("src_" + n.name);
    }
    // changed
    Map<String, Set<Pair<Object, Object>>> res = chase(keys, zzz, I, KIND.HYBRID);
    Map<String, Set<Pair<Object, Object>>> res0 = new HashMap<>();
    for (Node n : m.source.nodes) {
        res0.put(n.string, res.get("src_" + n.string));
    }
    for (Edge n : m.source.edges) {
        res0.put(n.name, res.get("src_" + n.name));
    }
    for (Attribute<Node> n : m.source.attrs) {
        res0.put(n.name, res.get("src_" + n.name));
    }
    Instance ret = new Instance(m.source, res0);
    return ret;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Attribute(catdata.fql.decl.Attribute) HashMap(java.util.HashMap) Instance(catdata.fql.decl.Instance) Node(catdata.fql.decl.Node) Signature(catdata.fql.decl.Signature) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Edge(catdata.fql.decl.Edge) EmbeddedDependency(catdata.fql.sql.EmbeddedDependency) Pair(catdata.Pair) HashSet(java.util.HashSet)

Aggregations

Edge (catdata.fql.decl.Edge)37 Node (catdata.fql.decl.Node)33 HashMap (java.util.HashMap)27 Pair (catdata.Pair)25 HashSet (java.util.HashSet)19 LinkedList (java.util.LinkedList)19 LinkedHashMap (java.util.LinkedHashMap)17 Instance (catdata.fql.decl.Instance)15 Set (java.util.Set)13 Map (java.util.Map)12 FQLException (catdata.fql.FQLException)11 Path (catdata.fql.decl.Path)11 Attribute (catdata.fql.decl.Attribute)10 Signature (catdata.fql.decl.Signature)9 List (java.util.List)7 Arr (catdata.fql.cat.Arr)6 Fn (catdata.fql.Fn)4 Transform (catdata.fql.decl.Transform)4 Triple (catdata.Triple)3 FinCat (catdata.fql.cat.FinCat)3