4
4
//
5
5
// 2011-11-27 GONG Chen <chen.sst@gmail.com>
6
6
//
7
+ #include < algorithm>
7
8
#include < fstream>
9
+ #include < utility>
8
10
#include < boost/algorithm/string.hpp>
9
11
#include < boost/lexical_cast.hpp>
10
12
#include < rime/algo/strings.h>
@@ -192,12 +194,14 @@ void EntryCollector::CreateEntry(const string& word,
192
194
bool is_word = (e->raw_code .size () == 1 );
193
195
if (is_word) {
194
196
auto & weights = words[e->text ];
195
- if (weights.find (code_str) != weights.end ()) {
197
+ if (std::find_if (weights.begin (), weights.end (), [&](const auto & p) {
198
+ return p.first == code_str;
199
+ }) != weights.end ()) {
196
200
LOG (WARNING) << " duplicate word definition '" << e->text << " ': ["
197
201
<< code_str << " ]." ;
198
202
return ;
199
203
}
200
- weights[ code_str] += e->weight ;
204
+ weights. push_back ( std::make_pair ( code_str, e->weight )) ;
201
205
total_weight[e->text ] += e->weight ;
202
206
}
203
207
entries.emplace_back (std::move (e));
@@ -214,6 +218,8 @@ bool EntryCollector::TranslateWord(const string& word, vector<string>* result) {
214
218
}
215
219
const auto & w = words.find (word);
216
220
if (w != words.end ()) {
221
+ std::sort (w->second .begin (), w->second .end (),
222
+ [](const auto & a, const auto & b) { return a.first < b.first ; });
217
223
for (const auto & v : w->second ) {
218
224
const double kMinimalWeight = 0.05 ; // 5%
219
225
double min_weight = total_weight[word] * kMinimalWeight ;
0 commit comments