1
0
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:
源文雨
2023-03-30 23:26:37 +08:00
parent 05e59426cd
commit 0ad433e9ce
5 changed files with 172 additions and 11 deletions

BIN
backend/utils/dict.zip Normal file

Binary file not shown.

29
backend/utils/jieba.go Normal file
View 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
}()