-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrequencyAnalysisTask.cs
77 lines (61 loc) · 2.04 KB
/
FrequencyAnalysisTask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
namespace TextAnalysis
{
internal static class FrequencyAnalysisTask
{
public static Dictionary<string, string> GetMostFrequentNextWords(List<List<string>> text)
{
Dictionary<string, string> result = new Dictionary<string, string>();
Dictionary<string, int> frequency = new Dictionary<string, int>();
List<string> allx2gramas = new List<string>(Get2gramas(text));
foreach (var item in allx2gramas)
{
if (!frequency.ContainsKey(item))
frequency.Add(item, 1);
else
frequency[item]++;
}
List<string> allx3gramas = new List<string>(Get3gramas(text));
foreach (var item in allx3gramas)
{
if (!frequency.ContainsKey(item))
frequency.Add(item, 1);
else
frequency[item]++;
}
for (int i = 0; i < frequency.Count; i++)
{
if (true)
{
}
}
return result;
}
private static List<string> Get3gramas(List<List<string>> text)
{
List<string> result = new List<string>();
foreach (var item in text)
{
for (int i = 0; i < item.Count - 2; i++)
result.Add(item[i] + " "
+ item[i + 1] + " "
+ item[i + 2]);
}
result.Sort();
return result;
}
private static List<string> Get2gramas(List<List<string>> text)
{
List<string> result = new List<string>();
foreach (var item in text)
{
for (int i = 0; i < item.Count - 1; i++)
result.Add(item[i] + " "
+ item[i + 1]);
}
result.Sort();
return result;
}
}
}