-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinit.go
57 lines (50 loc) · 1.08 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package jiagu
import (
"compress/gzip"
"embed"
"fmt"
"github.com/bububa/jiagu/perceptron"
)
const (
// POS_MODEL 词性标注model文件
POS_MODEL = "pos.model"
// NER_MODEL 命名实体识别model文件
NER_MODEL = "ner.model"
// KG_MODEL 知识图谱model文件
KG_MODEL = "kg.model"
// CWS_MODEL 分词model文件
CWS_MODEL = "cws.model"
// SENTIMENT_MODEL 情感分析model文件
SENTIMENT_MODEL = "sentiment.model"
// VOCAB_DICT 分词字典
VOCAB_DICT = "jiagu.dict"
// STOPWORDS stopwords字典
STOPWORDS_DICT = "stopwords.txt"
)
//go:embed model/*
var modelFS embed.FS
//go:embed dict/*
var dictFS embed.FS
func initPerceptron(modelFile string) (*perceptron.Perceptron, error) {
fd, err := modelFS.Open(fmt.Sprintf("model/%s", modelFile))
if err != nil {
return nil, err
}
defer fd.Close()
gr, err := gzip.NewReader(fd)
if err != nil {
return nil, err
}
defer gr.Close()
return perceptron.NewFromReader(gr)
}
func Init() {
NerModel()
PosModel()
Stopwords()
Segment()
KeywordsInstance()
SummarizeInstance()
KnowledgeInstance()
SentimentInstance()
}