Skip to content

tokenSetRatio

tokenSetRatio(a, b): number

Compute the token set ratio between two strings.

Lower-cases both strings and splits them into sets of whitespace-separated tokens (duplicates count once). With the shared tokens sorted and joined as common, returns the highest normalized Levenshtein similarity among common + rest of a vs common + rest of b, common vs common + rest of a, and common vs common + rest of b. It is 1.0 when the tokens of one string are a subset of the other’s. Returns a value between 0.0 and 1.0.

Parameter Type
a string
b string

number