-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcs.h
More file actions
149 lines (148 loc) · 2.49 KB
/
cs.h
File metadata and controls
149 lines (148 loc) · 2.49 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
class word_freq
{
public:
long long count();
bool add(wstring);
void print(double);
void calculate(long long);
long long query(wstring);
vector<wstring> word;
vector<double> freq;
vector<long long> times;
};
long long word_freq::count()
{
return word.size();
}
bool word_freq::add(wstring added_string)
{
bool status=false;
for(long long i=0;i<word.size();i++)
{
if(word[i]==added_string)
{
status=true;
times[i]++;
}
}
if(status==false)
{
word.push_back(added_string);
freq.push_back(0.0);
times.push_back(1);
return true;
}
else
{
return false;
}
}
void word_freq::print(double freq_limit_min=0.0)
{
for(long long i=0;i<word.size();i++)
{
if(freq[i]>=freq_limit_min)
{
wcout<<L"*"<<word[i]<<L":"<<freq[i]<<L"@"<<times[i]<<endl;
}
}
return;
}
void word_freq::calculate(long long word_total)
{
for(long long i=0;i<word.size();i++)
{
freq[i]=(double)times[i]/(double)word_total;
}
return;
}
long long word_freq::query(wstring w)
{
for(long long i=0;i<word.size();i++)
{
if(word[i]==w)
{
return times[i];
}
}
return 0;
}
class entropy
{
public:
void calculate();
wstring word;
vector<wstring> Lbhd;
vector<wstring> Rbhd;
double Letp;
double Retp;
};
void entropy::calculate()
{
}
class entropy_array
{
public:
long long fndItem(wstring);
bool addItem(wstring);
bool addLbhd(wstring,wstring);
bool addRbhd(wstring,wstring);
private:
vector<entropy> etp;
vector<wstring> etp_key;
};
long long entropy_array::fndItem(wstring itemName)
{
bool status=false;
long long location;
for(long long i=0;i<etp_key.size();i++)
{
if(etp_key[i]==itemName)
{
status=true;
location=i;
break;
}
}
if(status==false)
{
return -1;
}
else
{
return location;
}
}
bool entropy_array::addItem(wstring itemName)
{
long long status=fndItem(itemName);
if(status!=-1)
{
return false;
}
entropy etp_i;
etp_i.word=itemName;
etp.push_back(etp_i);
etp_key.push_back(itemName);
return true;
}
bool entropy_array::addLbhd(wstring itemName,wstring Lbhd)
{
long long status=fndItem(itemName);
if(status==-1)
{
return false;
}
etp[status].Lbhd.push_back(Lbhd);
return true;
}
bool entropy_array::addRbhd(wstring itemName,wstring Rbhd)
{
long long status=fndItem(itemName);
if(status==-1)
{
return false;
}
etp[status].Rbhd.push_back(Rbhd);
return true;
}