Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- namespace TextAnalysis
- {
- static class FrequencyAnalysisTask
- {
- public static Dictionary<string,string> CreateKey(List<string> sentence, int i)
- {
- return new Dictionary<string, string> {[sentence[i]] = sentence[i + 1]};
- }
- public static Dictionary<string, string> GetMostFrequentNextWords(List<List<string>> text)
- {
- var result = new Dictionary<string, string>();
- var inGram = new Dictionary<string,string>();
- var gramCount = new Dictionary<Dictionary<string, string>, int>();
- foreach (var sentence in text.Where(sentence => sentence.Count > 1))
- {
- for (var i = 0; i < sentence.Count - 1; i++)
- {
- var gg = CreateKey(sentence, i);
- if (!gramCount.ContainsKey(gg))
- gramCount[gg] = 1;
- else
- gramCount[gg]++;
- }
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement