Skip to content

partialRatio

partialRatio(a, b): number

Compute the partial ratio between two strings.

Lower-cases both strings and collapses whitespace runs into single spaces, then compares the shorter string with every window of the same length in the longer one and returns the highest normalized Levenshtein similarity. Useful when one string is a substring or truncation of the other; it does not match abbreviations (MSFT vs Microsoft scores low). Scores can differ from fuzzball’s / RapidFuzz’s partial_ratio, which use a different alignment. Returns a value between 0.0 and 1.0.

Takes time proportional to the length of the longer string times the square of the length of the shorter one: about 0.4 s for a 1,000-character string against a 10,000-character one with the native addon.

Parameter Type
a string
b string

number