public Dictionary<string, int> TopWords(int topCount, bool caseSensitive, string content)
{
char[] signs = { ',', '.', '?', ';', '!', '\t', '\n' };
IEnumerable<string> words = content.Trim(signs).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (caseSensitive)
{
return words.GroupBy(w => w.Trim()).OrderByDescending(g => g.Count()).Take(topCount).ToDictionary(g => g.Key, g => g.Count());
}
else
{
return words.GroupBy(w => w.ToLower().Trim()).OrderByDescending(g => g.Count()).Take(topCount).ToDictionary(g => g.First(), g => g.Count());
}
}
{
char[] signs = { ',', '.', '?', ';', '!', '\t', '\n' };
IEnumerable<string> words = content.Trim(signs).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (caseSensitive)
{
return words.GroupBy(w => w.Trim()).OrderByDescending(g => g.Count()).Take(topCount).ToDictionary(g => g.Key, g => g.Count());
}
else
{
return words.GroupBy(w => w.ToLower().Trim()).OrderByDescending(g => g.Count()).Take(topCount).ToDictionary(g => g.First(), g => g.Count());
}
}