Skip to content

Commit

Permalink
It seems that no shuangpin actually use "ng" as "ng". just remove it …
Browse files Browse the repository at this point in the history
…explicitly.

It should still possible to add NG=NG in direct profile.
  • Loading branch information
wengxt committed Mar 10, 2024
1 parent 0716195 commit 50aef18
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libime/pinyin/shuangpinprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ void ShuangpinProfile::buildShuangpinTable() {

// Add non-existent 2 char pinyin to the map.
for (const auto &p : getPinyinMapV2()) {
// Don't add "ng" as two char direct pinyin.
if (p.pinyin() == "ng") {
continue;
}

if (p.pinyin().size() == 2 && p.initial() == PinyinInitial::Zero &&
(!d->spTable_.count(p.pinyin()) ||
d->zeroS_.find('*') != std::string::npos)) {
Expand Down
20 changes: 20 additions & 0 deletions test/testshuangpinprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ void checkXiaoHe() {
});
}

void checkZiranma() {
ShuangpinProfile profile(ShuangpinBuiltinProfile::Ziranma);
FCITX_ASSERT(profile.table().count("ng") == 1);
FCITX_ASSERT(profile.table().find("ng")->second.count(PinyinSyllable(
PinyinInitial::N, libime::PinyinFinal::ENG)) == 1);
FCITX_ASSERT(profile.table().find("ng")->second.count(PinyinSyllable(
PinyinInitial::Zero, libime::PinyinFinal::NG)) == 0);
PinyinEncoder::parseUserShuangpin("aiaaah", profile, PinyinFuzzyFlag::None)
.dfs([](const SegmentGraphBase &segs, const std::vector<size_t> &path) {
size_t s = 0;
for (auto e : path) {
std::cout << segs.segment(s, e) << " ";
s = e;
}
std::cout << std::endl;
return true;
});
}

void checkSegments(const libime::SegmentGraph &graph,
std::vector<std::vector<std::string>> segments) {
graph.dfs([&segments](const SegmentGraphBase &segs,
Expand Down Expand Up @@ -513,6 +532,7 @@ int main() {
checkProfile(ShuangpinProfile(ShuangpinBuiltinProfile::Xiaohe), false);
checkABC();
checkXiaoHe();
checkZiranma();

// wo jiu shi xiang ce shi yi xia
checkSegments(PinyinEncoder::parseUserShuangpin(
Expand Down

0 comments on commit 50aef18

Please sign in to comment.