mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-08 17:40:23 +08:00
add jieba
This commit is contained in:
BIN
backend/utils/dict.zip
Normal file
BIN
backend/utils/dict.zip
Normal file
Binary file not shown.
29
backend/utils/jieba.go
Normal file
29
backend/utils/jieba.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
_ "embed"
|
||||
|
||||
"github.com/fumiama/jieba"
|
||||
)
|
||||
|
||||
//go:embed dict.zip
|
||||
var dictzip []byte
|
||||
|
||||
// Segmenter jieba 分词器
|
||||
var Segmenter = func() *jieba.Segmenter {
|
||||
r, err := zip.NewReader(bytes.NewReader(dictzip), int64(len(dictzip)))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
f, err := r.Open("dict.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
seg, err := jieba.LoadDictionary(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return seg
|
||||
}()
|
||||
Reference in New Issue
Block a user