libime
tabledecoder.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_TABLE_TABLEDECODER_H_
7 #define _FCITX_LIBIME_TABLE_TABLEDECODER_H_
8 
9 #include <cstddef>
10 #include <cstdint>
11 #include <memory>
12 #include <string>
13 #include <string_view>
14 #include <libime/core/decoder.h>
15 #include <libime/core/languagemodel.h>
16 #include <libime/core/lattice.h>
17 #include <libime/core/segmentgraph.h>
18 #include <libime/table/libimetable_export.h>
19 #include <libime/table/tablebaseddictionary.h>
20 
21 namespace libime {
22 
23 class TableLatticeNodePrivate;
24 
25 class LIBIMETABLE_EXPORT TableLatticeNode : public LatticeNode {
26 public:
27  TableLatticeNode(std::string_view word, WordIndex idx,
28  SegmentGraphPath path, const State &state, float cost,
29  std::unique_ptr<TableLatticeNodePrivate> data);
30  virtual ~TableLatticeNode();
31 
32  uint32_t index() const;
33  PhraseFlag flag() const;
34  const std::string &code() const;
35  size_t codeLength() const;
36 
37 private:
38  std::unique_ptr<TableLatticeNodePrivate> d_ptr;
39 };
40 
41 class LIBIMETABLE_EXPORT TableDecoder : public Decoder {
42 public:
44  const LanguageModelBase *model)
45  : Decoder(dict, model) {}
46 
47 protected:
48  LatticeNode *createLatticeNodeImpl(const SegmentGraphBase &graph,
49  const LanguageModelBase *model,
50  std::string_view word, WordIndex idx,
51  SegmentGraphPath path,
52  const State &state, float cost,
53  std::unique_ptr<LatticeNodeData> data,
54  bool onlyPath) const override;
55 
56  // When segment graph is extremely simple, no need to sort because context
57  // will sort it anyway.
58  bool needSort(const SegmentGraph &graph,
59  const SegmentGraphNode *node) const override;
60 };
61 
62 LIBIMETABLE_EXPORT SegmentGraph graphForCode(std::string_view s,
63  const TableBasedDictionary &dict);
64 } // namespace libime
65 
66 #endif // _FCITX_LIBIME_TABLE_TABLEDECODER_H_