Added dict with additional cards
This commit is contained in:
parent
181f3bc0aa
commit
88ea431a27
26 changed files with 232 additions and 35 deletions
21
internal/dicttranslate/match.go
Normal file
21
internal/dicttranslate/match.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package dicttranslate
|
||||
|
||||
import "github.com/texttheater/golang-levenshtein/levenshtein"
|
||||
|
||||
func match(query string, opts []string, maxDist int) (string, bool) {
|
||||
bestInd := -1
|
||||
bestDist := 0
|
||||
for i, s := range opts {
|
||||
cfg := levenshtein.DefaultOptions
|
||||
cfg.SubCost = 1
|
||||
dist := levenshtein.DistanceForStrings([]rune(s), []rune(query), cfg)
|
||||
if dist <= maxDist && (bestInd == -1 || dist < bestDist) {
|
||||
bestInd = i
|
||||
bestDist = dist
|
||||
}
|
||||
}
|
||||
if bestInd == -1 {
|
||||
return "", false
|
||||
}
|
||||
return opts[bestInd], true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue