File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ bool DictCompiler::Compile(const string &schema_file) {
7676 cc.ProcessFile (file_name);
7777 }
7878 if (settings.use_preset_vocabulary ()) {
79- cc.ProcessFile (PresetVocabulary::DictFilePath ());
79+ cc.ProcessFile (PresetVocabulary::DictFilePath (settings. vocabulary () ));
8080 }
8181 dict_file_checksum = cc.Checksum ();
8282 }
Original file line number Diff line number Diff line change @@ -50,7 +50,15 @@ string DictSettings::sort_order() {
5050}
5151
5252bool 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 ;
5462}
5563
5664bool DictSettings::use_rule_based_encoder () {
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class DictSettings : public Config {
2121 string dict_version ();
2222 string sort_order ();
2323 bool use_preset_vocabulary ();
24+ string vocabulary ();
2425 bool use_rule_based_encoder ();
2526 int max_phrase_length ();
2627 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) {
4141}
4242
4343void 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) {
4748 if (settings->max_phrase_length () > 0 )
4849 preset_vocabulary->set_max_phrase_length (settings->max_phrase_length ());
4950 if (settings->min_phrase_weight () > 0 )
Original file line number Diff line number Diff line change @@ -18,8 +18,6 @@ static const ResourceType kVocabularyResourceType = {
1818 " vocabulary" , " " , " .txt"
1919};
2020
21- static const string kDefaultVocabulary = " essay" ;
22-
2321struct VocabularyDb : public TextDb {
2422 explicit VocabularyDb (const string& path);
2523 an<DbAccessor> cursor;
@@ -56,14 +54,14 @@ const TextFormat VocabularyDb::format = {
5654 " Rime vocabulary" ,
5755};
5856
59- string PresetVocabulary::DictFilePath () {
57+ string PresetVocabulary::DictFilePath (const string& vocabulary ) {
6058 the<ResourceResolver> resource_resolver (
6159 Service::instance ().CreateResourceResolver (kVocabularyResourceType ));
62- return resource_resolver->ResolvePath (kDefaultVocabulary ).string ();
60+ return resource_resolver->ResolvePath (vocabulary ).string ();
6361}
6462
65- PresetVocabulary::PresetVocabulary () {
66- db_.reset (new VocabularyDb (DictFilePath ()));
63+ PresetVocabulary::PresetVocabulary (const string& vocabulary ) {
64+ db_.reset (new VocabularyDb (DictFilePath (vocabulary )));
6765 if (db_ && db_->OpenReadOnly ()) {
6866 db_->cursor = db_->QueryAll ();
6967 }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ struct VocabularyDb;
1515
1616class PresetVocabulary {
1717 public:
18- PresetVocabulary ();
18+ explicit PresetVocabulary (const string& vocabulary );
1919 ~PresetVocabulary ();
2020
2121 // random access
@@ -29,7 +29,7 @@ class PresetVocabulary {
2929 void set_max_phrase_length (int length) { max_phrase_length_ = length; }
3030 void set_min_phrase_weight (double weight) { min_phrase_weight_ = weight; }
3131
32- static string DictFilePath ();
32+ static string DictFilePath (const string& vacabulary );
3333
3434 protected:
3535 the<VocabularyDb> db_;
You can’t perform that action at this time.
0 commit comments