public virtual void Clean() { foreach (K1 key1 in Generics.NewHashSet(map.Keys)) { IntCounter <K2> c = map[key1]; foreach (K2 key2 in Generics.NewHashSet(c.KeySet())) { if (c.GetIntCount(key2) == 0) { c.Remove(key2); } } if (c.KeySet().IsEmpty()) { Sharpen.Collections.Remove(map, key1); } } }
public virtual int GetCount(K1 o1, K2 o2) { IntCounter <K2> c = GetCounter(o1); if (c.TotalCount() == 0 && !c.KeySet().Contains(o2)) { return(DefaultReturnValue()); } return(c.GetIntCount(o2)); }
public virtual IntCounter <Pair <K1, K2> > Flatten() { IntCounter <Pair <K1, K2> > result = new IntCounter <Pair <K1, K2> >(); result.SetDefaultReturnValue(defaultValue); foreach (K1 key1 in FirstKeySet()) { IntCounter <K2> inner = GetCounter(key1); foreach (K2 key2 in inner.KeySet()) { result.SetCount(new Pair <K1, K2>(key1, key2), inner.GetIntCount(key2)); } } return(result); }
/// <summary> /// A simple String representation of this TwoDimensionalCounter, which has /// the String representation of each key pair /// on a separate line, followed by the count for that pair. /// </summary> /// <remarks> /// A simple String representation of this TwoDimensionalCounter, which has /// the String representation of each key pair /// on a separate line, followed by the count for that pair. /// The items are tab separated, so the result is a tab-separated value (TSV) /// file. Iff none of the keys contain spaces, it will also be possible to /// treat this as whitespace separated fields. /// </remarks> public override string ToString() { StringBuilder buff = new StringBuilder(); foreach (K1 key1 in map.Keys) { IntCounter <K2> c = GetCounter(key1); foreach (K2 key2 in c.KeySet()) { double score = c.GetCount(key2); buff.Append(key1).Append("\t").Append(key2).Append("\t").Append(score).Append("\n"); } } return(buff.ToString()); }
/// <summary>Produces a new ConditionalCounter.</summary> /// <returns>a new ConditionalCounter, where order of indices is reversed</returns> public static Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <K2, K1> ReverseIndexOrder <K1, K2>(Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <K1, K2> cc) { // the typing on the outerMF is violated a bit, but it'll work.... Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <K2, K1> result = new Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter((MapFactory)cc.outerMF, (MapFactory)cc.innerMF); foreach (K1 key1 in cc.FirstKeySet()) { IntCounter <K2> c = cc.GetCounter(key1); foreach (K2 key2 in c.KeySet()) { int count = c.GetIntCount(key2); result.SetCount(key2, key1, count); } } return(result); }