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
+11.5k SSL : The certificate is not trusted because no issuer chain was provided
+9.6k Golang : Qt get screen resolution and display on center example
+18.3k Golang : Example for RSA package functions
+41.3k Golang : Convert string to array/slice
+9.6k Golang : interface - when and where to use examples
+29.7k Golang : How to get HTTP request header information?
+5.2k Javascript : Shuffle or randomize array example
+9.2k Golang : How to get ECDSA curve and parameters data?
+19.8k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+16k Golang : How to check if input from os.Args is integer?
+6.4k PHP : Shuffle to display different content or advertisement
+14.6k Golang : Normalize unicode strings for comparison purpose