libime
pinyindecoder.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_PINYIN_PINYINDECODER_H_
7 #define _FCITX_LIBIME_PINYIN_PINYINDECODER_H_
8 
9 #include <memory>
10 #include <string>
11 #include <string_view>
12 #include <libime/core/decoder.h>
13 #include <libime/core/languagemodel.h>
14 #include <libime/core/lattice.h>
15 #include <libime/core/segmentgraph.h>
16 #include <libime/pinyin/libimepinyin_export.h>
17 #include <libime/pinyin/pinyindictionary.h>
18 
19 namespace libime {
20 
21 class PinyinLatticeNodePrivate;
22 
23 class LIBIMEPINYIN_EXPORT PinyinLatticeNode : public LatticeNode {
24 public:
25  PinyinLatticeNode(std::string_view word, WordIndex idx,
26  SegmentGraphPath path, const State &state, float cost,
27  std::unique_ptr<PinyinLatticeNodePrivate> data);
28  virtual ~PinyinLatticeNode();
29 
30  const std::string &encodedPinyin() const;
31  bool isCorrection() const;
32  bool anyCorrectionOnPath() const;
33 
34 private:
35  std::unique_ptr<PinyinLatticeNodePrivate> d_ptr;
36 };
37 
38 class LIBIMEPINYIN_EXPORT PinyinDecoder : public Decoder {
39 public:
40  PinyinDecoder(const PinyinDictionary *dict, const LanguageModelBase *model)
41  : Decoder(dict, model) {}
42 
43 protected:
44  LatticeNode *createLatticeNodeImpl(const SegmentGraphBase &graph,
45  const LanguageModelBase *model,
46  std::string_view word, WordIndex idx,
47  SegmentGraphPath path,
48  const State &state, float cost,
49  std::unique_ptr<LatticeNodeData> data,
50  bool onlyPath) const override;
51 };
52 } // namespace libime
53 
54 #endif // _FCITX_LIBIME_PINYIN_PINYINDECODER_H_
PinyinDictionary is a set of dictionaries for Pinyin.