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
+6.8k Golang : Warp text string by number of characters or runes example
+30.1k Golang : Get and Set User-Agent examples
+18.8k Golang : Find IP address from string
+43.9k Golang : Get hardware information such as disk, memory and CPU usage
+6k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+13k Golang : Convert IPv4 address to packed 32-bit binary format
+6k AWS S3 : Prevent Hotlinking policy
+20.8k Nginx + FastCGI + Go Setup.
+13.8k Golang : Strings comparison
+7.8k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+14.6k Golang : Simple word wrap or line breaking example
+33.2k Golang : How to check if a date is within certain range?