Skip to content

Commit df00a0b

Browse files
bennyyipwengxt
andauthored
Support correction for shuangpin. (#90)
Co-authored-by: Weng Xuetian <[email protected]>
1 parent e321b9d commit df00a0b

6 files changed

+405
-276
lines changed

src/libime/pinyin/pinyincorrectionprofile.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ getProfileMapping(BuiltinPinyinCorrectionProfile profile) {
4747
class PinyinCorrectionProfilePrivate {
4848
public:
4949
PinyinMap pinyinMap_;
50+
std::unordered_map<char, std::vector<char>> correctionMap_;
5051
};
5152

5253
PinyinCorrectionProfile::PinyinCorrectionProfile(
@@ -57,6 +58,7 @@ PinyinCorrectionProfile::PinyinCorrectionProfile(
5758
const std::unordered_map<char, std::vector<char>> &mapping)
5859
: d_ptr(std::make_unique<PinyinCorrectionProfilePrivate>()) {
5960
FCITX_D();
61+
d->correctionMap_ = mapping;
6062
// Fill with the original pinyin map.
6163
d->pinyinMap_ = getPinyinMapV2();
6264
if (mapping.empty()) {
@@ -93,4 +95,9 @@ const PinyinMap &PinyinCorrectionProfile::pinyinMap() const {
9395
return d->pinyinMap_;
9496
}
9597

96-
} // namespace libime
98+
const std::unordered_map<char, std::vector<char>> &
99+
PinyinCorrectionProfile::correctionMap() const {
100+
FCITX_D();
101+
return d->correctionMap_;
102+
}
103+
} // namespace libime

src/libime/pinyin/pinyincorrectionprofile.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ class LIBIMEPINYIN_EXPORT PinyinCorrectionProfile {
6464
* @see getPinyinMapV2
6565
*/
6666
const PinyinMap &pinyinMap() const;
67+
/**
68+
* Return the correction mapping.
69+
*
70+
* E.g. w may be corrected to q,e, the mapping will contain {'w': ['q',
71+
* 'e']}.
72+
*
73+
* @see getPinyinMapV2
74+
*/
75+
const std::unordered_map<char, std::vector<char>> &correctionMap() const;
6776

6877
private:
6978
FCITX_DECLARE_PRIVATE(PinyinCorrectionProfile);
@@ -72,4 +81,4 @@ class LIBIMEPINYIN_EXPORT PinyinCorrectionProfile {
7281

7382
} // namespace libime
7483

75-
#endif
84+
#endif

0 commit comments

Comments
 (0)