diff --git a/analyzer/analyzer.go b/analyzer/analyzer.go index 679cc41..320063d 100644 --- a/analyzer/analyzer.go +++ b/analyzer/analyzer.go @@ -81,13 +81,14 @@ func New(modelPath, stopWordsPath string) (*Analyzer, error) { dictPath := filepath.Join(".", "dict") jiebaDict := filepath.Join(dictPath, "jieba.dict.utf8") hmmModel := filepath.Join(dictPath, "hmm_model.utf8") - posDict := filepath.Join(dictPath, "pos_dict.utf8") - idenDict := filepath.Join(dictPath, "iden_dict.utf8") + userDict := filepath.Join(dictPath, "user.dict.utf8") + idfPath := filepath.Join(dictPath, "idf.utf8") + stopWords := filepath.Join(dictPath, "stop_words.utf8") var j *gojieba.Jieba if _, err := os.Stat(jiebaDict); err == nil { // 词典存在,使用本地路径 - j = gojieba.NewJieba(jiebaDict, hmmModel, posDict, idenDict) + j = gojieba.NewJieba(jiebaDict, hmmModel, userDict, idfPath, stopWords) } else { // 词典不存在,使用默认路径(go module 缓存) j = gojieba.NewJieba() @@ -100,12 +101,12 @@ func New(modelPath, stopWordsPath string) (*Analyzer, error) { WithMinimumRelativeDistance(0.15). Build() - stopWords := loadStopWords(stopWordsPath) + stopWordsMap := loadStopWords(stopWordsPath) return &Analyzer{ jieba: j, detector: detector, - stopWords: stopWords, + stopWords: stopWordsMap, }, nil }