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
+16.9k Golang : Get download file size
+14.2k Golang : Get checkbox or extract multipart form data value example
+22.6k Golang : Generate MD5 checksum of a file
+28.8k Golang : Remove characters from string example
+10.3k Golang : Fuzzy string search or approximate string matching example
+7.9k Golang : How to get username from email address
+6.6k Golang : Generate human readable password
+7.4k Golang : Count leading or ending zeros(any item of interest) example
+10k Golang : Concatenate (combine) buffer data example
+12.6k Golang : Tutorial on loading GOB and PEM files
+23.2k Golang : GORM read from database example