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.5k Golang : Humanize and Titleize functions
+4.2k Linux/MacOSX : Search and delete files by extension
+10.2k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+10k Golang : Convert file unix timestamp to UTC time example
+37k Upload multiple files with Go
+8.5k Golang : Take screen shot of browser with JQuery example
+5.2k Golang : fmt.Println prints out empty data from struct
+9.2k Golang : How to extract video or image files from html source code
+19.1k Golang : How to count the number of repeated characters in a string?
+5.3k Python : Print unicode escape characters and string
+7.6k Golang : Load DSA public key from file example