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>
18
19namespace rime {
20
21namespace reverse {
22
23struct Metadata {
24 static const int kFormatMaxLength = 32;
30 uint32_t key_trie_size;
33};
34
35} // namespace reverse
36
37struct Ticket;
38class DictSettings;
39
40class 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
64 : public Class<ReverseLookupDictionary, const Ticket&> {
65 public:
67 bool Load();
68 bool ReverseLookup(const string& text, string* result);
69 bool LookupStems(const string& text, string* result);
71
72 protected:
74};
75
77
79 : public ReverseLookupDictionary::Component,
80 protected DbPool<ReverseDb> {
81 public:
84 ReverseLookupDictionary* Create(const string& dict_name);
85};
86
87} // namespace rime
88
89#endif // RIME_REVERSE_LOOKUP_DICTIONARY_H_
Definition algebra.cc:12
std::shared_ptr< T > an
Definition common.h:60
set< string > Syllabary
Definition vocabulary.h:17
std::unique_ptr< T > the
Definition common.h:58
hash_map< string, set< string > > ReverseLookupTable
Definition vocabulary.h:107
Definition reverse_lookup_dictionary.h:21
Definition common.h:84
Definition component.h:21
DbPool(the< ResourceResolver > resource_resolver)
Definition db_pool_impl.h:10
Definition dict_settings.h:16
Definition mapped_file.h:22
Definition mapped_file.h:53
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 reverse_lookup_dictionary.h:23
static const int kFormatMaxLength
Definition reverse_lookup_dictionary.h:24
OffsetPtr< char > key_trie
Definition reverse_lookup_dictionary.h:29
String dict_settings
Definition reverse_lookup_dictionary.h:27
uint32_t value_trie_size
Definition reverse_lookup_dictionary.h:32
uint32_t key_trie_size
Definition reverse_lookup_dictionary.h:30
OffsetPtr< char > value_trie
Definition reverse_lookup_dictionary.h:31
char format[kFormatMaxLength]
Definition reverse_lookup_dictionary.h:25
uint32_t dict_file_checksum
Definition reverse_lookup_dictionary.h:26
List< StringId > index
Definition reverse_lookup_dictionary.h:28
bool Load()
Definition reverse_lookup_dictionary.cc:32
reverse::Metadata * metadata() const
Definition reverse_lookup_dictionary.h:55
bool Lookup(const string &text, string *result)
Definition reverse_lookup_dictionary.cc:71
uint32_t dict_file_checksum() const
Definition reverse_lookup_dictionary.cc:201
ReverseDb(const path &file_path)
Definition reverse_lookup_dictionary.cc:30
bool Save()
Definition reverse_lookup_dictionary.cc:196
bool Build(DictSettings *settings, const Syllabary &syllabary, const Vocabulary &vocabulary, const ReverseLookupTable &stems, uint32_t dict_file_checksum)
Definition reverse_lookup_dictionary.cc:84
Definition reverse_lookup_dictionary.h:64
bool ReverseLookup(const string &text, string *result)
Definition reverse_lookup_dictionary.cc:211
ReverseLookupDictionary(an< ReverseDb > db)
Definition reverse_lookup_dictionary.cc:205
an< ReverseDb > db_
Definition reverse_lookup_dictionary.h:73
bool LookupStems(const string &text, string *result)
Definition reverse_lookup_dictionary.cc:216
bool Load()
Definition reverse_lookup_dictionary.cc:207
an< DictSettings > GetDictSettings()
Definition reverse_lookup_dictionary.cc:220
ReverseLookupDictionaryComponent()
Definition reverse_lookup_dictionary.cc:237
ReverseLookupDictionary * Create(const Ticket &ticket)
Definition reverse_lookup_dictionary.cc:248
Definition vocabulary.h:100
Definition resource.h:22
Definition ticket.h:17