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());
}
}
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;
}
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);
}
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);
}
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);
}
Aggregations