public static string ToCSVString <Ck1, Ck2>(Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <CK1, CK2> counter, NumberFormat nf, IComparator <CK1> key1Comparator, IComparator <CK2> key2Comparator)
            where Ck1 : IComparable <CK1>
            where Ck2 : IComparable <CK2>
        {
            IList <CK1> firstKeys  = new List <CK1>(counter.FirstKeySet());
            IList <CK2> secondKeys = new List <CK2>(counter.SecondKeySet());

            firstKeys.Sort(key1Comparator);
            secondKeys.Sort(key2Comparator);
            StringBuilder b = new StringBuilder();
            int           secondKeysSize = secondKeys.Count;

            string[] headerRow = new string[secondKeysSize + 1];
            headerRow[0] = string.Empty;
            for (int j = 0; j < secondKeysSize; j++)
            {
                headerRow[j + 1] = secondKeys[j].ToString();
            }
            b.Append(StringUtils.ToCSVString(headerRow)).Append('\n');
            foreach (CK1 rowLabel in firstKeys)
            {
                string[] row = new string[secondKeysSize + 1];
                row[0] = rowLabel.ToString();
                for (int j_1 = 0; j_1 < secondKeysSize; j_1++)
                {
                    CK2 colLabel = secondKeys[j_1];
                    row[j_1 + 1] = nf.Format(counter.GetCount(rowLabel, colLabel));
                }
                b.Append(StringUtils.ToCSVString(row)).Append('\n');
            }
            return(b.ToString());
        }
 public virtual void AddAll(Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <K1, K2> c)
 {
     foreach (K1 key in c.FirstKeySet())
     {
         IntCounter <K2> inner   = c.GetCounter(key);
         IntCounter <K2> myInner = GetCounter(key);
         Counters.AddInPlace(myInner, inner);
         total += inner.TotalIntCount();
     }
 }
 public virtual void SubtractAll(Edu.Stanford.Nlp.Stats.TwoDimensionalIntCounter <K1, K2> c, bool removeKeys)
 {
     foreach (K1 key in c.FirstKeySet())
     {
         IntCounter <K2> inner   = c.GetCounter(key);
         IntCounter <K2> myInner = GetCounter(key);
         Counters.SubtractInPlace(myInner, inner);
         if (removeKeys)
         {
             Counters.RetainNonZeros(myInner);
         }
         total -= inner.TotalIntCount();
     }
 }
 /// <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);
 }