librime 1.2
Rime Input Method Engine, the core library
prism.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2011-05-16 Zou Xu <zouivex@gmail.com>
6// 2012-01-26 GONG Chen <chen.sst@gmail.com> spelling algebra support
7//
8
9#ifndef RIME_PRISM_H_
10#define RIME_PRISM_H_
11
12#include <darts.h>
13#include <rime/common.h>
14#include <rime/algo/spelling.h>
17
18namespace rime {
19
20namespace prism {
21
22using Credibility = float;
23
26 // bit 30: is_correction
27 int32_t type;
30};
31
34
35struct Metadata {
36 static const int kFormatMaxLength = 32;
40 uint32_t num_syllables;
41 uint32_t num_spellings;
44 // v1.0
46 char alphabet[256];
47};
48
49} // namespace prism
50
52 public:
53 SpellingAccessor(prism::SpellingMap* spelling_map, SyllableId spelling_id);
54 bool Next();
55 bool exhausted() const;
56 SyllableId syllable_id() const;
58
59 protected:
63};
64
65class Script;
66
67class Prism : public MappedFile {
68 public:
69 using Match = Darts::DoubleArray::result_pair_type;
70
71 RIME_DLL explicit Prism(const path& file_path);
72
73 RIME_DLL bool Load();
74 RIME_DLL bool Save();
75 RIME_DLL bool Build(const Syllabary& syllabary,
76 const Script* script = nullptr,
77 uint32_t dict_file_checksum = 0,
78 uint32_t schema_file_checksum = 0);
79
80 RIME_DLL bool HasKey(const string& key);
81 RIME_DLL bool GetValue(const string& key, int* value) const;
82 RIME_DLL void CommonPrefixSearch(const string& key, vector<Match>* result);
83 RIME_DLL void ExpandSearch(const string& key,
84 vector<Match>* result,
85 size_t limit);
87
88 RIME_DLL size_t array_size() const;
89
90 uint32_t dict_file_checksum() const;
91 uint32_t schema_file_checksum() const;
92 Darts::DoubleArray& trie() const { return *trie_; }
93
94 protected:
98 double format_ = 0.0;
99};
100
101} // namespace rime
102
103#endif // RIME_PRISM_H_
#define RIME_DLL
Definition rime_api.h:33
DoubleArrayImpl< void, void, int, void > DoubleArray
Definition darts.h:316
Definition algebra.cc:12
set< string > Syllabary
Definition vocabulary.h:17
std::unique_ptr< T > the
Definition common.h:58
int32_t SyllableId
Definition syllabifier.h:21
Definition prism.h:20
List< SpellingDescriptor > SpellingMapItem
Definition prism.h:32
Array< SpellingMapItem > SpellingMap
Definition prism.h:33
float Credibility
Definition prism.h:22
Definition algebra.h:20
Definition spelling.h:24
Definition common.h:84
Definition mapped_file.h:22
Definition mapped_file.h:53
Definition mapped_file.h:61
Definition mapped_file.h:71
const path & file_path() const
Definition mapped_file.h:121
MappedFile(const path &file_path)
Definition mapped_file.cc:46
Definition prism.h:24
Credibility credibility
Definition prism.h:28
int32_t type
Definition prism.h:27
SyllableId syllable_id
Definition prism.h:25
String tips
Definition prism.h:29
Definition prism.h:35
char format[kFormatMaxLength]
Definition prism.h:37
OffsetPtr< char > double_array
Definition prism.h:43
uint32_t num_syllables
Definition prism.h:40
static const int kFormatMaxLength
Definition prism.h:36
uint32_t num_spellings
Definition prism.h:41
OffsetPtr< SpellingMap > spelling_map
Definition prism.h:45
uint32_t schema_file_checksum
Definition prism.h:39
uint32_t dict_file_checksum
Definition prism.h:38
uint32_t double_array_size
Definition prism.h:42
char alphabet[256]
Definition prism.h:46
Definition prism.h:51
SyllableId syllable_id() const
Definition prism.cc:59
SyllableId spelling_id_
Definition prism.h:60
SpellingProperties properties() const
Definition prism.cc:66
bool exhausted() const
Definition prism.cc:55
prism::SpellingDescriptor * end_
Definition prism.h:62
SpellingAccessor(prism::SpellingMap *spelling_map, SyllableId spelling_id)
Definition prism.cc:37
bool Next()
Definition prism.cc:47
prism::SpellingDescriptor * iter_
Definition prism.h:61
uint32_t dict_file_checksum() const
Definition prism.cc:334
Darts::DoubleArray & trie() const
Definition prism.h:92
RIME_DLL void ExpandSearch(const string &key, vector< Match > *result, size_t limit)
Definition prism.cc:282
RIME_DLL size_t array_size() const
Definition prism.cc:330
RIME_DLL bool Build(const Syllabary &syllabary, const Script *script=nullptr, uint32_t dict_file_checksum=0, uint32_t schema_file_checksum=0)
Definition prism.cc:139
the< Darts::DoubleArray > trie_
Definition prism.h:95
prism::SpellingMap * spelling_map_
Definition prism.h:97
RIME_DLL bool Load()
Definition prism.cc:82
uint32_t schema_file_checksum() const
Definition prism.cc:338
Darts::DoubleArray::result_pair_type Match
Definition prism.h:69
RIME_DLL bool Save()
Definition prism.cc:131
RIME_DLL void CommonPrefixSearch(const string &key, vector< Match > *result)
Definition prism.cc:272
RIME_DLL bool HasKey(const string &key)
Definition prism.cc:256
RIME_DLL Prism(const path &file_path)
Definition prism.cc:79
SpellingAccessor QuerySpelling(SyllableId spelling_id)
Definition prism.cc:326
RIME_DLL bool GetValue(const string &key, int *value) const
Definition prism.cc:261
double format_
Definition prism.h:98
prism::Metadata * metadata_
Definition prism.h:96