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
+6.8k Javascript : How to check a browser's Do Not Track status?
+46.2k Golang : How to convert JSON string to map and slice
+23.9k Golang : Convert uint value to string type
+7.7k Golang : Gonum standard normal random numbers example
+5.6k Golang : Gargish-English language translator
+16.1k Golang : Find smallest number in array
+6.7k Gogland : Where to put source code files in package directory for rookie
+6.2k Golang : Gorrila mux.Vars() function example
+5k Golang : Generate multiplication table from an integer example
+9.3k Golang : Generate random integer or float number
+3k Golang : PGX CopyFrom to insert rows into Postgres database
+22.2k Golang : Print out struct values in string format