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.1k Golang : cannot assign type int to value (type uint8) in range error
+18.8k Golang : Use TLS version 1.2 and enforce server security configuration over client
+9.6k Golang : How to calculate the distance between two coordinates using Haversine formula
+25k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+3.5k HTTP common errors and their meaning explained
+8.2k Golang : Fix go.exe is not compatible with the version of Windows you're running
+3.9k Golang : Issue HTTP commands to server and port example
+12k Golang : How to filter a map's elements for faster lookup
+48.8k Golang : How to get time in milliseconds?
+21k Golang : Strings to lowercase and uppercase example
+4.3k Golang : Generate multiplication table from an integer example
+5k Golang : Warp text string by number of characters or runes example