Guest User

Untitled

a guest
Apr 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4.  
  5. namespace WordCountCS
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var sw = new System.Diagnostics.Stopwatch();
  12. sw.Start();
  13. Directory.EnumerateFiles(@"C:\TEMP\20_newsgroups", "*", SearchOption.AllDirectories)
  14. .AsParallel()
  15. .AsUnordered()
  16. .SelectMany(fn => File.ReadLines(fn))
  17. .SelectMany(line => line.Split(' ', '.', ':', ';', '?'))
  18. .GroupBy(key => key, element => element, (word, grouping) => new { word, count = grouping.Count() })
  19. .ForAll(x => Console.WriteLine("{0}:{1}", x.word, x.count));
  20. Console.Error.WriteLine("Elapsed: {0}", sw.Elapsed);
  21. }
  22. }
  23. }
Add Comment
Please, Sign In to add comment