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.7k Golang : Close channel after ticker stopped example
+3.2k Golang : Get environment variable
+1.8k Golang : Find the length of big.Int variable example
+5.8k Golang : Surveillance with web camera and OpenCV
+8.9k Golang : Qt image viewer example
+1.6k Golang : Calculate US Dollar Index (DXY)
+4.4k Random number generation with crypto/rand in Go
+1.9k Golang : Join lines with certain suffix symbol example
+6k Golang : Recombine chunked files example
+8.9k Golang : Convert slice to array
+3.1k Golang: Prevent over writing file with md5 hash
+5.9k Golang : Display list of time zones with GMT