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.1k PHP : How to check if an array is empty ?
+5.3k Golang : Generate Interleaved 2 inch by 5 inch barcode
+10.7k Android Studio : Simple input textbox and intercept key example
+20.9k Golang : Convert PNG transparent background image to JPG or JPEG image
+17.6k Golang : Clone with pointer and modify value
+17k Golang : Set up source IP address before making HTTP request
+5.4k Golang : Reclaim memory occupied by make() example
+5k Nginx and PageSpeed build from source CentOS example
+19k Golang : Padding data for encryption and un-padding data for decryption
+14.1k Golang : Reverse IP address for reverse DNS lookup example
+7.5k Android Studio : How to detect camera, activate and capture example