// // Copyright RIME Developers // Distributed under the BSD License // // 2012-01-05 GONG Chen // 2014-07-06 GONG Chen redesigned binary file format. // #ifndef RIME_REVERSE_LOOKUP_DICTIONARY_H_ #define RIME_REVERSE_LOOKUP_DICTIONARY_H_ #include #include #include #include #include #include #include namespace rime { namespace reverse { struct Metadata { static const int kFormatMaxLength = 32; char format[kFormatMaxLength]; uint32_t dict_file_checksum; String dict_settings; List index; OffsetPtr key_trie; uint32_t key_trie_size; OffsetPtr value_trie; uint32_t value_trie_size; }; } // namespace reverse struct Ticket; class DictSettings; class ReverseDb : public MappedFile { public: explicit ReverseDb(const path& file_path); 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 key_trie_; the value_trie_; }; class ReverseLookupDictionary : public Class { public: explicit ReverseLookupDictionary(an db); bool Load(); bool ReverseLookup(const string& text, string* result); bool LookupStems(const string& text, string* result); an GetDictSettings(); protected: an db_; }; class ResourceResolver; class ReverseLookupDictionaryComponent : public ReverseLookupDictionary::Component, protected DbPool { public: ReverseLookupDictionaryComponent(); ReverseLookupDictionary* Create(const Ticket& ticket); ReverseLookupDictionary* Create(const string& dict_name); }; } // namespace rime #endif // RIME_REVERSE_LOOKUP_DICTIONARY_H_