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
+8.3k Android Studio : Rating bar example
+9.9k Random number generation with crypto/rand in Go
+4.8k MariaDB/MySQL : Form select statement or search query with Chinese characters
+9.7k Golang : Read file with ioutil
+6.7k Golang : How to validate ISBN?
+9.3k Golang : Create and shuffle deck of cards example
+3.7k Java : Get FX sentiment from website example
+6.3k Golang : Extract sub-strings
+12k Golang : Determine if time variables have same calendar day
+7.4k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+13.3k Golang : Convert(cast) int to int64
+14.6k Android Studio : Use image as AlertDialog title with custom layout example