File tree 6 files changed +21
-13
lines changed
6 files changed +21
-13
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ bool DictCompiler::Compile(const string &schema_file) {
76
76
cc.ProcessFile (file_name);
77
77
}
78
78
if (settings.use_preset_vocabulary ()) {
79
- cc.ProcessFile (PresetVocabulary::DictFilePath ());
79
+ cc.ProcessFile (PresetVocabulary::DictFilePath (settings. vocabulary () ));
80
80
}
81
81
dict_file_checksum = cc.Checksum ();
82
82
}
Original file line number Diff line number Diff line change @@ -50,7 +50,15 @@ string DictSettings::sort_order() {
50
50
}
51
51
52
52
bool DictSettings::use_preset_vocabulary () {
53
- return (*this )[" use_preset_vocabulary" ].ToBool ();
53
+ return (*this )[" use_preset_vocabulary" ].ToBool () ||
54
+ (*this )[" vocabulary" ].IsValue ();
55
+ }
56
+
57
+ static const string kDefaultVocabulary = " essay" ;
58
+
59
+ string DictSettings::vocabulary () {
60
+ string value = (*this )[" vocabulary" ].ToString ();
61
+ return !value.empty () ? value : kDefaultVocabulary ;
54
62
}
55
63
56
64
bool DictSettings::use_rule_based_encoder () {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class DictSettings : public Config {
21
21
string dict_version ();
22
22
string sort_order ();
23
23
bool use_preset_vocabulary ();
24
+ string vocabulary ();
24
25
bool use_rule_based_encoder ();
25
26
int max_phrase_length ();
26
27
double min_phrase_weight ();
Original file line number Diff line number Diff line change @@ -41,9 +41,10 @@ void EntryCollector::Collect(const vector<string>& dict_files) {
41
41
}
42
42
43
43
void EntryCollector::LoadPresetVocabulary (DictSettings* settings) {
44
- LOG (INFO) << " loading preset vocabulary." ;
45
- preset_vocabulary.reset (new PresetVocabulary);
46
- if (preset_vocabulary && settings) {
44
+ auto vocabulary = settings->vocabulary ();
45
+ LOG (INFO) << " loading preset vocabulary: " << vocabulary;
46
+ preset_vocabulary.reset (new PresetVocabulary (vocabulary));
47
+ if (preset_vocabulary) {
47
48
if (settings->max_phrase_length () > 0 )
48
49
preset_vocabulary->set_max_phrase_length (settings->max_phrase_length ());
49
50
if (settings->min_phrase_weight () > 0 )
Original file line number Diff line number Diff line change @@ -18,8 +18,6 @@ static const ResourceType kVocabularyResourceType = {
18
18
" vocabulary" , " " , " .txt"
19
19
};
20
20
21
- static const string kDefaultVocabulary = " essay" ;
22
-
23
21
struct VocabularyDb : public TextDb {
24
22
explicit VocabularyDb (const string& path);
25
23
an<DbAccessor> cursor;
@@ -56,14 +54,14 @@ const TextFormat VocabularyDb::format = {
56
54
" Rime vocabulary" ,
57
55
};
58
56
59
- string PresetVocabulary::DictFilePath () {
57
+ string PresetVocabulary::DictFilePath (const string& vocabulary ) {
60
58
the<ResourceResolver> resource_resolver (
61
59
Service::instance ().CreateResourceResolver (kVocabularyResourceType ));
62
- return resource_resolver->ResolvePath (kDefaultVocabulary ).string ();
60
+ return resource_resolver->ResolvePath (vocabulary ).string ();
63
61
}
64
62
65
- PresetVocabulary::PresetVocabulary () {
66
- db_.reset (new VocabularyDb (DictFilePath ()));
63
+ PresetVocabulary::PresetVocabulary (const string& vocabulary ) {
64
+ db_.reset (new VocabularyDb (DictFilePath (vocabulary )));
67
65
if (db_ && db_->OpenReadOnly ()) {
68
66
db_->cursor = db_->QueryAll ();
69
67
}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ struct VocabularyDb;
15
15
16
16
class PresetVocabulary {
17
17
public:
18
- PresetVocabulary ();
18
+ explicit PresetVocabulary (const string& vocabulary );
19
19
~PresetVocabulary ();
20
20
21
21
// random access
@@ -29,7 +29,7 @@ class PresetVocabulary {
29
29
void set_max_phrase_length (int length) { max_phrase_length_ = length; }
30
30
void set_min_phrase_weight (double weight) { min_phrase_weight_ = weight; }
31
31
32
- static string DictFilePath ();
32
+ static string DictFilePath (const string& vacabulary );
33
33
34
34
protected:
35
35
the<VocabularyDb> db_;
You can’t perform that action at this time.
0 commit comments