Skip to content

Commit

Permalink
Add comment for isCorrection value.
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Mar 23, 2024
1 parent d2f8414 commit ad7758a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/libime/pinyin/pinyindictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,14 @@ void matchWordsOnTrie(const MatchedPinyinPath &path, bool matchLongWord,
uint64_t pos;
size_t fuzzies;
std::tie(pos, fuzzies) = pr;
float extraCost = fuzzies * fuzzyCost;
const float extraCost = fuzzies * fuzzyCost;
// This is an inaccuration estimation, since fuzzies may contain real
// fuzzy pinyin. But since this value is 10, it is a good estimate.
// After all 10 fuzzies in a word is kinda impossible.
const bool isCorrection = fuzzies >= PINYIN_CORRECTION_FUZZY_FACTOR;
if (matchLongWord) {
path.trie()->foreach(
[&path, &callback, extraCost, fuzzies](
[&path, &callback, extraCost, isCorrection](
PinyinTrie::value_type value, size_t len, uint64_t pos) {
std::string s;
s.reserve(len + path.size() * 2);
Expand All @@ -371,7 +375,7 @@ void matchWordsOnTrie(const MatchedPinyinPath &path, bool matchLongWord,

callback(encodedPinyin, hanzi,
value + extraCost + overLengthCost,
fuzzies >= PINYIN_CORRECTION_FUZZY_FACTOR);
isCorrection);
}
return true;
},
Expand All @@ -384,7 +388,7 @@ void matchWordsOnTrie(const MatchedPinyinPath &path, bool matchLongWord,
}

path.trie()->foreach(
[&path, &callback, extraCost, fuzzies](
[&path, &callback, extraCost, isCorrection](
PinyinTrie::value_type value, size_t len, uint64_t pos) {
std::string s;
s.reserve(len + path.size() * 2 + 1);
Expand All @@ -393,7 +397,7 @@ void matchWordsOnTrie(const MatchedPinyinPath &path, bool matchLongWord,
auto encodedPinyin = view.substr(0, path.size() * 2);
auto hanzi = view.substr(path.size() * 2 + 1);
callback(encodedPinyin, hanzi, value + extraCost,
fuzzies >= PINYIN_CORRECTION_FUZZY_FACTOR);
isCorrection);
return true;
},
pos);
Expand Down

0 comments on commit ad7758a

Please sign in to comment.