fix: support custom jieba dictionary directory

This commit is contained in:
langcaiye
2026-06-08 20:10:37 +08:00
committed by lyingbug
parent 99f35f8dea
commit 521a663b0c
+18 -1
View File
@@ -2,13 +2,30 @@ package types
import (
"encoding/json"
"os"
"path/filepath"
"time"
"github.com/yanyiwu/gojieba"
)
// Jieba is a global instance of Chinese text segmentation tool
var Jieba *gojieba.Jieba = gojieba.NewJieba()
var Jieba *gojieba.Jieba = newJieba()
func newJieba() *gojieba.Jieba {
dictDir := os.Getenv("JIEBA_DICT_DIR")
if dictDir == "" {
return gojieba.NewJieba()
}
return gojieba.NewJieba(
filepath.Join(dictDir, "jieba.dict.utf8"),
filepath.Join(dictDir, "hmm_model.utf8"),
filepath.Join(dictDir, "user.dict.utf8"),
filepath.Join(dictDir, "idf.utf8"),
filepath.Join(dictDir, "stop_words.utf8"),
)
}
// EvaluationStatue represents the status of an evaluation task
type EvaluationStatue int