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
+23k Golang : Daemonizing a simple web server process example
+29.7k error: trying to remove "yum", which is protected
+29.3k Golang : How to redirect to new page with net/http?
+14.4k Golang : invalid character ',' looking for beginning of value
+5.3k Golang : How to solve "too many .rsrc sections" error?
+24.7k Golang : Get executable name behind process ID example
+15k Golang : Find out mime type from bytes in buffer
+5.4k Golang : Test input string for unicode example
+12.1k Golang : Calculate elapsed years or months since a date
+23k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+8k Golang : How to extract video or image files from html source code
+12.7k Golang : Gin framework accept query string by post request example