Search in sources :

Example 31 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class FullSigma method exec.

@Override
public void exec(PSMInterp interp, Map<String, Set<Map<Object, Object>>> state) {
    Signature C = f.source;
    Signature D = f.target;
    List<Pair<String, List<Pair<Object, Object>>>> I0 = PSMGen.gather(inst, C, state);
    try {
        Instance I = new Instance(C, I0);
        interp.sigmas.put(pre, interp.guid);
        Quad<Instance, Map<Node, Map<Object, Integer>>, Map<Node, Map<Integer, Object>>, Map<Object, List<Pair<String, Object>>>> xxx = LeftKanSigma.fullSigmaWithAttrs(interp, f, I, null, null, null);
        interp.sigmas2.put(pre, interp.guid);
        Instance J = xxx.first;
        Map<Node, Map<Object, Integer>> yyy = xxx.second;
        for (Node n : C.nodes) {
            state.put(pre + "_" + n.string + "_e", conv2(yyy.get(n)));
        }
        for (Node n : D.nodes) {
            state.put(pre + "_" + n.string, conv(J.data.get(n.string)));
        }
        for (Edge n : D.edges) {
            state.put(pre + "_" + n.name, conv(J.data.get(n.name)));
        }
        for (Attribute<Node> n : D.attrs) {
            state.put(pre + "_" + n.name, conv(J.data.get(n.name)));
        }
        Set<Map<Object, Object>> l = new HashSet<>();
        for (Object k : xxx.fourth.keySet()) {
            List<Pair<String, Object>> v = xxx.fourth.get(k);
            if (v.isEmpty()) {
                continue;
            }
            Map<Object, Object> m = new HashMap<>();
            m.put("c0", k);
            boolean first = true;
            String rest = "";
            for (Pair<String, Object> p : v) {
                if (first) {
                    first = false;
                    m.put("c1", p.first);
                    m.put("c2", p.second);
                } else {
                    rest += p.first;
                }
            }
            m.put("c3", rest);
            l.add(m);
        }
        state.put(pre + "_lineage", l);
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException("Error in instance " + pre + ": " + e.getLocalizedMessage());
    }
}
Also used : Instance(catdata.fql.decl.Instance) HashMap(java.util.HashMap) Node(catdata.fql.decl.Node) Signature(catdata.fql.decl.Signature) HashMap(java.util.HashMap) Map(java.util.Map) Edge(catdata.fql.decl.Edge) Pair(catdata.Pair) HashSet(java.util.HashSet)

Example 32 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class FinSet method hom.

@SuppressWarnings({ "unchecked" })
@Override
public Set hom(Set A, Set B) {
    Pair<Set, Set> p = new Pair<>(A, B);
    Set retX = cached.get(p);
    if (retX != null) {
        return retX;
    }
    Set<Fn> ret = new HashSet<>();
    List<LinkedHashMap<Set, Set>> k = homomorphs(new LinkedList<>(A), new LinkedList<>(B));
    for (LinkedHashMap<Set, Set> v : k) {
        ret.add(new Fn(A, B, v::get));
    }
    cached.put(p, ret);
    return ret;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Fn(catdata.fqlpp.cat.FinSet.Fn) Pair(catdata.Pair) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap)

Example 33 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class Functor method compose.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static <O1, A1, O2, A2, O3, A3> Functor<O1, A1, O3, A3> compose(Functor<O1, A1, O2, A2> a1, Functor<O2, A2, O3, A3> a2) {
    Pair p = new Pair<>(a1, a2);
    if (cache.containsKey(p)) {
        return cache.get(p);
    }
    if (!a1.target.equals(a2.source)) {
        throw new RuntimeException("Dom/Cod mismatch on " + a1 + " and " + a2);
    }
    cache.put(p, new Functor<>(a1.source, a2.target, a1.o.andThen(a2.o), a1.a.andThen(a2.a)));
    return cache.get(p);
}
Also used : Pair(catdata.Pair)

Example 34 with Pair

use of catdata.Pair in project fql by CategoricalData.

the class Inst method split.

private Pair<Functor<O, A, Set, Fn>, Functor<O, A, Set, Fn>> split(Functor<O, A, Set, Fn> I) {
    Map<O, Set> nm1 = new HashMap<>();
    Map<A, Fn> em1 = new HashMap<>();
    Map<O, Set> nm2 = new HashMap<>();
    Map<A, Fn> em2 = new HashMap<>();
    for (O o : I.source.objects()) {
        Set s1 = new HashSet();
        Set s2 = new HashSet();
        for (Object x : I.applyO(o)) {
            Pair p = (Pair) x;
            s1.add(p.first);
            s2.add(p.second);
        }
        nm1.put(o, s1);
        nm2.put(o, s2);
    }
    for (A a : I.source.arrows()) {
        Map s1 = new HashMap();
        Map s2 = new HashMap();
        for (Object o : I.applyO(I.source.source(a))) {
            Pair q = (Pair) o;
            Pair p = (Pair) I.applyA(a).apply(o);
            s1.put(q.first, p.first);
            s2.put(q.second, p.second);
        }
        Fn f1 = new Fn(nm1.get(I.source.source(a)), nm1.get(I.source.target(a)), s1::get);
        Fn f2 = new Fn(nm2.get(I.source.source(a)), nm2.get(I.source.target(a)), s2::get);
        em1.put(a, f1);
        em2.put(a, f2);
    }
    Functor<O, A, Set, Fn> fst = new Functor<>(cat, FinSet.FinSet, nm1::get, em1::get);
    Functor<O, A, Set, Fn> snd = new Functor<>(cat, FinSet.FinSet, nm2::get, em2::get);
    return new Pair<>(fst, snd);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Fn(catdata.fqlpp.cat.FinSet.Fn) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet) Pair(catdata.Pair)

Example 35 with Pair

use of catdata.Pair 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)

Aggregations

Pair (catdata.Pair)305 LinkedList (java.util.LinkedList)169 HashMap (java.util.HashMap)144 List (java.util.List)127 HashSet (java.util.HashSet)101 Triple (catdata.Triple)98 Map (java.util.Map)94 LinkedHashMap (java.util.LinkedHashMap)82 Set (java.util.Set)70 Tuple3 (org.jparsec.functors.Tuple3)46 Node (catdata.fql.decl.Node)38 JPanel (javax.swing.JPanel)37 GridLayout (java.awt.GridLayout)32 FQLException (catdata.fql.FQLException)31 Paint (java.awt.Paint)29 Chc (catdata.Chc)28 Util (catdata.Util)27 En (catdata.aql.exp.SchExpRaw.En)26 Tuple5 (org.jparsec.functors.Tuple5)26 Ty (catdata.aql.exp.TyExpRaw.Ty)25