librime: reverse_lookup_dictionary.h Source File

| librime 1.2 Rime Input Method Engine, the core library

reverse_lookup_dictionary.h
Go to the documentation of this file.
1//
2// Copyright RIME Developers
3// Distributed under the BSD License
4//
5// 2012-01-05 GONG Chen <chen.sst@gmail.com>
6// 2014-07-06 GONG Chen <chen.sst@gmail.com> redesigned binary file format.
7//
8#ifndef RIME_REVERSE_LOOKUP_DICTIONARY_H_
9#define RIME_REVERSE_LOOKUP_DICTIONARY_H_
10
11#include <stdint.h>
12#include <rime/common.h>
13#include <rime/component.h>
14#include <rime/dict/db_pool.h>
15#include <rime/dict/mapped_file.h>
16#include <rime/dict/string_table.h>
17#include <rime/dict/vocabulary.h>
18
19namespace rime {
20
21 namespace reverse {
22
23 struct Metadata {
24 static const int kFormatMaxLength = 32;
25 char format[kFormatMaxLength];
26 uint32_t dict_file_checksum;
27 String dict_settings;
28 List<StringId> index;
29 OffsetPtr<char> key_trie;
30 uint32_t key_trie_size;
31 OffsetPtr<char> value_trie;
32 uint32_t value_trie_size;
33};
34
35} // namespace reverse
36
37struct Ticket;
38class DictSettings;
39
40 class ReverseDb : public MappedFile {
41 public:
42 explicit ReverseDb(const path& file_path);
43
44 bool Load();
45 bool Lookup(const string& text, string* result);
46
47 bool Build(DictSettings* settings,
48 const Syllabary& syllabary,
49 const Vocabulary& vocabulary,
50 const ReverseLookupTable& stems,
51 uint32_t dict_file_checksum);
52 bool Save();
53
54 uint32_t dict_file_checksum() const;
55 reverse::Metadata* metadata() const { return metadata_; }
56
57 private:
58 reverse::Metadata* metadata_ = nullptr;
59 the<StringTable> key_trie_;
60 the<StringTable> value_trie_;
61};
62
63 class ReverseLookupDictionary
64 : public Class<ReverseLookupDictionary, const Ticket&> {
65 public:
66 explicit ReverseLookupDictionary(an<ReverseDb> db);
67 bool Load();
68 bool ReverseLookup(const string& text, string* result);
69 bool LookupStems(const string& text, string* result);
70 an<DictSettings> GetDictSettings();
71
72 protected:
73 an<ReverseDb> db_;
74};
75
76class ResourceResolver;
77
78 class ReverseLookupDictionaryComponent
79 : public ReverseLookupDictionary::Component,
80 protected DbPool<ReverseDb> {
81 public:
82 ReverseLookupDictionaryComponent();
83 ReverseLookupDictionary* Create(const Ticket& ticket);
84 ReverseLookupDictionary* Create(const string& dict_name);
85};
86
87} // namespace rime
88
89#endif // RIME_REVERSE_LOOKUP_DICTIONARY_H_
common.h
component.h
mapped_file.h
string_table.h
vocabulary.h
db_pool.h
rime
Definition algebra.cc:12
rime::an
std::shared_ptr< T > an
Definition common.h:60
rime::Syllabary
set< string > Syllabary
Definition vocabulary.h:17
rime::the
std::unique_ptr< T > the
Definition common.h:58
rime::ReverseLookupTable
hash_map< string, set< string > > ReverseLookupTable
Definition vocabulary.h:107
rime::reverse
Definition reverse_lookup_dictionary.h:21
rime::path
Definition common.h:84
rime::Class
Definition component.h:21
rime::DbPool< ReverseDb >::DbPool
DbPool(the< ResourceResolver > resource_resolver)
Definition db_pool_impl.h:10
rime::DictSettings
Definition dict_settings.h:16
rime::OffsetPtr
Definition mapped_file.h:22
rime::String
Definition mapped_file.h:53
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::reverse::Metadata
Definition reverse_lookup_dictionary.h:23
rime::reverse::Metadata::kFormatMaxLength
static const int kFormatMaxLength
Definition reverse_lookup_dictionary.h:24
rime::reverse::Metadata::key_trie
OffsetPtr< char > key_trie
Definition reverse_lookup_dictionary.h:29
rime::reverse::Metadata::dict_settings
String dict_settings
Definition reverse_lookup_dictionary.h:27
rime::reverse::Metadata::value_trie_size
uint32_t value_trie_size
Definition reverse_lookup_dictionary.h:32
rime::reverse::Metadata::key_trie_size
uint32_t key_trie_size
Definition reverse_lookup_dictionary.h:30
rime::reverse::Metadata::value_trie
OffsetPtr< char > value_trie
Definition reverse_lookup_dictionary.h:31
rime::reverse::Metadata::format
char format[kFormatMaxLength]
Definition reverse_lookup_dictionary.h:25
rime::reverse::Metadata::dict_file_checksum
uint32_t dict_file_checksum
Definition reverse_lookup_dictionary.h:26
rime::reverse::Metadata::index
List< StringId > index
Definition reverse_lookup_dictionary.h:28
rime::ReverseDb::Load
bool Load()
Definition reverse_lookup_dictionary.cc:32
rime::ReverseDb::metadata
reverse::Metadata * metadata() const
Definition reverse_lookup_dictionary.h:55
rime::ReverseDb::Lookup
bool Lookup(const string &text, string *result)
Definition reverse_lookup_dictionary.cc:71
rime::ReverseDb::dict_file_checksum
uint32_t dict_file_checksum() const
Definition reverse_lookup_dictionary.cc:201
rime::ReverseDb::ReverseDb
ReverseDb(const path &file_path)
Definition reverse_lookup_dictionary.cc:30
rime::ReverseDb::Save
bool Save()
Definition reverse_lookup_dictionary.cc:196
rime::ReverseDb::Build
bool Build(DictSettings *settings, const Syllabary &syllabary, const Vocabulary &vocabulary, const ReverseLookupTable &stems, uint32_t dict_file_checksum)
Definition reverse_lookup_dictionary.cc:84
rime::ReverseLookupDictionary
Definition reverse_lookup_dictionary.h:64
rime::ReverseLookupDictionary::ReverseLookup
bool ReverseLookup(const string &text, string *result)
Definition reverse_lookup_dictionary.cc:211
rime::ReverseLookupDictionary::ReverseLookupDictionary
ReverseLookupDictionary(an< ReverseDb > db)
Definition reverse_lookup_dictionary.cc:205
rime::ReverseLookupDictionary::db_
an< ReverseDb > db_
Definition reverse_lookup_dictionary.h:73
rime::ReverseLookupDictionary::LookupStems
bool LookupStems(const string &text, string *result)
Definition reverse_lookup_dictionary.cc:216
rime::ReverseLookupDictionary::Load
bool Load()
Definition reverse_lookup_dictionary.cc:207
rime::ReverseLookupDictionary::GetDictSettings
an< DictSettings > GetDictSettings()
Definition reverse_lookup_dictionary.cc:220
rime::ReverseLookupDictionaryComponent::ReverseLookupDictionaryComponent
ReverseLookupDictionaryComponent()
Definition reverse_lookup_dictionary.cc:237
rime::ReverseLookupDictionaryComponent::Create
ReverseLookupDictionary * Create(const Ticket &ticket)
Definition reverse_lookup_dictionary.cc:248
rime::Vocabulary
Definition vocabulary.h:100
rime::ResourceResolver
Definition resource.h:22
rime::Ticket
Definition ticket.h:17