mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-28 21:48:25 +00:00
* feat: Add check for misspelled executable name command * Update server/utils/spellcheck_test.go Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com> --------- Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com> Co-authored-by: Ken Kaizu <k.kaizu38@gmail.com>
18 lines
483 B
Go
18 lines
483 B
Go
package utils
|
|
|
|
import (
|
|
"github.com/agext/levenshtein"
|
|
)
|
|
|
|
// IsSimilarWord calculates "The Levenshtein Distance" between two strings which
|
|
// represents the minimum total cost of edits that would convert the first string
|
|
// into the second. If the distance is less than 3, the word is considered misspelled.
|
|
func IsSimilarWord(given string, suggestion string) bool {
|
|
dist := levenshtein.Distance(given, suggestion, nil)
|
|
if dist > 0 && dist < 3 {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|