progarmm source code that demonstrate frequency words(use from c# tokenizer)?
Loading
progarmm source code that demonstrate frequency words(use from c# tokenizer)?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted May 16, 2012, 5:32 AM EDT
using System;
using System.Linq;
using System.Text.RegularExpressions;
class Test
{
static void Main()
{
string text = "The quick brown fox jumps over the quick lazy dog and the quick brown cat";
MatchCollection mc = Regex.Matches(text, @"\b\w+\b");
var query = from Match m in mc group m by m.Value.ToLower() into g select new {Word = g.Key, Frequency = g.Count()};
foreach(var item in query)
{
Console.WriteLine("{0} : {1}", item.Word, item.Frequency);
}
Console.ReadKey();
}
}
A 'word' for this purpose can only consist of the characters: a-z, A-Z, 0-9 or underscore but can be easily changed to include other characters.
The output of the above program should be:
the : 3
quick : 3
brown : 2
fox : 1
jumps : 1
over : 1
lazy : 1
dog : 1
and : 1
cat : 1
Azharunissa Khan16 reputationPosted Dec 26, 2013, 8:53 PM EST
Instead of taking a plain text as input,can we take a text file at run time and execute the code given
above?
If so,what is the procedure or code required?
And thank you so much for providing us the code.
VulpesRank #55 · 29.2K reputationPosted Dec 27, 2013, 5:32 AM EST
Here's some revised code:
Azharunissa Khan16 reputationPosted Jan 1, 2014, 6:16 PM EST