Documentation ¶
Index ¶
- func ASCIIOnly(s string) string
- func Cleanse(s string, forceASCII bool) string
- func Dedupe(sliceWithDupes []string, threshold *int, scorer func(string, string) int) ([]string, error)
- func EditDistance(s1, s2 string) int
- func LevEditDistance(s1, s2 string, xcost int) int
- func PartialRatio(s1, s2 string) int
- func PartialTokenSetRatio(s1, s2 string, opts ...bool) int
- func PartialTokenSortRatio(s1, s2 string, opts ...bool) int
- func QRatio(s1, s2 string) int
- func Ratio(s1, s2 string) int
- func TokenSetRatio(s1, s2 string, opts ...bool) int
- func TokenSortRatio(s1, s2 string, opts ...bool) int
- func UQRatio(s1, s2 string) int
- func UWRatio(s1, s2 string) int
- func WRatio(s1, s2 string) int
- type MatchPair
- type MatchPairs
- type StringSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EditDistance ¶
EditDistance omputes the Levenshtein distance between two strings, weighting replacements the same as insertions and deletions.
func LevEditDistance ¶
LevEditDistance computes Levenshtein distance between 2 strings. If xcost parameter is zero, the replace operation has weight 1. Otherwise, all edit operations have equal weights of 1.
func PartialRatio ¶
PartialRatio computes a score of how close a string is with the most similar substring from another string. Order of arguments does not matter. Returns an integer score [0,100], higher score indicates that the string and substring are closer.
func PartialTokenSetRatio ¶
PartialTokenSetRatio extracts tokens from each input string, adds them to a set, construct two strings of the form <sorted intersection><sorted remainder>, takes the partial ratios of those two strings, and returns the max.
func PartialTokenSortRatio ¶
PartialTokenSortRatio computes a score similar to PartialRatio, except tokens are sorted and (optionally) cleansed prior to comparison.
func QRatio ¶
QRatio computes a score similar to Ratio, except both strings are trimmed, cleansed of non-ASCII characters, and case-standardized.
func Ratio ¶
Ratio computes a score of how close two unicode strings are based on their Levenshtein edit distance. Returns an integer score [0,100], higher score indicates that strings are closer.
func TokenSetRatio ¶
TokenSetRatio extracts tokens from each input string, adds them to a set, construct strings of the form <sorted intersection><sorted remainder>, takes the ratios of those two strings, and returns the max.
func TokenSortRatio ¶
TokenSortRatio computes a score similar to Ratio, except tokens are sorted and (optionally) cleansed prior to comparison.
func UQRatio ¶
UQRatio computes a score similar to Ratio, except both strings are trimmed and case-standardized.
func WRatio ¶
WRatio computes a score with the following steps:
- Cleanse both strings, remove non-ASCII characters.
- Take Ratio as baseline score.
- Run a few heuristics to determine whether partial ratios should be taken.
- If partial ratios were determined to be necessary, compute PartialRatio, PartialTokenSetRatio, and PartialTokenSortRatio. Otherwise, compute TokenSortRatio and TokenSetRatio.
- Return the max of all computed ratios.
Types ¶
type MatchPairs ¶
type MatchPairs []*MatchPair
func Extract ¶
func Extract(query string, choices []string, limit int, args ...interface{}) (MatchPairs, error)
func ExtractWithoutOrder ¶
func ExtractWithoutOrder(query string, choices []string, args ...interface{}) (MatchPairs, error)
func (MatchPairs) Len ¶
func (slice MatchPairs) Len() int
func (MatchPairs) Less ¶
func (slice MatchPairs) Less(i, j int) bool
func (MatchPairs) Swap ¶
func (slice MatchPairs) Swap(i, j int)
type StringSet ¶
type StringSet struct {
// contains filtered or unexported fields
}
func NewStringSet ¶
func (*StringSet) Difference ¶
Difference returns the set of strings that are present in this set but not the other set