使用本地表

This commit is contained in:
2026-04-12 04:38:28 +08:00
parent 04bba673de
commit c90c58ae05
+6 -5
View File
@@ -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
}