Skip to content

Commit

Permalink
Support correction for shuangpin. (#90)
Browse files Browse the repository at this point in the history
Co-authored-by: Weng Xuetian <wengxt@gmail.com>
  • Loading branch information
bennyyip and wengxt authored Dec 22, 2024
1 parent e321b9d commit df00a0b
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 276 deletions.
9 changes: 8 additions & 1 deletion src/libime/pinyin/pinyincorrectionprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ getProfileMapping(BuiltinPinyinCorrectionProfile profile) {
class PinyinCorrectionProfilePrivate {
public:
PinyinMap pinyinMap_;
std::unordered_map<char, std::vector<char>> correctionMap_;
};

PinyinCorrectionProfile::PinyinCorrectionProfile(
Expand All @@ -57,6 +58,7 @@ PinyinCorrectionProfile::PinyinCorrectionProfile(
const std::unordered_map<char, std::vector<char>> &mapping)
: d_ptr(std::make_unique<PinyinCorrectionProfilePrivate>()) {
FCITX_D();
d->correctionMap_ = mapping;
// Fill with the original pinyin map.
d->pinyinMap_ = getPinyinMapV2();
if (mapping.empty()) {
Expand Down Expand Up @@ -93,4 +95,9 @@ const PinyinMap &PinyinCorrectionProfile::pinyinMap() const {
return d->pinyinMap_;
}

} // namespace libime
const std::unordered_map<char, std::vector<char>> &
PinyinCorrectionProfile::correctionMap() const {
FCITX_D();
return d->correctionMap_;
}
} // namespace libime
11 changes: 10 additions & 1 deletion src/libime/pinyin/pinyincorrectionprofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ class LIBIMEPINYIN_EXPORT PinyinCorrectionProfile {
* @see getPinyinMapV2
*/
const PinyinMap &pinyinMap() const;
/**
* Return the correction mapping.
*
* E.g. w may be corrected to q,e, the mapping will contain {'w': ['q',
* 'e']}.
*
* @see getPinyinMapV2
*/
const std::unordered_map<char, std::vector<char>> &correctionMap() const;

private:
FCITX_DECLARE_PRIVATE(PinyinCorrectionProfile);
Expand All @@ -72,4 +81,4 @@ class LIBIMEPINYIN_EXPORT PinyinCorrectionProfile {

} // namespace libime

#endif
#endif
Loading

0 comments on commit df00a0b

Please sign in to comment.