Advertisement
nekotrap

Untitled

Oct 16th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3.  
  4. namespace TextAnalysis
  5. {
  6. static class FrequencyAnalysisTask
  7. {
  8. public static Dictionary<string,string> CreateKey(List<string> sentence, int i)
  9. {
  10. return new Dictionary<string, string> {[sentence[i]] = sentence[i + 1]};
  11. }
  12. public static Dictionary<string, string> GetMostFrequentNextWords(List<List<string>> text)
  13. {
  14. var result = new Dictionary<string, string>();
  15. var inGram = new Dictionary<string,string>();
  16. var gramCount = new Dictionary<Dictionary<string, string>, int>();
  17. foreach (var sentence in text.Where(sentence => sentence.Count > 1))
  18. {
  19. for (var i = 0; i < sentence.Count - 1; i++)
  20. {
  21. var gg = CreateKey(sentence, i);
  22. if (!gramCount.ContainsKey(gg))
  23. gramCount[gg] = 1;
  24. else
  25. gramCount[gg]++;
  26. }
  27. }
  28. return result;
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement