@@ -60,10 +60,10 @@ namespace CppJieba
6060 _minWeight = MAX_DOUBLE;
6161 _setInitFlag (false );
6262 }
63- DictTrie (const string& filePath )
63+ DictTrie (const string& dictPath, const string& userDictPath = " " )
6464 {
6565 new (this ) DictTrie ();
66- _setInitFlag (init (filePath ));
66+ _setInitFlag (init (dictPath, userDictPath ));
6767 }
6868 ~DictTrie ()
6969 {
@@ -80,9 +80,12 @@ namespace CppJieba
8080 _loadDict (dictPath, _nodeInfos);
8181 _calculateWeight (_nodeInfos);
8282 _minWeight = _findMinWeight (_nodeInfos);
83+
8384 if (userDictPath.size ())
8485 {
85- _loadUserDict (dictPath, _minWeight, UNKNOWN_TAG, _nodeInfos);
86+ double maxWeight = _findMaxWeight (_nodeInfos);
87+ _loadUserDict (userDictPath, maxWeight, UNKNOWN_TAG, _nodeInfos);
88+ LogDebug (" load userdict[%s] ok." , userDictPath.c_str ());
8689 }
8790 _shrink (_nodeInfos);
8891 _trie = _creatTrie (_nodeInfos);
@@ -167,6 +170,15 @@ namespace CppJieba
167170 }
168171 return ret;
169172 }
173+ double _findMaxWeight (const vector<DictUnit>& nodeInfos) const
174+ {
175+ double ret = MIN_DOUBLE;
176+ for (size_t i = 0 ; i < nodeInfos.size (); i++)
177+ {
178+ ret = max (nodeInfos[i].weight , ret);
179+ }
180+ return ret;
181+ }
170182
171183 void _calculateWeight (vector<DictUnit>& nodeInfos) const
172184 {
0 commit comments