From c90c58ae05ba7ec3f78965b42820698a876cb948 Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 12 Apr 2026 04:38:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=9C=AC=E5=9C=B0=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analyzer/analyzer.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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 }