// // Copyright RIME Developers // Distributed under the BSD License // // 2011-11-27 GONG Chen // #ifndef RIME_ENTRY_COLLECTOR_H_ #define RIME_ENTRY_COLLECTOR_H_ #include #include #include #include #include namespace rime { struct RawDictEntry { RawCode raw_code; string text; double weight; }; // code -> weight using WeightMap = map; // word -> [ { code, weight } ] // For the sake of memory usage, don't use word -> { code -> weight } as there // may be many words, but may not be many representations for a word using WordMap = hash_map>>; // [ (word, weight), ... ] using EncodeQueue = std::queue>; class PresetVocabulary; class DictSettings; class EntryCollector : public PhraseCollector { public: Syllabary syllabary; bool build_syllabary = true; vector> entries; size_t num_entries = 0; ReverseLookupTable stems; public: EntryCollector(); explicit EntryCollector(Syllabary&& fixed_syllabary); virtual ~EntryCollector(); void Configure(DictSettings* settings); void Collect(const vector& dict_files); // export contents of table and prism to text files void Dump(const path& file_path) const; void CreateEntry(const string& word, const string& code_str, const string& weight_str); bool TranslateWord(const string& word, vector* code); protected: void LoadPresetVocabulary(DictSettings* settings); // call Collect() multiple times for all required tables void Collect(const path& dict_file); // encode all collected entries void Finish(); protected: the preset_vocabulary; the encoder; EncodeQueue encode_queue; set collection; WordMap words; WeightMap total_weight; private: string current_dict_file; size_t line_number; }; } // namespace rime #endif // RIME_ENTRY_COLLECTOR_H_