-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmmseg_test.go
75 lines (59 loc) · 1.5 KB
/
mmseg_test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package gommseg
import "testing"
func TestSegmentGetWord(t *testing.T) {
text := "你好"
_, ok := Ana.Get(text)
if !ok {
t.Errorf("shit happen\n")
}
}
func TestSegmentWord(t *testing.T) {
text := "你好"
word, _ := Ana.Get(text)
if word.Text != text {
t.Errorf("expected %s, got %s", text, word.Text)
}
if word.Freq != 974 {
t.Errorf("word freq should be 974, got %d", word.Freq)
}
}
func TestSegmentMatchWordsLength(t *testing.T) {
text := "希望找到一个能发挥你能力的地方?"
// text := []byte("你好吗")
words := Ana.MatchWords(text)
if len(words) != 2 {
t.Errorf("words length should be 2, got %d, got %v", len(words), words)
}
}
func TestSegmentMatchWords(t *testing.T) {
text := "希望找到一个能发挥你能力的地方?"
words := Ana.MatchWords(text)
if words[0].Text != "希" {
t.Errorf("match word error")
}
}
func TestSegmentChunks(t *testing.T) {
text := "南京市长江大桥欢迎你"
chunks := Ana.Chunks(text)
if len(chunks) != 16 {
t.Errorf("expected 2, got %d", len(chunks))
}
}
func TestSegmentChunksFilter(t *testing.T) {
text := "南京市长江大桥欢迎你"
chunks := Ana.Chunks(text)
chunk := Ana.Filter(chunks)
if chunk.Words[0].Text != "南京市" && chunk.Length() != 27 {
t.Errorf("filter fail")
}
}
func TestSegmentCut(t *testing.T) {
text := "我们在野生动物园玩"
Ana.Cut(text)
}
func BenchmarkSegment(b *testing.B) {
text := "南京市长江大桥欢迎你"
for n := 0; n < b.N; n++ {
Ana.Cut(text)
}
}