libime
pinyincorrectionprofile.h
1 /*
2  * SPDX-FileCopyrightText: 2024-2024 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  */
6 #ifndef _FCITX_LIBIME_PINYIN_PINYINCORRECTIONPROFILE_H_
7 #define _FCITX_LIBIME_PINYIN_PINYINCORRECTIONPROFILE_H_
8 
9 #include <memory>
10 #include <unordered_map>
11 #include <vector>
12 #include <fcitx-utils/macros.h>
13 #include <libime/pinyin/libimepinyin_export.h>
14 #include <libime/pinyin/pinyindata.h>
15 
16 namespace libime {
17 
18 /**
19  * Built-in pinyin profile mapping
20  *
21  * @since 1.1.7
22  */
23 enum class BuiltinPinyinCorrectionProfile {
24  /**
25  * Pinyin correction based on qwerty keyboard
26  */
27  Qwerty,
28 };
29 
30 class PinyinCorrectionProfilePrivate;
31 
32 /**
33  * Class that holds updated Pinyin correction mapping based on correction
34  * mapping.
35  * @since 1.1.7
36  */
37 class LIBIMEPINYIN_EXPORT PinyinCorrectionProfile {
38 public:
39  /**
40  * Construct the profile based on builtin layout.
41  *
42  * @param profile built-in profile
43  */
44  explicit PinyinCorrectionProfile(BuiltinPinyinCorrectionProfile profile);
45 
46  /**
47  * Construct the profile based on customized mapping.
48  *
49  * E.g. w may be corrected to q,e, the mapping will contain {'w': ['q',
50  * 'e']}.
51  *
52  * @param mapping pinyin character and the corresponding possible wrong key.
53  */
54  explicit PinyinCorrectionProfile(
55  const std::unordered_map<char, std::vector<char>> &mapping);
56 
57  virtual ~PinyinCorrectionProfile();
58 
59  /**
60  * Return the updated pinyin map
61  *
62  * New entries will be marked with PinyinFuzzyFlag::Correction
63  *
64  * @see getPinyinMapV2
65  */
66  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;
76 
77 private:
78  FCITX_DECLARE_PRIVATE(PinyinCorrectionProfile);
79  std::unique_ptr<PinyinCorrectionProfilePrivate> d_ptr;
80 };
81 
82 } // namespace libime
83 
84 #endif
Class that holds updated Pinyin correction mapping based on correction mapping.