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
+4.7k Golang : Intercept, inject and replay HTTP traffics from web server
+14.4k Golang : Get query string value on a POST request
+7.4k Golang : Routes multiplexer routing example with regular expression control
+3.3k Detect if Google Analytics and Developer Media are loaded properly or not
+34.3k Golang : Save image to PNG, JPEG or GIF format.
+12.3k Swift : Convert (cast) Int to String ?
+7.4k Golang : Auto-generate reply email with text/template package
+4.2k Golang : Customize scanner.Scanner to treat dash as part of identifier
+6.1k Swift : substringWithRange() function example
+11k Golang : Split strings into command line arguments
+4.2k HTTP common errors and their meaning explained
+8.4k Golang : How to control fmt or log print format?