Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- namespace WordCountCS
- {
- class Program
- {
- static void Main(string[] args)
- {
- var sw = new System.Diagnostics.Stopwatch();
- sw.Start();
- Directory.EnumerateFiles(@"C:\TEMP\20_newsgroups", "*", SearchOption.AllDirectories)
- .AsParallel()
- .AsUnordered()
- .SelectMany(fn => File.ReadLines(fn))
- .SelectMany(line => line.Split(' ', '.', ':', ';', '?'))
- .GroupBy(key => key, element => element, (word, grouping) => new { word, count = grouping.Count() })
- .ForAll(x => Console.WriteLine("{0}:{1}", x.word, x.count));
- Console.Error.WriteLine("Elapsed: {0}", sw.Elapsed);
- }
- }
- }
Add Comment
Please, Sign In to add comment