librime: prism.h Source File

| 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>
15#include <rime/dict/mapped_file.h>
16#include <rime/dict/vocabulary.h>
17
18namespace rime {
19
20 namespace prism {
21
22 using Credibility = float;
23
24 struct SpellingDescriptor {
25 SyllableId syllable_id;
26 // bit 30: is_correction
27 int32_t type;
28 Credibility credibility;
29 String tips;
30};
31
32 using SpellingMapItem = List<SpellingDescriptor>;
33 using SpellingMap = Array<SpellingMapItem>;
34
35 struct Metadata {
36 static const int kFormatMaxLength = 32;
37 char format[kFormatMaxLength];
38 uint32_t dict_file_checksum;
39 uint32_t schema_file_checksum;
40 uint32_t num_syllables;
41 uint32_t num_spellings;
42 uint32_t double_array_size;
43 OffsetPtr<char> double_array;
44 // v1.0
45 OffsetPtr<SpellingMap> spelling_map;
46 char alphabet[256];
47};
48
49} // namespace prism
50
51 class SpellingAccessor {
52 public:
53 SpellingAccessor(prism::SpellingMap* spelling_map, SyllableId spelling_id);
54 bool Next();
55 bool exhausted() const;
56 SyllableId syllable_id() const;
57 SpellingProperties properties() const;
58
59 protected:
60 SyllableId spelling_id_;
61 prism::SpellingDescriptor* iter_;
62 prism::SpellingDescriptor* end_;
63};
64
65class Script;
66
67 class 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);
86 SpellingAccessor QuerySpelling(SyllableId spelling_id);
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:
95 the<Darts::DoubleArray> trie_;
96 prism::Metadata* metadata_ = nullptr;
97 prism::SpellingMap* spelling_map_ = nullptr;
98 double format_ = 0.0;
99};
100
101} // namespace rime
102
103#endif // RIME_PRISM_H_
darts.h
spelling.h
common.h
mapped_file.h
vocabulary.h
RIME_DLL
#define RIME_DLL
Definition rime_api.h:33
Darts::DoubleArray
DoubleArrayImpl< void, void, int, void > DoubleArray
Definition darts.h:316
rime
Definition algebra.cc:12
rime::Syllabary
set< string > Syllabary
Definition vocabulary.h:17
rime::the
std::unique_ptr< T > the
Definition common.h:58
rime::SyllableId
int32_t SyllableId
Definition syllabifier.h:21
rime::prism
Definition prism.h:20
rime::prism::SpellingMapItem
List< SpellingDescriptor > SpellingMapItem
Definition prism.h:32
rime::prism::SpellingMap
Array< SpellingMapItem > SpellingMap
Definition prism.h:33
rime::prism::Credibility
float Credibility
Definition prism.h:22
rime::Script
Definition algebra.h:20
rime::SpellingProperties
Definition spelling.h:24
rime::path
Definition common.h:84
rime::OffsetPtr
Definition mapped_file.h:22
rime::String
Definition mapped_file.h:53
rime::Array
Definition mapped_file.h:61
rime::List
Definition mapped_file.h:71
rime::MappedFile::file_path
const path & file_path() const
Definition mapped_file.h:121
rime::MappedFile::MappedFile
MappedFile(const path &file_path)
Definition mapped_file.cc:46
rime::prism::SpellingDescriptor
Definition prism.h:24
rime::prism::SpellingDescriptor::credibility
Credibility credibility
Definition prism.h:28
rime::prism::SpellingDescriptor::type
int32_t type
Definition prism.h:27
rime::prism::SpellingDescriptor::syllable_id
SyllableId syllable_id
Definition prism.h:25
rime::prism::SpellingDescriptor::tips
String tips
Definition prism.h:29
rime::prism::Metadata
Definition prism.h:35
rime::prism::Metadata::format
char format[kFormatMaxLength]
Definition prism.h:37
rime::prism::Metadata::double_array
OffsetPtr< char > double_array
Definition prism.h:43
rime::prism::Metadata::num_syllables
uint32_t num_syllables
Definition prism.h:40
rime::prism::Metadata::kFormatMaxLength
static const int kFormatMaxLength
Definition prism.h:36
rime::prism::Metadata::num_spellings
uint32_t num_spellings
Definition prism.h:41
rime::prism::Metadata::spelling_map
OffsetPtr< SpellingMap > spelling_map
Definition prism.h:45
rime::prism::Metadata::schema_file_checksum
uint32_t schema_file_checksum
Definition prism.h:39
rime::prism::Metadata::dict_file_checksum
uint32_t dict_file_checksum
Definition prism.h:38
rime::prism::Metadata::double_array_size
uint32_t double_array_size
Definition prism.h:42
rime::prism::Metadata::alphabet
char alphabet[256]
Definition prism.h:46
rime::SpellingAccessor
Definition prism.h:51
rime::SpellingAccessor::syllable_id
SyllableId syllable_id() const
Definition prism.cc:59
rime::SpellingAccessor::spelling_id_
SyllableId spelling_id_
Definition prism.h:60
rime::SpellingAccessor::properties
SpellingProperties properties() const
Definition prism.cc:66
rime::SpellingAccessor::exhausted
bool exhausted() const
Definition prism.cc:55
rime::SpellingAccessor::end_
prism::SpellingDescriptor * end_
Definition prism.h:62
rime::SpellingAccessor::SpellingAccessor
SpellingAccessor(prism::SpellingMap *spelling_map, SyllableId spelling_id)
Definition prism.cc:37
rime::SpellingAccessor::Next
bool Next()
Definition prism.cc:47
rime::SpellingAccessor::iter_
prism::SpellingDescriptor * iter_
Definition prism.h:61
rime::Prism::dict_file_checksum
uint32_t dict_file_checksum() const
Definition prism.cc:334
rime::Prism::trie
Darts::DoubleArray & trie() const
Definition prism.h:92
rime::Prism::ExpandSearch
RIME_DLL void ExpandSearch(const string &key, vector< Match > *result, size_t limit)
Definition prism.cc:282
rime::Prism::array_size
RIME_DLL size_t array_size() const
Definition prism.cc:330
rime::Prism::Build
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
rime::Prism::trie_
the< Darts::DoubleArray > trie_
Definition prism.h:95
rime::Prism::spelling_map_
prism::SpellingMap * spelling_map_
Definition prism.h:97
rime::Prism::Load
RIME_DLL bool Load()
Definition prism.cc:82
rime::Prism::schema_file_checksum
uint32_t schema_file_checksum() const
Definition prism.cc:338
rime::Prism::Match
Darts::DoubleArray::result_pair_type Match
Definition prism.h:69
rime::Prism::Save
RIME_DLL bool Save()
Definition prism.cc:131
rime::Prism::CommonPrefixSearch
RIME_DLL void CommonPrefixSearch(const string &key, vector< Match > *result)
Definition prism.cc:272
rime::Prism::HasKey
RIME_DLL bool HasKey(const string &key)
Definition prism.cc:256
rime::Prism::Prism
RIME_DLL Prism(const path &file_path)
Definition prism.cc:79
rime::Prism::QuerySpelling
SpellingAccessor QuerySpelling(SyllableId spelling_id)
Definition prism.cc:326
rime::Prism::GetValue
RIME_DLL bool GetValue(const string &key, int *value) const
Definition prism.cc:261
rime::Prism::format_
double format_
Definition prism.h:98
rime::Prism::metadata_
prism::Metadata * metadata_
Definition prism.h:96