Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace TextAnalysis
  5. {
  6. static class FrequencyAnalysisTask
  7. {
  8.  
  9.  
  10. public static Dictionary<string, string> GetMostFrequentNextWords(List<List<string>> text)
  11. {
  12. Dictionary<Tuple<string, string>, int> frequency = new Dictionary<Tuple<string, string>, int>();
  13. Dictionary<string, Tuple<int, string>> help = new Dictionary<string, Tuple<int, string>>();
  14. Dictionary<string, string> bigrams = new Dictionary<string, string>();
  15. List<string> list1 = new List<string>();
  16. Dictionary<string, int> dic = new Dictionary<string, int>();
  17.  
  18. int j = 0;
  19. foreach (var sentence in text)
  20. {
  21. for (int i = 0; i < sentence.Count - 1; i++)
  22. {
  23. if (!frequency.ContainsKey(new Tuple<string, string>(sentence[i], sentence[i + 1])))
  24. frequency.Add(new Tuple<string, string>(sentence[i], sentence[i + 1]), 0);
  25. frequency[new Tuple<string, string>(sentence[i], sentence[i + 1])]++;
  26.  
  27.  
  28. if (sentence[i] == "where")
  29. {
  30. if (!dic.ContainsKey(sentence[i+1]))
  31. dic.Add(sentence[i + 1], 0);
  32. dic[sentence[i + 1]]++;
  33. }
  34.  
  35.  
  36.  
  37. }
  38. }
  39.  
  40.  
  41. foreach (var elemenr in frequency)
  42. {
  43. if (!help.ContainsKey(elemenr.Key.Item1))
  44. help.Add(elemenr.Key.Item1, new Tuple<int, string>(elemenr.Value, elemenr.Key.Item2));
  45. else if (help[elemenr.Key.Item1].Item1 < elemenr.Value
  46. || (help[elemenr.Key.Item1].Item1 == elemenr.Value &&
  47. string.CompareOrdinal(elemenr.Key.Item2, help[elemenr.Key.Item1].Item2) > 0))
  48. help[elemenr.Key.Item1] = new Tuple<int, string>(elemenr.Value, elemenr.Key.Item2);
  49. }
  50.  
  51. Console.WriteLine(help["where"]);
  52.  
  53. foreach (var el in help)
  54. bigrams.Add(el.Key, el.Value.Item2);
  55.  
  56.  
  57.  
  58. return bigrams;
  59. }
  60.  
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement