Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add score_cutoff to 'extract' method in 'process' #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions fuzzywuzzy/process.py
Expand Up @@ -119,7 +119,7 @@ def no_process(x):
yield (choice, score)


def extract(query, choices, processor=default_processor, scorer=default_scorer, limit=5):
def extract(query, choices, processor=default_processor, scorer=default_scorer, score_cutoff=0, limit=5):
"""Select the best match in a list or dictionary of choices.

Find best matches in a list or dictionary of choices, return a
Expand All @@ -146,6 +146,8 @@ def extract(query, choices, processor=default_processor, scorer=default_scorer,
of the form f(query, choice) -> int.
By default, fuzz.WRatio() is used and expects both query and
choice to be strings.
score_cutoff: Optional argument for score threshold. No matches with
a score less than this number will be returned. Defaults to 0.
limit: Optional maximum for the number of elements returned. Defaults
to 5.

Expand All @@ -164,7 +166,7 @@ def extract(query, choices, processor=default_processor, scorer=default_scorer,

[('train', 22, 'bard'), ('man', 0, 'dog')]
"""
sl = extractWithoutOrder(query, choices, processor, scorer)
sl = extractWithoutOrder(query, choices, processor, scorer, score_cutoff)
return heapq.nlargest(limit, sl, key=lambda i: i[1]) if limit is not None else \
sorted(sl, key=lambda i: i[1], reverse=True)

Expand Down