Go version of the Sørensen–Dice coefficient. It can be used to compare two strings or return the best match in a slice of strings.
Note: The code was part of an exercise in learning Go. Pull requests are welcome.
go get github.com/imjasonmiller/godice
Compare string a
to string b
and return the score.
godice.CompareString("gopher", "golang")
The above would return 0.2
.
Strings are converted to lowercase
Compare string a
to a slice
of strings. Strings are sorted by their score.
godice.CompareStrings("golang", []string{"gopher", "gerbil", "grison"})
The above would return:
Matches{
BestMatch:{ Text: "gopher", Score: 0.2 },
Candidates:[
{ Text: "gopher", Score: 0.2 },
{ Text: "gerbil", Score: 0.0 },
{ Text: "grison", Score: 0.0 },
],
}