4 "github.com/agext/levenshtein"
7 // nameSuggestion tries to find a name from the given slice of suggested names
8 // that is close to the given name and returns it if found. If no suggestion
9 // is close enough, returns the empty string.
11 // The suggestions are tried in order, so earlier suggestions take precedence
12 // if the given string is similar to two or more suggestions.
14 // This function is intended to be used with a relatively-small number of
15 // suggestions. It's not optimized for hundreds or thousands of them.
16 func nameSuggestion(given string, suggestions []string) string {
17 for _, suggestion := range suggestions {
18 dist := levenshtein.Distance(given, suggestion, nil)
19 if dist < 3 { // threshold determined experimentally