-
Notifications
You must be signed in to change notification settings - Fork 7
/
maximum_matching_test.go
68 lines (56 loc) · 1.74 KB
/
maximum_matching_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
package gotokenizer
import (
"reflect"
"strings"
"testing"
)
var (
expectedForForwardMaxMatch = "中华人民共和国/万岁/万岁/万万岁"
mm = NewMaxMatch(dictZhPath)
)
func TestMaxMatch_Get_With_mixtureText(t *testing.T) {
expectedResult := "gotokenizer/是/一款/基于/字典/和/Bigram/模型/纯/go/语言/编写/的/分词器/,/支持/6/种/分词/算法/。/支持/stopToken/过滤/和/自定义/word/过滤/功能/。"
mm.LoadDict()
result, err := mm.Get(mixtureText)
checkErr(err, t)
reality := strings.Join(result, "/")
if reality != expectedResult {
t.Errorf(errorFormat,
reality, expectedResult)
}
}
func TestMaxMatch_Get_enabledStopToken(t *testing.T) {
mm.LoadDict()
mm.EnabledFilterStopToken = true
mm.StopTokens = NewStopTokens()
mm.StopTokens.Load(stopTokensDictPath)
result, err := mm.Get(mixtureText)
checkErr(err, t)
expectedResult := "gotokenizer/一款/字典/Bigram/模型/go/语言/编写/分词器/支持/6/种/分词/算法/支持/stopToken/过滤/自定义/word/过滤/功能"
reality := strings.Join(result, "/")
if reality != expectedResult {
t.Errorf(errorFormat,
reality, expectedResult)
}
}
func TestMaxMatch_Get(t *testing.T) {
mm.LoadDict()
result, err := mm.Get(zhText)
checkErr(err, t)
reality := strings.Join(result, "/")
if reality != expectedForForwardMaxMatch {
t.Errorf(errorFormat,
reality, expectedForForwardMaxMatch)
}
}
func TestMaxMatch_GetFrequency(t *testing.T) {
mm.LoadDict()
result := strings.Split(expectedForForwardMaxMatch, "/")
expected := GetFrequency(result)
reality, err := mm.GetFrequency(zhText)
checkErr(err, t)
if !reflect.DeepEqual(expected, reality) {
t.Errorf(errorFormat,
reality, expectedForForwardMaxMatch)
}
}