Repository navigation
Expand file tree
/
Copy pathpath.go
More file actions
190 lines (157 loc) · 6.71 KB
/
Copy pathpath.go
File metadata and controls
190 lines (157 loc) · 6.71 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package datamuse
import (
"path"
"strconv"
)
// Words endpoint returns a list of words (and multiword expressions) from a given vocabulary that match a given set of
// constraints.
func (dm *Datamuse) Words() *Datamuse {
dm.appendToPath("words")
return dm
}
// Suggestions endpoint provides word suggestions given a partially-entered query.
func (dm *Datamuse) Suggestions(s string) *Datamuse {
dm.appendToPath("sug")
dm.setQueryParam("s", s)
return dm
}
// MeansLike - require that the results have a meaning related to this string value, which can be any word or sequence
// of words. (This is effectively the reverse dictionary feature of OneLook.)
func (dm *Datamuse) MeansLike(s string) *Datamuse {
dm.setQueryParam("ml", s)
return dm
}
// SoundsLike - require that the results are pronounced similarly to this string of characters.
// If the string of characters doesn't have a known pronunciation, the system will make its best guess using a
// text-to-phonemes algorithm.
func (dm *Datamuse) SoundsLike(s string) *Datamuse {
dm.setQueryParam("sl", s)
return dm
}
// SpelledLike - require that the results are spelled similarly to this string of characters, or that they match this
// wildcard pattern. A pattern can include any combination of alphanumeric characters, spaces, and two reserved
// characters that represent placeholders — * (which matches any number of characters) and ? (which matches exactly one
// character).
func (dm *Datamuse) SpelledLike(s string) *Datamuse {
dm.setQueryParam("sp", s)
return dm
}
// Related - require that the results, when paired with the word in this parameter, are in a predefined lexical relation
// indicated by [code]. Any number of these parameters may be specified any number of times. An assortment of semantic,
// phonetic, and corpus-statistics-based relations are available. At this time, these relations are available for
// English-language vocabularies only.
func (dm *Datamuse) Related(code, s string) *Datamuse {
dm.setQueryParam("rel_"+code, s)
return dm
}
// RelatedNouns - Popular nouns modified by the given adjective, per Google Books Ngrams.
func (dm *Datamuse) RelatedNouns(s string) *Datamuse {
return dm.Related(RelatedNouns, s)
}
// RelatedAdjectives - Popular adjectives used to modify the given noun, per Google Books Ngrams.
func (dm *Datamuse) RelatedAdjectives(s string) *Datamuse {
return dm.Related(RelatedAdjectives, s)
}
// RelatedSynonyms - Synonyms (words contained within the same WordNet synset).
func (dm *Datamuse) RelatedSynonyms(s string) *Datamuse {
return dm.Related(RelatedSynonyms, s)
}
// RelatedTriggers - "Triggers" (words that are statistically associated with the query word in the same piece
// of text.)
func (dm *Datamuse) RelatedTriggers(s string) *Datamuse {
return dm.Related(RelatedTriggers, s)
}
// RelatedAntonyms - Antonyms (per WordNet)
func (dm *Datamuse) RelatedAntonyms(s string) *Datamuse {
return dm.Related(RelatedAntonyms, s)
}
// RelatedKindOf - "Kind of" (direct hypernyms, per WordNet)
func (dm *Datamuse) RelatedKindOf(s string) *Datamuse {
return dm.Related(RelatedKindOf, s)
}
// RelatedMoreGeneralThan - "More general than" (direct hyponyms, per WordNet)
func (dm *Datamuse) RelatedMoreGeneralThan(s string) *Datamuse {
return dm.Related(RelatedMoreGeneralThan, s)
}
// RelatedComprises - "Comprises" (direct holonyms, per WordNet)
func (dm *Datamuse) RelatedComprises(s string) *Datamuse {
return dm.Related(RelatedComprises, s)
}
// RelatedPartOf - "Part of" (direct meronyms, per WordNet)
func (dm *Datamuse) RelatedPartOf(s string) *Datamuse {
return dm.Related(RelatedPartOf, s)
}
// RelatedFrequentFollowers - Frequent followers (w′ such that P(w′|w) ≥ 0.001, per Google Books Ngrams)
func (dm *Datamuse) RelatedFrequentFollowers(s string) *Datamuse {
return dm.Related(RelatedFrequentFollowers, s)
}
// RelatedFrequentPredecessors - Frequent predecessors (w′ such that P(w|w′) ≥ 0.001, per Google Books Ngrams)
func (dm *Datamuse) RelatedFrequentPredecessors(s string) *Datamuse {
return dm.Related(RelatedFrequentPredecessors, s)
}
// RelatedRhymes - Rhymes ("perfect" rhymes, per RhymeZone)
func (dm *Datamuse) RelatedRhymes(s string) *Datamuse {
return dm.Related(RelatedRhymes, s)
}
// RelatedApproximateRhymes - Approximate rhymes (per RhymeZone)
func (dm *Datamuse) RelatedApproximateRhymes(s string) *Datamuse {
return dm.Related(RelatedApproximateRhymes, s)
}
// RelatedHomophones - Homophones (sound-alike words)
func (dm *Datamuse) RelatedHomophones(s string) *Datamuse {
return dm.Related(RelatedHomophones, s)
}
// RelatedConsonant - Consonant match
func (dm *Datamuse) RelatedConsonant(s string) *Datamuse {
return dm.Related(RelatedConsonant, s)
}
// Vocabulary - Identifier for the vocabulary to use.
func (dm *Datamuse) Vocabulary(s string) *Datamuse {
dm.setQueryParam("v", s)
return dm
}
// VocabularyDefault - The default 550,000-term vocabulary of English words and multiword expressions is used.
func (dm *Datamuse) VocabularyDefault() *Datamuse {
dm.setQueryParam("v", "")
return dm
}
// VocabularySpanish - The 500,000-term vocabulary of words from Spanish-language books is used.
func (dm *Datamuse) VocabularySpanish() *Datamuse {
return dm.Vocabulary(VocabularySpanish)
}
// VocabularyWikipedia - The approximately 6 million-term vocabulary of article titles from the English-language
// Wikipedia is used (updated monthly).
func (dm *Datamuse) VocabularyWikipedia() *Datamuse {
return dm.Vocabulary(VocabularyWikipedia)
}
// Topics - An optional hint to the system about the theme of the document being written. Results will be skewed toward
// these topics. At most 5 words can be specified. Space or comma delimited. Nouns work best.
func (dm *Datamuse) Topics(s string) *Datamuse {
dm.setQueryParam("topics", s)
return dm
}
// LeftContext - An optional hint to the system about the word that appears immediately to the left of the target word
// in a sentence. (At this time, only a single word may be specified.)
func (dm *Datamuse) LeftContext(s string) *Datamuse {
dm.setQueryParam("lc", s)
return dm
}
// RightContext - An optional hint to the system about the word that appears immediately to the right of the target word
// in a sentence. (At this time, only a single word may be specified.)
func (dm *Datamuse) RightContext(s string) *Datamuse {
dm.setQueryParam("rc", s)
return dm
}
// Max - Maximum number of results to return, not to exceed 1000. (default: 100)
func (dm *Datamuse) Max(n uint) *Datamuse {
dm.setQueryParam("max", strconv.FormatUint(uint64(n), 10))
return dm
}
func (dm *Datamuse) appendToPath(s string) {
dm.apiURL.Path = path.Join(dm.apiURL.Path, s)
}
func (dm *Datamuse) setQueryParam(key, value string) {
q := dm.apiURL.Query()
q.Set(key, value)
dm.apiURL.RawQuery = q.Encode()
}