fix: support custom jieba dictionary directory
This commit is contained in:
@@ -2,13 +2,30 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/yanyiwu/gojieba"
|
"github.com/yanyiwu/gojieba"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Jieba is a global instance of Chinese text segmentation tool
|
// 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
|
// EvaluationStatue represents the status of an evaluation task
|
||||||
type EvaluationStatue int
|
type EvaluationStatue int
|
||||||
|
|||||||
Reference in New Issue
Block a user