libime
userlanguagemodel.h
1 /*
2  * SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  */
6 #ifndef _FCITX_LIBIME_CORE_USERLANGUAGEMODEL_H_
7 #define _FCITX_LIBIME_CORE_USERLANGUAGEMODEL_H_
8 
9 #include <istream>
10 #include <memory>
11 #include <ostream>
12 #include <string>
13 #include <string_view>
14 #include <vector>
15 #include <fcitx-utils/macros.h>
16 #include <libime/core/historybigram.h>
17 #include <libime/core/languagemodel.h>
18 #include <libime/core/libimecore_export.h>
19 
20 namespace libime {
21 
22 class UserLanguageModelPrivate;
23 class HistoryBigram;
24 
25 class LIBIMECORE_EXPORT UserLanguageModel : public LanguageModel {
26 public:
27  explicit UserLanguageModel(const char *sysfile);
28 
30  std::shared_ptr<const StaticLanguageModelFile> file = nullptr);
31  virtual ~UserLanguageModel();
32 
33  HistoryBigram &history();
34  const HistoryBigram &history() const;
35  void load(std::istream &in);
36  void save(std::ostream &out);
37 
38  void setHistoryWeight(float w);
39  float historyWeight() const;
40 
41  void setUseOnlyUnigram(bool useOnlyUnigram);
42  bool useOnlyUnigram() const;
43 
44  const State &beginState() const override;
45  const State &nullState() const override;
46  float score(const State &state, const WordNode &word,
47  State &out) const override;
48  bool isUnknown(WordIndex idx, std::string_view view) const override;
49 
50  bool containsNonUnigram(const std::vector<std::string> &words) const;
51 
52  void setCodeExtractor(ValidationCodeExtractor extractor);
53 
54 private:
55  std::unique_ptr<UserLanguageModelPrivate> d_ptr;
56  FCITX_DECLARE_PRIVATE(UserLanguageModel);
57 };
58 } // namespace libime
59 
60 #endif // _FCITX_LIBIME_CORE_USERLANGUAGEMODEL_H_