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
+9.8k Golang : Check if user agent is a robot or crawler example
+5.8k Golang : Shuffle array of list
+10k Golang : Compare files modify date example
+14.6k Golang : Find commonalities in two slices or arrays example
+29.2k Golang : Record voice(audio) from microphone to .WAV file
+7.3k Golang : Convert source code to assembly language
+11.3k Golang : Concatenate (combine) buffer data example
+5.5k Golang : Frobnicate or tweaking a string example
+6.8k Golang : Normalize email to prevent multiple signups example
+7.7k Swift : Convert (cast) String to Double
+8.7k Golang : HTTP Routing with Goji example