Search in sources :

Example 11 with Attribute

use of catdata.fql.decl.Attribute 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 12 with Attribute

use of catdata.fql.decl.Attribute 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 13 with Attribute

use of catdata.fql.decl.Attribute 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 14 with Attribute

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

Example 15 with Attribute

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

the class CategoryOfElements method build.

private static Pair<Graph<Pair<Node, Object>, Pair<Path, Integer>>, HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>>> build(Instance i) throws FQLException {
    FinCat<Node, Path> c = i.thesig.toCategory2().first;
    HashMap<Pair<Node, Object>, Map<Attribute<Node>, Object>> map = new HashMap<>();
    Graph<Pair<Node, Object>, Pair<Path, Integer>> g2 = new DirectedSparseMultigraph<>();
    for (Node n : c.objects) {
        for (Pair<Object, Object> o : i.data.get(n.string)) {
            Pair<Node, Object> xx = new Pair<>(n, o.first);
            g2.addVertex(xx);
            List<Attribute<Node>> attrs = i.thesig.attrsFor(n);
            Map<Attribute<Node>, Object> m = new HashMap<>();
            for (Attribute<Node> attr : attrs) {
                Object a = lookup(i.data.get(attr.name), o.first);
                m.put(attr, a);
            }
            map.put(xx, m);
        }
    }
    int j = 0;
    for (Pair<Node, Object> x : g2.getVertices()) {
        for (Pair<Node, Object> y : g2.getVertices()) {
            Set<Arr<Node, Path>> h = c.hom(x.first, y.first);
            for (Arr<Node, Path> arr : h) {
                if (c.isId(arr)) {
                    continue;
                }
                if (!DefunctGlobalOptions.debug.fql.ALL_GR_PATHS && arr.arr.path.size() != 1) {
                    continue;
                }
                if (doLookup(i, arr.arr, x.second, y.second)) {
                    g2.addEdge(new Pair<>(arr.arr, j++), x, y);
                }
            }
        }
    }
    return new Pair<>(g2, map);
}
Also used : Path(catdata.fql.decl.Path) Arr(catdata.fql.cat.Arr) HashMap(java.util.HashMap) Attribute(catdata.fql.decl.Attribute) Node(catdata.fql.decl.Node) Paint(java.awt.Paint) DirectedSparseMultigraph(edu.uci.ics.jung.graph.DirectedSparseMultigraph) HashMap(java.util.HashMap) Map(java.util.Map) Pair(catdata.Pair)

Aggregations

Attribute (catdata.fql.decl.Attribute)21 Pair (catdata.Pair)20 Node (catdata.fql.decl.Node)19 HashMap (java.util.HashMap)15 LinkedList (java.util.LinkedList)15 Map (java.util.Map)12 FQLException (catdata.fql.FQLException)11 Instance (catdata.fql.decl.Instance)11 LinkedHashMap (java.util.LinkedHashMap)11 Arr (catdata.fql.cat.Arr)10 Edge (catdata.fql.decl.Edge)10 Path (catdata.fql.decl.Path)10 Signature (catdata.fql.decl.Signature)10 List (java.util.List)8 Triple (catdata.Triple)6 Transform (catdata.fql.decl.Transform)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Fn (catdata.fql.Fn)4 FinCat (catdata.fql.cat.FinCat)3