c#代码备忘

1、统计词频。重点在于统计后的排序

                    Dictionary<string, WordStatistic> dws = new Dictionary<string, WordStatistic>();
                    WordStatistic ws = null;
                    foreach (string s in words)
                    {
                        if (dws.ContainsKey(s))
                        {
                            dws.TryGetValue(s, out ws);
                            ws.WordCount++;
                        }
                        else
                        {
                            ws = new WordStatistic();
                            ws.WordCount++;
                            ws.Word = s;
                            dws.Add(s, ws);
                        }
                    }

                    Dictionary<string, WordStatistic>.ValueCollection vc = dws.Values;
                    List<WordStatistic> lws = vc.ToList();

                    IEnumerable<WordStatistic> siws = lws.OrderByDescending(sws => sws.WordCount);
                    List<WordStatistic> slws = siws.ToList();

  

posted @ 2013-08-14 09:51  惡盈好謙  阅读(170)  评论(0编辑  收藏  举报