librime: syllabifier.h Source File

| librime 1.2 Rime Input Method Engine, the core library

syllabifier.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2011-7-12 Zou xu <zouivex@gmail.com>
6//
7
8#ifndef RIME_SYLLABIFIER_H_
9#define RIME_SYLLABIFIER_H_
10
11#include <stdint.h>
12#include <rime_api.h>
13#include <rime/common.h>
14#include "spelling.h"
15
16namespace rime {
17
18class Prism;
19class Corrector;
20
21 using SyllableId = int32_t;
22
23 struct EdgeProperties : SpellingProperties {
24 EdgeProperties(SpellingProperties sup) : SpellingProperties(sup) {};
25 EdgeProperties() = default;
26 // 切分歧義編碼段的起始位置
27 set<size_t> ambiguous_source_positions;
28};
29
30 using SpellingMap = map<SyllableId, EdgeProperties>;
31 using VertexMap = map<size_t, SpellingType>;
32 using EndVertexMap = map<size_t, SpellingMap>;
33 using EdgeMap = map<size_t, EndVertexMap>;
34
35 using SpellingPropertiesList = vector<const EdgeProperties*>;
36 using SpellingIndex = map<SyllableId, SpellingPropertiesList>;
37 using SpellingIndices = map<size_t, SpellingIndex>;
38
39 struct SyllableGraph {
40 size_t input_length = 0;
41 size_t interpreted_length = 0;
42 VertexMap vertices;
43 EdgeMap edges;
44 SpellingIndices indices;
45};
46
47 class Syllabifier {
48 public:
49 Syllabifier() = default;
50 explicit Syllabifier(const string& delimiters,
51 bool enable_completion = false,
52 bool strict_spelling = false)
53 : delimiters_(delimiters),
54 enable_completion_(enable_completion),
55 strict_spelling_(strict_spelling) {}
56
57 RIME_DLL int BuildSyllableGraph(const string& input,
58 Prism& prism,
59 SyllableGraph* graph);
60 RIME_DLL void EnableCorrection(Corrector* corrector);
61
62 protected:
63 void CheckOverlappedSpellings(SyllableGraph* graph, size_t start, size_t end);
64 void Transpose(SyllableGraph* graph);
65
66 string delimiters_;
67 bool enable_completion_ = false;
68 bool strict_spelling_ = false;
69 Corrector* corrector_ = nullptr;
70};
71
72} // namespace rime
73
74#endif // RIME_SYLLABIFIER_H_
spelling.h
common.h
rime_api.h
RIME_DLL
#define RIME_DLL
Definition rime_api.h:33
rime
Definition algebra.cc:12
rime::SpellingIndex
map< SyllableId, SpellingPropertiesList > SpellingIndex
Definition syllabifier.h:36
rime::SpellingIndices
map< size_t, SpellingIndex > SpellingIndices
Definition syllabifier.h:37
rime::EdgeMap
map< size_t, EndVertexMap > EdgeMap
Definition syllabifier.h:33
rime::SpellingPropertiesList
vector< const EdgeProperties * > SpellingPropertiesList
Definition syllabifier.h:35
rime::SpellingMap
map< SyllableId, EdgeProperties > SpellingMap
Definition syllabifier.h:30
rime::VertexMap
map< size_t, SpellingType > VertexMap
Definition syllabifier.h:31
rime::SyllableId
int32_t SyllableId
Definition syllabifier.h:21
rime::EndVertexMap
map< size_t, SpellingMap > EndVertexMap
Definition syllabifier.h:32
rime::corrector
Definition corrector.h:32
rime::prism
Definition prism.h:20
rime::SpellingProperties
Definition spelling.h:24
rime::EdgeProperties::EdgeProperties
EdgeProperties(SpellingProperties sup)
Definition syllabifier.h:24
rime::EdgeProperties::ambiguous_source_positions
set< size_t > ambiguous_source_positions
Definition syllabifier.h:27
rime::EdgeProperties::EdgeProperties
EdgeProperties()=default
rime::SyllableGraph
Definition syllabifier.h:39
rime::SyllableGraph::vertices
VertexMap vertices
Definition syllabifier.h:42
rime::SyllableGraph::indices
SpellingIndices indices
Definition syllabifier.h:44
rime::SyllableGraph::input_length
size_t input_length
Definition syllabifier.h:40
rime::SyllableGraph::interpreted_length
size_t interpreted_length
Definition syllabifier.h:41
rime::SyllableGraph::edges
EdgeMap edges
Definition syllabifier.h:43
rime::Syllabifier::strict_spelling_
bool strict_spelling_
Definition syllabifier.h:68
rime::Syllabifier::Transpose
void Transpose(SyllableGraph *graph)
Definition syllabifier.cc:291
rime::Syllabifier::delimiters_
string delimiters_
Definition syllabifier.h:66
rime::Syllabifier::EnableCorrection
RIME_DLL void EnableCorrection(Corrector *corrector)
Definition syllabifier.cc:303
rime::Syllabifier::Syllabifier
Syllabifier()=default
rime::Syllabifier::BuildSyllableGraph
RIME_DLL int BuildSyllableGraph(const string &input, Prism &prism, SyllableGraph *graph)
Definition syllabifier.cc:30
rime::Syllabifier::Syllabifier
Syllabifier(const string &delimiters, bool enable_completion=false, bool strict_spelling=false)
Definition syllabifier.h:50
rime::Syllabifier::CheckOverlappedSpellings
void CheckOverlappedSpellings(SyllableGraph *graph, size_t start, size_t end)
Definition syllabifier.cc:257
rime::Syllabifier::enable_completion_
bool enable_completion_
Definition syllabifier.h:67
rime::Syllabifier::corrector_
Corrector * corrector_
Definition syllabifier.h:69
rime::Corrector
Definition corrector.h:56
rime::Prism
Definition prism.h:67