Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions thefuzz/fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
###########################


def _rapidfuzz_scorer(scorer, s1, s2, force_ascii, full_process):
def _rapidfuzz_scorer(scorer: callable, s1: str, s2: str, force_ascii: bool, full_process: bool) -> int:
"""
wrapper around rapidfuzz function to be compatible with the API of thefuzz
"""
Expand All @@ -32,11 +32,11 @@ def _rapidfuzz_scorer(scorer, s1, s2, force_ascii, full_process):
return int(round(scorer(s1, s2)))


def ratio(s1, s2):
def ratio(s1: str, s2: str) -> int:
return _rapidfuzz_scorer(_ratio, s1, s2, False, False)


def partial_ratio(s1, s2):
def partial_ratio(s1: str, s2: str) -> int:
"""
Return the ratio of the most similar substring
as a number between 0 and 100.
Expand All @@ -52,15 +52,15 @@ def partial_ratio(s1, s2):
# find all alphanumeric tokens in the string
# sort those tokens and take ratio of resulting joined strings
# controls for unordered string elements
def token_sort_ratio(s1, s2, force_ascii=True, full_process=True):
def token_sort_ratio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True) -> int:
"""
Return a measure of the sequences' similarity between 0 and 100
but sorting the token before comparing.
"""
return _rapidfuzz_scorer(_token_sort_ratio, s1, s2, force_ascii, full_process)


def partial_token_sort_ratio(s1, s2, force_ascii=True, full_process=True):
def partial_token_sort_ratio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True) -> int:
"""
Return the ratio of the most similar substring as a number between
0 and 100 but sorting the token before comparing.
Expand All @@ -70,11 +70,11 @@ def partial_token_sort_ratio(s1, s2, force_ascii=True, full_process=True):
)


def token_set_ratio(s1, s2, force_ascii=True, full_process=True):
def token_set_ratio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True) -> int:
return _rapidfuzz_scorer(_token_set_ratio, s1, s2, force_ascii, full_process)


def partial_token_set_ratio(s1, s2, force_ascii=True, full_process=True):
def partial_token_set_ratio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True) -> int:
return _rapidfuzz_scorer(
_partial_token_set_ratio, s1, s2, force_ascii, full_process
)
Expand All @@ -85,7 +85,7 @@ def partial_token_set_ratio(s1, s2, force_ascii=True, full_process=True):
###################

# q is for quick
def QRatio(s1, s2, force_ascii=True, full_process=True):
def QRatio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True) -> int:
"""
Quick ratio comparison between two strings.

Expand All @@ -101,7 +101,7 @@ def QRatio(s1, s2, force_ascii=True, full_process=True):
return _rapidfuzz_scorer(_QRatio, s1, s2, force_ascii, full_process)


def UQRatio(s1, s2, full_process=True):
def UQRatio(s1: str, s2: str, full_process: bool = True) -> int:
"""
Unicode quick ratio

Expand All @@ -115,7 +115,7 @@ def UQRatio(s1, s2, full_process=True):


# w is for weighted
def WRatio(s1, s2, force_ascii=True, full_process=True):
def WRatio(s1: str, s2: str, force_ascii: bool = True, full_process: bool = True) -> int:
"""
Return a measure of the sequences' similarity between 0 and 100, using different algorithms.

Expand Down Expand Up @@ -152,7 +152,7 @@ def WRatio(s1, s2, force_ascii=True, full_process=True):
return _rapidfuzz_scorer(_WRatio, s1, s2, force_ascii, full_process)


def UWRatio(s1, s2, full_process=True):
def UWRatio(s1: str, s2: str, full_process: bool = True) -> int:
"""
Return a measure of the sequences' similarity between 0 and 100,
using different algorithms. Same as WRatio but preserving unicode.
Expand Down