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
+3.1k Detect if Google Analytics and Developer Media are loaded properly or not
+11k Golang : List running EC2 instances and descriptions
+32.7k Golang : convert(cast) bytes to string
+7.7k Golang : Gorilla web tool kit schema example
+14.9k Golang : Find out mime type from bytes in buffer
+20.2k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+11.3k Golang : How to display image file or expose CSS, JS files from localhost?
+3.3k Javascript : Empty an array example
+6.1k Web : How to see your website from different countries?
+7.9k Golang : Build and compile multiple source files
+11.5k Golang : Get terminal width and height example
+5.6k Golang : Skip or discard items of non-interest when iterating example