mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-09-21 05:43:43 +08:00
fix: support custom jieba dictionary directory
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user