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.2k Golang : How to control fmt or log print format?
+13.5k Golang : Rename directory
+3.6k Adding Skype actions such as call and chat into web page examples
+7.4k Android Studio : Image button and button example
+8.7k Golang : Bcrypting password
+8.9k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+8.8k Golang : Check if user agent is a robot or crawler example
+5.2k Linux/Unix : Commands that you need to be careful about
+17.1k Golang : Implement getters and setters
+16.1k Golang : How to make a file read only and set it to writable again?
+9.8k Golang : Web routing/multiplex example
+10.6k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example