@@ -59,11 +59,13 @@ func TestSegment(t *testing.T) {
59
59
segments := seg .Segment ([]byte ("中国有十三亿人口" ))
60
60
tt .Expect (t , "中国/ 有/p3 十三亿/ 人口/p12 " , ToString (segments , false ))
61
61
// tt.Expect(t, "中国/ 有/x 十三亿/ 人口/p12 ", ToString(segments, false))
62
+
62
63
tt .Expect (t , "4" , len (segments ))
63
64
tt .Expect (t , "0" , segments [0 ].start )
64
65
tt .Expect (t , "6" , segments [0 ].end )
65
66
tt .Expect (t , "6" , segments [1 ].start )
66
67
tt .Expect (t , "9" , segments [1 ].end )
68
+
67
69
tt .Expect (t , "9" , segments [2 ].start )
68
70
tt .Expect (t , "18" , segments [2 ].end )
69
71
tt .Expect (t , "18" , segments [3 ].start )
@@ -108,11 +110,12 @@ func TestSegmentJp(t *testing.T) {
108
110
seg .LoadDict ("data/dict/jp/dict.txt" )
109
111
text2 := []byte ("こんにちは世界" )
110
112
segments := seg .Segment ([]byte (text2 ))
113
+
111
114
tt .Expect (t , "こんにちは/感動詞 世界/名詞 " , ToString (segments , false ))
112
- tt .Expect (t , "2" , len (segments ))
113
115
tt .Expect (t , "こん/名詞 こんにちは/感動詞 世界/名詞 " , ToString (segments , true ))
114
116
tt .Expect (t , "[こん こんにちは 世界]" , ToSlice (segments , true ))
115
117
tt .Expect (t , "[こんにちは 世界]" , ToSlice (segments , false ))
118
+
116
119
tt .Expect (t , "2" , len (segments ))
117
120
tt .Expect (t , "0" , segments [0 ].start )
118
121
tt .Expect (t , "15" , segments [0 ].end )
@@ -121,6 +124,7 @@ func TestSegmentJp(t *testing.T) {
121
124
func TestDictPaths (t * testing.T ) {
122
125
paths := DictPaths ("./dictDir" , "zh,jp" )
123
126
tt .Expect (t , "2" , len (paths ))
127
+
124
128
if paths [0 ] != "dictDir/dict/dictionary.txt" {
125
129
t .Errorf ("what=\" %s\" , got=\" %s\" " , "dictDir/dict/dictionary.txt" , paths [0 ])
126
130
}
@@ -161,6 +165,12 @@ func TestSegmentDicts(t *testing.T) {
161
165
tt .Expect (t , "5704" , token .Frequency ())
162
166
tt .Expect (t , "感動詞" , token .Pos ())
163
167
168
+ var tokenArr []* Token
169
+ for i := 0 ; i < len (segments ); i ++ {
170
+ tokenArr = append (tokenArr , segments [i ].Token ())
171
+ }
172
+ tt .Expect (t , "こんにちは 世界 " , printTokens (tokenArr , 2 ))
173
+
164
174
tseg := token .Segments ()
165
175
tt .Expect (t , "0" , tseg [0 ].Start ())
166
176
tt .Expect (t , "6" , tseg [0 ].End ())
0 commit comments