-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmystem_test.go
121 lines (111 loc) · 2.46 KB
/
mystem_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package mystem
import (
"reflect"
"testing"
)
func TestGetAnalysesCount(t *testing.T) {
analyses := NewAnalyses("маша")
defer analyses.Close()
if analyses.Count() != 2 {
t.Fail()
}
}
func TestGetLemmaText(t *testing.T) {
analyses := NewAnalyses("маша")
defer analyses.Close()
lemma := analyses.GetLemma(0)
if lemma.TextLength() != 4 {
t.Fail()
}
if lemma.Text() != "маша" {
t.Fail()
}
lemma = analyses.GetLemma(1)
if lemma.TextLength() != 6 {
t.Fail()
}
if lemma.Text() != "махать" {
t.Fail()
}
}
func TestGetLemmaForm(t *testing.T) {
analyses := NewAnalyses("маша")
defer analyses.Close()
lemma := analyses.GetLemma(0)
if lemma.FormLength() != 4 {
t.Fail()
}
if lemma.Form() != "маша" {
t.Fail()
}
}
func TestGetLemmaQuality(t *testing.T) {
analyses := NewAnalyses("маша")
lemma := analyses.GetLemma(0)
if lemma.Quality() != Dictionary {
t.Fail()
}
analyses.Close()
analyses = NewAnalyses("майстем")
defer analyses.Close()
lemma = analyses.GetLemma(0)
if lemma.Quality() != Bastard {
t.Fail()
}
}
func TestGetLemmaStemGrammemes(t *testing.T) {
analyses := NewAnalyses("маша")
defer analyses.Close()
lemma := analyses.GetLemma(0)
grammemes := lemma.StemGram()
if !reflect.DeepEqual(grammemes, []int{Substantive, FirstName, Feminine, Animated}) {
t.Fail()
}
}
func TestGetLemmaFlexGrammemes(t *testing.T) {
analyses := NewAnalyses("маша")
defer analyses.Close()
lemma := analyses.GetLemma(0)
grammemes := lemma.FlexGram()
if !reflect.DeepEqual(grammemes, [][]int{[]int{Nominative, Singular}}) {
t.Fail()
}
}
func TestGetLemmaForms(t *testing.T) {
analyses := NewAnalyses("маша")
defer analyses.Close()
lemma := analyses.GetLemma(0)
forms := lemma.GenerateForms()
if forms.Count() != 10 {
t.Fail()
}
}
func TestGetForm(t *testing.T) {
analyses := NewAnalyses("маша")
defer analyses.Close()
lemma := analyses.GetLemma(0)
forms := lemma.GenerateForms()
form := forms.Get(0)
if form.TextLength() != 3 {
t.Fail()
}
if form.Text() != "маш" {
t.Fail()
}
if !reflect.DeepEqual(form.StemGram(), []int{Substantive, FirstName, Feminine, Animated}) {
t.Fail()
}
if !reflect.DeepEqual(form.FlexGram()[0], []int{Accusative, Plural}) {
t.Fail()
}
}
func BenchmarkMystem(b *testing.B) {
mystem := NewAnalyses("маша")
defer mystem.Close()
for i := 0; i < b.N; i++ {
for i := 0; i < mystem.Count(); i++ {
lemma := mystem.GetLemma(i)
lemma.Text()
}
}
}