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
+10k Golang : How to tokenize source code with text/scanner package?
+13.3k Golang : error parsing regexp: invalid or unsupported Perl syntax
+14.9k Golang : package is not in GOROOT during compilation
+21.8k Golang : Use TLS version 1.2 and enforce server security configuration over client
+15.8k Golang : Update database with GORM example
+13.5k Golang : reCAPTCHA example
+27.6k PHP : Count number of JSON items/objects
+14.3k Golang : Recombine chunked files example
+11.8k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+5.6k Fix fatal error: evacuation not done in time problem
+41.6k Golang : How do I convert int to uint8?