forked from go-ego/gse
/
main.go
55 lines (43 loc) · 1.15 KB
/
main.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
package main
import (
"fmt"
"github.com/go-ego/gse"
)
var (
text = "旧金山湾金门大桥"
new = gse.New("zh,../../testdata/test_dict.txt")
seg gse.Segmenter
)
func main() {
cut()
// LoadDict()
LoadDictEmbed()
segment()
}
func LoadDictEmbed() {
seg.LoadDictEmbed()
seg.LoadStopEmbed()
}
func LoadDict() {
// var seg gse.Segmenter
seg.LoadDict("zh,../../testdata/test_dict.txt,../../testdata/test_dict1.txt")
seg.LoadStop()
}
func cut() {
fmt.Println("cut: ", new.Cut(text, true))
fmt.Println("cut all: ", new.CutAll(text))
fmt.Println("cut for search: ", new.CutSearch(text, true))
}
func segment() {
text1 := []byte(text)
fmt.Println(seg.String(text, true))
// 金山/nr 旧金山/ns 湾/zg 旧金山湾/ns 金门/n 大桥/ns 金门大桥/nz
segments := seg.Segment(text1)
// fmt.Println(gse.ToString(segments, false))
fmt.Println(gse.ToString(segments))
//"旧金山湾/n 金门大桥/nz "
// 搜索模式主要用于给搜索引擎提供尽可能多的关键字
segs := seg.ModeSegment(text1, true)
fmt.Println(gse.ToString(segs, true))
// "金山/nr 旧金山/ns 湾/zg 旧金山湾/ns 金门/n 大桥/ns 金门大桥/nz "
}