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
+13.2k Golang : How to get a user home directory path?
+7.2k Golang : Array mapping with Interface
+7k Golang : Decode XML data from RSS feed
+16.6k Golang : File path independent of Operating System
+28.3k Golang : Connect to database (MySQL/MariaDB) server
+7.4k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+6k Golang : Shuffle array of list
+5k HTTP common errors and their meaning explained
+14.3k Golang : Fix image: unknown format error
+14.3k Elastic Search : Mapping date format and sort by date
+5.7k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday