Golang : Levenshtein distance example
Continue from previous tutorial on fuzzy string search. This is a short example on Levenshtein distance with https://github.com/renstrom/fuzzysearch package. If you ever need to build a parser to parse natural language - Levenshtein distance will be handy. It also helps in spell checkers, correction systems for optical character recognition, and software to assist natural language translation.
Here you go!
package main
import (
"fmt"
"github.com/renstrom/fuzzysearch/fuzzy"
)
func main() {
input := []string{"example", "help", "assistance", "existence"}
rankMatches := fuzzy.RankFind("ex", input)
for _, rank := range rankMatches {
fmt.Println("Source : ", rank.Source, " Word :", rank.Target, " Distance : ", rank.Distance)
}
}
References :
See also : Golang : Fuzzy string search or approximate string matching example
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.6k Golang : How to check if input string is a word?
+10.6k Generate Random number with math/rand in Go
+17.2k Golang : Covert map/slice/array to JSON or XML format
+9.5k Golang : Timeout example
+8.5k Useful methods to access blocked websites
+9.4k Golang : Create and shuffle deck of cards example
+31.4k Golang : Calculate percentage change of two values
+5.5k Golang : Intercept, inject and replay HTTP traffics from web server
+14.5k Golang : Get uploaded file name or access uploaded files
+6k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+11.3k Golang : How to determine a prime number?
+51.6k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate