Skip to content
DeepForgeby svx
All problems
HardNLPnlp-034

Jaro-Winkler Prefix Boost

Problem

Return the Jaro-Winkler similarity: the Jaro similarity plus prefix * p * (1 - Jaro), where prefix is the length of the common prefix of the two strings capped at 4 and p defaults to 0.1.

Return 1.0 for equal strings, including two empty strings.

Hint

Compute the Jaro similarity first, then boost it by the shared prefix.

Test cases

case 1
in: ["martha","marhta"]
expected: 0.9611111111111111
case 2
in: ["dwayne","duane"]
expected: 0.8400000000000001
case 3
in: ["abc","abc"]
expected: 1
case 4
in: ["abc","xyz"]
expected: 0
case 5
in: ["",""]
expected: 1
Starter codePython
def jaro_winkler(s1, s2, p=0.1):
    # Your code here
    pass

5 test cases · run your code against them in the editor