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();
浙公网安备 33010602011771号