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
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+7.9k Setting $GOPATH environment variable for Unix/Linux and Windows
+17k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+6k Linux/MacOSX : Search for files by filename and extension with find command
+10.3k Golang : Detect number of faces or vehicles in a photo
+10.5k Golang : Select region of interest with mouse click and crop from image
+10.6k Golang : Flip coin example
+18.2k Golang : Get path name to current directory or folder
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+7.2k Golang : Check if one string(rune) is permutation of another string(rune)
+13k Golang : Calculate elapsed years or months since a date
+12.5k Golang : Arithmetic operation with numerical slices or arrays example