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