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
+9.5k Random number generation with crypto/rand in Go
+10.2k Golang : Meaning of omitempty in struct's field tag
+3.9k Detect if Google Analytics and Developer Media are loaded properly or not
+21.5k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+5.9k Golang : Experimenting with the Rejang script
+16.8k Golang : Get number of CPU cores
+7.1k Golang : File system scanning
+21.7k Golang : Join arrays or slices example
+6k Golang : Extract XML attribute data with attr field tag example
+8k Golang : Find relative luminance or color brightness
+16.8k Golang : Capture stdout of a child process and act according to the result
+16.9k Golang : Covert map/slice/array to JSON or XML format