1 //
2 // Copyright RIME Developers
3 // Distributed under the BSD License
4 //
5 // 2011-11-27 GONG Chen <chen.sst@gmail.com>
6 //
7 #ifndef PRESET_VOCABULARY_H_
8 #define PRESET_VOCABULARY_H_
9 
10 #include <rime/common.h>
11 
12 namespace rime {
13 
14 struct VocabularyDb;
15 
16 class PresetVocabulary {
17  public:
18   explicit PresetVocabulary(const string& vocabulary);
19   ~PresetVocabulary();
20 
21   // random access
22   bool GetWeightForEntry(const string& key, double* weight);
23   // traversing
24   void Reset();
25   bool GetNextEntry(string* key, string* value);
26   bool IsQualifiedPhrase(const string& phrase,
27                          const string& weight_str);
28 
set_max_phrase_length(int length)29   void set_max_phrase_length(int length) { max_phrase_length_ = length; }
set_min_phrase_weight(double weight)30   void set_min_phrase_weight(double weight) { min_phrase_weight_ = weight; }
31 
32   static string DictFilePath(const string& vacabulary);
33 
34  protected:
35   the<VocabularyDb> db_;
36   int max_phrase_length_ = 0;
37   double min_phrase_weight_ = 0.0;
38 };
39 
40 }  // namespace rime
41 
42 #endif  // PRESET_VOCABULARY_H_
43