Skip to content

Commit 33e3dfd

Browse files
committed
Rename 'Name()' to 'DictionaryName()'
1 parent 5f4799c commit 33e3dfd

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func main() {
8585
// Spell supports multiple dictionaries
8686
s4 := spell.New()
8787

88-
s4.AddEntry(spell.Entry{Word: "épeler"}, spell.Name("french"))
88+
s4.AddEntry(spell.Entry{Word: "épeler"}, spell.DictionaryName("french"))
8989
suggestions, _ = s4.Lookup("épeler", spell.DictionaryOpts(
90-
spell.Name("french"),
90+
spell.DictionaryName("french"),
9191
))
9292
fmt.Println(suggestions)
9393
// -> [épeler]

spell.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,26 @@ func Load(filename string) (*Spell, error) {
140140
return s, nil
141141
}
142142

143-
type dictParams struct {
143+
type dictOptions struct {
144144
name string
145145
}
146146

147147
// DictionaryOption is a function that controls the dictionary being used.
148148
// An error will be returned if a dictionary option is invalid
149-
type DictionaryOption func(*dictParams) error
149+
type DictionaryOption func(*dictOptions) error
150150

151-
func (s *Spell) defaultDictParams() *dictParams {
152-
return &dictParams{
151+
func (s *Spell) defaultDictOptions() *dictOptions {
152+
return &dictOptions{
153153
name: defaultDict,
154154
}
155155
}
156156

157-
// Name defines the name of the dictionary that should be used when storing,
158-
// deleting, looking up words, etc. If not set, the default dictionary will be
159-
// used
160-
func Name(name string) DictionaryOption {
161-
return func(params *dictParams) error {
162-
params.name = name
157+
// DictionaryName defines the name of the dictionary that should be used when
158+
// storing, deleting, looking up words, etc. If not set, the default dictionary
159+
// will be used
160+
func DictionaryName(name string) DictionaryOption {
161+
return func(opts *dictOptions) error {
162+
opts.name = name
163163
return nil
164164
}
165165
}
@@ -168,10 +168,10 @@ func Name(name string) DictionaryOption {
168168
// will be overwritten. Returns true if a new word was added, false otherwise.
169169
// Will return an error if there was a problem adding a word
170170
func (s *Spell) AddEntry(de Entry, opts ...DictionaryOption) (bool, error) {
171-
dictParams := s.defaultDictParams()
171+
dictOptions := s.defaultDictOptions()
172172

173173
for _, opt := range opts {
174-
if err := opt(dictParams); err != nil {
174+
if err := opt(dictOptions); err != nil {
175175
return false, err
176176
}
177177
}
@@ -182,13 +182,13 @@ func (s *Spell) AddEntry(de Entry, opts ...DictionaryOption) (bool, error) {
182182

183183
// If the word already exists, just update its result - we don't need to
184184
// recalculate the deletes as these should never change
185-
if _, exists := s.library.load(dictParams.name, word); exists {
185+
if _, exists := s.library.load(dictOptions.name, word); exists {
186186
atomic.AddUint64(&s.cumulativeFreq, ^(de.Frequency - 1))
187-
s.library.store(dictParams.name, word, de)
187+
s.library.store(dictOptions.name, word, de)
188188
return false, nil
189189
}
190190

191-
s.library.store(dictParams.name, word, de)
191+
s.library.store(dictOptions.name, word, de)
192192

193193
// Keep track of the longest word in the dictionary
194194
wordLength := uint32(len([]rune(word)))
@@ -208,7 +208,7 @@ func (s *Spell) AddEntry(de Entry, opts ...DictionaryOption) (bool, error) {
208208
str: word,
209209
}
210210
for deleteHash := range deletes {
211-
s.dictionaryDeletes.add(dictParams.name, deleteHash, &de)
211+
s.dictionaryDeletes.add(dictOptions.name, deleteHash, &de)
212212
}
213213
}
214214

@@ -218,15 +218,15 @@ func (s *Spell) AddEntry(de Entry, opts ...DictionaryOption) (bool, error) {
218218
// GetEntry returns the Entry for word. If a word does not exist, nil will
219219
// be returned
220220
func (s *Spell) GetEntry(word string, opts ...DictionaryOption) (*Entry, error) {
221-
dictParams := s.defaultDictParams()
221+
dictOpts := s.defaultDictOptions()
222222

223223
for _, opt := range opts {
224-
if err := opt(dictParams); err != nil {
224+
if err := opt(dictOpts); err != nil {
225225
return nil, err
226226
}
227227
}
228228

229-
if entry, exists := s.library.load(dictParams.name, word); exists {
229+
if entry, exists := s.library.load(dictOpts.name, word); exists {
230230
return &entry, nil
231231
}
232232
return nil, nil
@@ -240,15 +240,15 @@ func (s *Spell) GetLongestWord() uint32 {
240240
// RemoveEntry removes a entry from the dictionary. Returns true if the entry
241241
// was removed, false otherwise
242242
func (s *Spell) RemoveEntry(word string, opts ...DictionaryOption) (bool, error) {
243-
dictParams := s.defaultDictParams()
243+
dictOpts := s.defaultDictOptions()
244244

245245
for _, opt := range opts {
246-
if err := opt(dictParams); err != nil {
246+
if err := opt(dictOpts); err != nil {
247247
return false, err
248248
}
249249
}
250250

251-
return s.library.remove(dictParams.name, word), nil
251+
return s.library.remove(dictOpts.name, word), nil
252252
}
253253

254254
// Save a representation of spell to disk at filename
@@ -305,7 +305,7 @@ func (s SuggestionList) String() string {
305305
}
306306

307307
type lookupParams struct {
308-
dictParams *dictParams
308+
dictOpts *dictOptions
309309
distanceFunction func([]rune, []rune, int) int
310310
editDistance uint32
311311
prefixLength uint32
@@ -315,7 +315,7 @@ type lookupParams struct {
315315

316316
func (s *Spell) defaultLookupParams() *lookupParams {
317317
return &lookupParams{
318-
dictParams: s.defaultDictParams(),
318+
dictOpts: s.defaultDictOptions(),
319319
distanceFunction: strmet.DamerauLevenshteinRunes,
320320
editDistance: s.MaxEditDistance,
321321
prefixLength: s.PrefixLength,
@@ -346,7 +346,7 @@ type LookupOption func(*lookupParams) error
346346
func DictionaryOpts(opts ...DictionaryOption) LookupOption {
347347
return func(params *lookupParams) error {
348348
for _, opt := range opts {
349-
if err := opt(params.dictParams); err != nil {
349+
if err := opt(params.dictOpts); err != nil {
350350
return err
351351
}
352352
}
@@ -404,7 +404,7 @@ func PrefixLength(prefixLength uint32) LookupOption {
404404
}
405405
}
406406

407-
func (s *Spell) newDictSuggestion(input string, dist int, dp *dictParams) Suggestion {
407+
func (s *Spell) newDictSuggestion(input string, dist int, dp *dictOptions) Suggestion {
408408
entry, _ := s.library.load(dp.name, input)
409409

410410
return Suggestion{
@@ -429,11 +429,11 @@ func (s *Spell) Lookup(input string, opts ...LookupOption) (SuggestionList, erro
429429
}
430430

431431
results := SuggestionList{}
432-
dict := lookupParams.dictParams.name
432+
dict := lookupParams.dictOpts.name
433433

434434
// Check for an exact match
435435
if _, exists := s.library.load(dict, input); exists {
436-
results = append(results, s.newDictSuggestion(input, 0, lookupParams.dictParams))
436+
results = append(results, s.newDictSuggestion(input, 0, lookupParams.dictOpts))
437437

438438
if lookupParams.suggestionLevel != LevelAll {
439439
return results, nil
@@ -556,14 +556,14 @@ func (s *Spell) Lookup(input string, opts ...LookupOption) (SuggestionList, erro
556556
results = SuggestionList{}
557557
}
558558
case LevelBest:
559-
entry, _ := s.library.load(lookupParams.dictParams.name, suggestion.str)
559+
entry, _ := s.library.load(lookupParams.dictOpts.name, suggestion.str)
560560

561561
curFreq := entry.Frequency
562562
closestFreq := results[0].Frequency
563563

564564
if dist < editDistance || curFreq > closestFreq {
565565
editDistance = dist
566-
results[0] = s.newDictSuggestion(suggestion.str, dist, lookupParams.dictParams)
566+
results[0] = s.newDictSuggestion(suggestion.str, dist, lookupParams.dictOpts)
567567
}
568568
continue
569569
}
@@ -574,7 +574,7 @@ func (s *Spell) Lookup(input string, opts ...LookupOption) (SuggestionList, erro
574574
}
575575

576576
results = append(results,
577-
s.newDictSuggestion(suggestion.str, dist, lookupParams.dictParams))
577+
s.newDictSuggestion(suggestion.str, dist, lookupParams.dictOpts))
578578
}
579579

580580
}

spell_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func TestLookup_multipleDictionaries(t *testing.T) {
205205
// Test adding a word to a different dictionary
206206
ok, err := s.AddEntry(Entry{
207207
Word: "française",
208-
}, Name("french"))
208+
}, DictionaryName("french"))
209209
if err != nil {
210210
t.Fatal(err)
211211
}
@@ -222,7 +222,7 @@ func TestLookup_multipleDictionaries(t *testing.T) {
222222
t.Fatal("Should get no results for word in different dictionary")
223223
}
224224

225-
suggestions, err = s.Lookup("française", DictionaryOpts(Name("french")))
225+
suggestions, err = s.Lookup("française", DictionaryOpts(DictionaryName("french")))
226226
if err != nil {
227227
t.Fatal(err)
228228
}

0 commit comments

Comments
 (0)