package main import ( "fmt" "github.com/hbollon/go-edlib" ) type Record struct { ID int Name string City string } func matches(a, b Record) bool { distance := edlib.LevenshteinDistance(a.Name, b.Name) return distance <= 3 && a.City == b.City } func main() { a := Record{ Name: "Vincent Van Gogh", City: "Paris", } b := Record{ Name: "Vince Van Gough", City: "Paris", } if matches(a, b) { fmt.Printf("%s and %s are probably the same person\n", a.Name, b.Name) } else { fmt.Printf("%s and %s are probably not the same person\n", a.Name, b.Name) } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter