8 #ifndef _FCITX_LIBIME_TABLE_TABLEBASEDDICTIONARY_H_ 9 #define _FCITX_LIBIME_TABLE_TABLEBASEDDICTIONARY_H_ 18 #include <string_view> 19 #include <unordered_set> 21 #include <fcitx-utils/connectableobject.h> 22 #include <fcitx-utils/macros.h> 23 #include <fcitx-utils/signals.h> 24 #include <libime/core/dictionary.h> 25 #include <libime/core/segmentgraph.h> 26 #include <libime/table/libimetable_export.h> 29 class TableBasedDictionaryPrivate;
32 enum class PhraseFlag {
42 using TableMatchCallback = std::function<bool(
43 std::string_view, std::string_view, uint32_t, PhraseFlag)>;
45 enum class TableFormat { Text, Binary };
46 enum class TableMatchMode { Exact, Prefix };
52 public fcitx::ConnectableObject {
61 void load(
const char *filename, TableFormat format = TableFormat::Binary);
62 void load(std::istream &in, TableFormat format = TableFormat::Binary);
63 void save(
const char *filename, TableFormat format = TableFormat::Binary);
64 void save(std::ostream &out, TableFormat format = TableFormat::Binary);
66 void loadUser(
const char *filename,
67 TableFormat format = TableFormat::Binary);
68 void loadUser(std::istream &in, TableFormat format = TableFormat::Binary);
69 void saveUser(
const char *filename,
70 TableFormat format = TableFormat::Binary);
71 void saveUser(std::ostream &out, TableFormat format = TableFormat::Binary);
73 size_t loadExtra(
const char *filename,
74 TableFormat format = TableFormat::Binary);
75 size_t loadExtra(std::istream &in,
76 TableFormat format = TableFormat::Binary);
77 void saveExtra(
size_t index,
const char *filename,
78 TableFormat format = TableFormat::Binary);
79 void saveExtra(
size_t index, std::ostream &out,
80 TableFormat format = TableFormat::Binary);
82 void removeAllExtra();
84 bool hasRule()
const noexcept;
85 bool hasCustomPrompt()
const noexcept;
86 const TableRule *findRule(std::string_view name)
const;
87 bool insert(std::string_view key, std::string_view value,
88 PhraseFlag flag = PhraseFlag::None,
89 bool verifyWithRule =
false);
90 bool insert(std::string_view value, PhraseFlag flag = PhraseFlag::None);
91 bool generate(std::string_view value, std::string &key)
const;
92 bool generateWithHint(std::string_view value,
93 const std::vector<std::string> &codeHint,
94 std::string &key)
const;
96 bool isInputCode(uint32_t c)
const;
97 bool isAllInputCode(std::string_view code)
const;
98 bool isEndKey(uint32_t c)
const;
100 bool hasPinyin()
const;
101 uint32_t maxLength()
const;
102 bool isValidLength(
size_t length)
const;
104 void statistic()
const;
109 bool matchWords(std::string_view code, TableMatchMode mode,
110 const TableMatchCallback &callback)
const;
112 bool hasMatchingWords(std::string_view code)
const;
113 bool hasMatchingWords(std::string_view code, std::string_view next)
const;
115 bool hasOneMatchingWord(std::string_view code)
const;
117 PhraseFlag wordExists(std::string_view code, std::string_view word)
const;
118 void removeWord(std::string_view code, std::string_view word);
120 std::string reverseLookup(std::string_view word,
121 PhraseFlag flag = PhraseFlag::None)
const;
122 std::string hint(std::string_view key)
const;
127 void loadText(std::istream &in);
128 void loadBinary(std::istream &in);
129 void saveText(std::ostream &out);
130 void saveBinary(std::ostream &origOut);
134 const GraphMatchCallback &callback,
135 const std::unordered_set<const SegmentGraphNode *> &ignore,
136 void *helper)
const override;
138 std::unique_ptr<TableBasedDictionaryPrivate> d_ptr;
143 #endif // _FCITX_LIBIME_TABLE_TABLEBASEDDICTIONARY_H_