Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace TextAnalysis
- {
- static class FrequencyAnalysisTask
- {
- public static Dictionary<string, string> GetMostFrequentNextWords(List<List<string>> text)
- {
- Dictionary<Tuple<string, string>, int> frequency = new Dictionary<Tuple<string, string>, int>();
- Dictionary<string, Tuple<int, string>> help = new Dictionary<string, Tuple<int, string>>();
- Dictionary<string, string> bigrams = new Dictionary<string, string>();
- List<string> list1 = new List<string>();
- Dictionary<string, int> dic = new Dictionary<string, int>();
- int j = 0;
- foreach (var sentence in text)
- {
- for (int i = 0; i < sentence.Count - 1; i++)
- {
- if (!frequency.ContainsKey(new Tuple<string, string>(sentence[i], sentence[i + 1])))
- frequency.Add(new Tuple<string, string>(sentence[i], sentence[i + 1]), 0);
- frequency[new Tuple<string, string>(sentence[i], sentence[i + 1])]++;
- if (sentence[i] == "where")
- {
- if (!dic.ContainsKey(sentence[i+1]))
- dic.Add(sentence[i + 1], 0);
- dic[sentence[i + 1]]++;
- }
- }
- }
- foreach (var elemenr in frequency)
- {
- if (!help.ContainsKey(elemenr.Key.Item1))
- help.Add(elemenr.Key.Item1, new Tuple<int, string>(elemenr.Value, elemenr.Key.Item2));
- else if (help[elemenr.Key.Item1].Item1 < elemenr.Value
- || (help[elemenr.Key.Item1].Item1 == elemenr.Value &&
- string.CompareOrdinal(elemenr.Key.Item2, help[elemenr.Key.Item1].Item2) > 0))
- help[elemenr.Key.Item1] = new Tuple<int, string>(elemenr.Value, elemenr.Key.Item2);
- }
- Console.WriteLine(help["where"]);
- foreach (var el in help)
- bigrams.Add(el.Key, el.Value.Item2);
- return bigrams;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement