-
Notifications
You must be signed in to change notification settings - Fork 1
/
examples_test.go
167 lines (137 loc) · 5.64 KB
/
examples_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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package datamuse
import (
"testing"
"github.com/stretchr/testify/assert"
)
// In order to find words with a meaning similar to ringing in the ears.
func Test_Words_Means_Like(t *testing.T) {
dm := New()
res, err := dm.Words().MeansLike("ringing in the ears").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?ml=ringing+in+the+ears", dm.URL())
assert.Equal(t, "tinnitus", res[0].Word)
assert.NotZero(t, res[0].Score)
assert.EqualValues(t, []string{"syn", "n", "results_type:primary_external", "results_type:backfill_gloss"}, res[0].Tags)
}
// In order to find words related to duck that start with the letter b.
func Test_Words_Means_Like_Starts_With(t *testing.T) {
dm := New()
res, err := dm.Words().MeansLike("duck").SpelledLike("b*").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?ml=duck&sp=b%2A", dm.URL())
assert.Equal(t, "bird", res[0].Word)
assert.NotZero(t, res[0].Score)
assert.EqualValues(t, []string{"n", "results_type:primary_rel"}, res[0].Tags)
}
// In order to find words related to spoon that end with the letter a.
func Test_Words_Means_Like_Ends_With(t *testing.T) {
dm := New()
res, err := dm.Words().MeansLike("spoon").SpelledLike("*a").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?ml=spoon&sp=%2Aa", dm.URL())
assert.Equal(t, "spatula", res[0].Word)
assert.NotZero(t, res[0].Score)
assert.EqualValues(t, []string{"n", "results_type:primary_rel"}, res[0].Tags)
}
// In order to find words that sound like elefint.
func Test_Words_Sounds_Like(t *testing.T) {
dm := New()
res, err := dm.Words().SoundsLike("elefint").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?sl=elefint", dm.URL())
assert.Equal(t, "elefant", res[0].Word)
assert.NotZero(t, res[0].Score)
assert.EqualValues(t, 3, res[0].SyllablesCount)
}
// In order to find words that start with t, end in k, and have two letters in between.
func Test_Words_Spelled_Like_Pattern(t *testing.T) {
dm := New()
res, err := dm.Words().SpelledLike("t??k").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?sp=t%3F%3Fk", dm.URL())
assert.Equal(t, "talk", res[0].Word)
assert.NotZero(t, res[0].Score)
}
// In order to find words that are spelled similarly to coneticut.
func Test_Words_Spelled_Like(t *testing.T) {
dm := New()
res, err := dm.Words().SpelledLike("coneticut").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?sp=coneticut", dm.URL())
assert.Equal(t, "conneticut", res[0].Word)
assert.NotZero(t, res[0].Score)
}
// In order to find words that rhyme with forgetful.
func Test_Words_Related_Rhymes(t *testing.T) {
dm := New()
res, err := dm.Words().RelatedRhymes("forgetful").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?rel_rhy=forgetful", dm.URL())
assert.Equal(t, "fretful", res[0].Word)
assert.NotZero(t, res[0].Score)
assert.EqualValues(t, 2, res[0].SyllablesCount)
}
// In order to find words that rhyme with grape that are related to breakfast.
func Test_Words_Means_Like_Related_Rhymes(t *testing.T) {
dm := New()
res, err := dm.Words().MeansLike("breakfast").RelatedRhymes("grape").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?ml=breakfast&rel_rhy=grape", dm.URL())
assert.Equal(t, "crepe", res[0].Word)
assert.NotZero(t, res[0].Score)
assert.EqualValues(t, 1, res[0].SyllablesCount)
}
// In order to find adjectives that are often used to describe ocean.
func Test_Words_Related_Adjectives(t *testing.T) {
dm := New()
res, err := dm.Words().RelatedAdjectives("ocean").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?rel_jjb=ocean", dm.URL())
assert.Equal(t, "open", res[0].Word)
assert.NotZero(t, res[0].Score)
}
// In order to find adjectives describing ocean sorted by how related they are to temperature.
func Test_Words_Related_Adjectives_By_Topics(t *testing.T) {
dm := New()
res, err := dm.Words().RelatedAdjectives("ocean").Topics("temperature").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?rel_jjb=ocean&topics=temperature", dm.URL())
assert.Equal(t, "cold", res[0].Word)
assert.NotZero(t, res[0].Score)
}
// In order to find nouns that are often described by the adjective yellow.
func Test_Words_Related_Noun(t *testing.T) {
dm := New()
res, err := dm.Words().RelatedNouns("yellow").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?rel_jja=yellow", dm.URL())
assert.Equal(t, "fever", res[0].Word)
assert.NotZero(t, res[0].Score)
}
// In order to find words that often follow "drink" in a sentence, that start with the letter w
func Test_Words_Left_Context(t *testing.T) {
dm := New()
res, err := dm.Words().LeftContext("drink").SpelledLike("w*").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?lc=drink&sp=w%2A", dm.URL())
assert.Equal(t, "with", res[0].Word)
assert.NotZero(t, res[0].Score)
}
// In order to find words that are triggered by (strongly associated with) the word "cow"
func Test_Words_Related_Triggers(t *testing.T) {
dm := New()
res, err := dm.Words().RelatedTriggers("cow").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/words?rel_trg=cow", dm.URL())
assert.Equal(t, "dung", res[0].Word)
assert.NotZero(t, res[0].Score)
}
// In order to find suggestions for the user if they have typed in rawand so far
func Test_Suggestions(t *testing.T) {
dm := New()
res, err := dm.Suggestions("rawand").Get()
assert.NoError(t, err)
assert.Equal(t, "https://api.datamuse.com/sug?s=rawand", dm.URL())
assert.Equal(t, "rwanda", res[0].Word)
assert.NotZero(t, res[0].Score)
}