Skip to content

Commit

Permalink
When parsing with correction flag, u,i,v should not be considered as …
Browse files Browse the repository at this point in the history
…invalid

Fix #67
  • Loading branch information
wengxt committed May 1, 2024
1 parent 21328ab commit 9ed5f07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libime/pinyin/pinyinencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ struct LongestMatchResult {
template <typename Iter>
LongestMatchResult longestMatch(Iter iter, Iter end, PinyinFuzzyFlags flags,
const PinyinMap &map) {
if (*iter == 'i' || *iter == 'u' || *iter == 'v') {
if ((*iter == 'i' || *iter == 'u' || *iter == 'v') &&
!flags.test(PinyinFuzzyFlag::Correction)) {
return {false, std::string_view(&*iter, std::distance(iter, end)),
false};
}
Expand Down
5 changes: 5 additions & 0 deletions test/testpinyinencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ int main() {
auto graph = PinyinEncoder::parseUserPinyin(
"zhyi", &profile, PinyinFuzzyFlag::Correction);
dfs(graph, {"zhyi"});

graph = PinyinEncoder::parseUserPinyin("xianguaoyige", &profile,
PinyinFuzzyFlag::Correction);
dfs(graph, {"xiang", "uao", "yi", "ge"});
dfs(graph, {"xian", "gu", "ao", "yi", "ge"});
}

return 0;
Expand Down

0 comments on commit 9ed5f07

Please sign in to comment.