Skip to content

imjasonmiller/godice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

godice

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.

Install

go get github.com/imjasonmiller/godice

Usage

godice.compareString(a, b str) float64

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

godice.compareStrings(a str, b []str) Matches

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 },
  ],
}

About

Sørensen–Dice coefficient in Go

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages