public static void Main(string[] args) { Edu.Stanford.Nlp.Stats.TwoDimensionalCounter <string, string> cc = new Edu.Stanford.Nlp.Stats.TwoDimensionalCounter <string, string>(); cc.SetCount("a", "c", 1.0); cc.SetCount("b", "c", 1.0); cc.SetCount("a", "d", 1.0); cc.SetCount("a", "d", -1.0); cc.SetCount("b", "d", 1.0); System.Console.Out.WriteLine(cc); cc.IncrementCount("b", "d", 1.0); System.Console.Out.WriteLine(cc); Edu.Stanford.Nlp.Stats.TwoDimensionalCounter <string, string> cc2 = Edu.Stanford.Nlp.Stats.TwoDimensionalCounter.ReverseIndexOrder(cc); System.Console.Out.WriteLine(cc2); }
/// <summary>Produces a new ConditionalCounter.</summary> /// <returns>a new ConditionalCounter, where order of indices is reversed</returns> public static Edu.Stanford.Nlp.Stats.TwoDimensionalCounter <K2, K1> ReverseIndexOrder <K1, K2>(Edu.Stanford.Nlp.Stats.TwoDimensionalCounter <K1, K2> cc) { // they typing on the outerMF is violated a bit, but it'll work.... Edu.Stanford.Nlp.Stats.TwoDimensionalCounter <K2, K1> result = new Edu.Stanford.Nlp.Stats.TwoDimensionalCounter((MapFactory)cc.outerMF, (MapFactory)cc.innerMF); foreach (K1 key1 in cc.FirstKeySet()) { ClassicCounter <K2> c = cc.GetCounter(key1); foreach (K2 key2 in c.KeySet()) { double count = c.GetCount(key2); result.SetCount(key2, key1, count); } } return(result); }