libime
prediction.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_PREDICTION_H_
7 #define _FCITX_LIBIME_CORE_PREDICTION_H_
8 
9 #include <cstddef>
10 #include <memory>
11 #include <string>
12 #include <utility>
13 #include <vector>
14 #include <fcitx-utils/macros.h>
15 #include <libime/core/languagemodel.h>
16 #include <libime/core/libimecore_export.h>
17 #include <libime/core/userlanguagemodel.h>
18 
19 namespace libime {
20 
21 class PredictionPrivate;
22 class HistoryBigram;
23 
24 class LIBIMECORE_EXPORT Prediction {
25 public:
26  Prediction();
27  virtual ~Prediction();
28 
29  void setUserLanguageModel(const UserLanguageModel *lm) {
30  setLanguageModel(lm);
31  setHistoryBigram(&lm->history());
32  }
33 
34  void setLanguageModel(const LanguageModel *model);
35 
36  const LanguageModel *model() const;
37 
38  void setHistoryBigram(const HistoryBigram *bigram);
39 
40  const HistoryBigram *historyBigram() const;
41 
42  std::vector<std::string>
43  predict(const State &state, const std::vector<std::string> &sentence = {},
44  size_t maxSize = 0);
45  std::vector<std::string>
46  predict(const std::vector<std::string> &sentence = {}, size_t maxSize = 0);
47 
48  std::vector<std::pair<std::string, float>>
49  predictWithScore(const State &state,
50  const std::vector<std::string> &sentence, size_t maxSize);
51 
52 private:
53  std::unique_ptr<PredictionPrivate> d_ptr;
54  FCITX_DECLARE_PRIVATE(Prediction);
55 };
56 
57 } // namespace libime
58 
59 #endif // _LIBIM_LIBIME_CORE_PREDICTION_H_