Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testQRatioForceAscii(self):
s1 = "ABCD\u00C1"
s2 = "ABCD"
score = fuzz.WRatio(s1, s2, force_ascii=True)
self.assertEqual(score, 100)
score = fuzz.WRatio(s1, s2, force_ascii=False)
self.assertLess(score, 100)
def testWRatioMisorderedMatch(self):
# misordered full matches are scaled by .95
self.assertEqual(fuzz.WRatio(self.s4, self.s5), 95)
def testWRatioPartialMatch(self):
# a partial match is scaled by .9
self.assertEqual(fuzz.WRatio(self.s1, self.s3), 90)
def testWRatioUnicode(self):
self.assertEqual(fuzz.WRatio(unicode(self.s1), unicode(self.s1a)), 100)
def refresh(self):
# TODO optimize
self.search_results = sorted(filter(lambda x: x[0], (
(entry, fuzzywuzzy.fuzz.WRatio(self.query, entry.key)
if self.query else 0)
for entry in self.session.entries)),
key=lambda x: (100 - x[1], x[0].key))
def fuzzy(s1, s2):
return [fuzz.ratio(s1, s2) / 100,
fuzz.partial_ratio(s1, s2) / 100,
fuzz.token_sort_ratio(s1, s2) / 100,
fuzz.partial_token_sort_ratio(s1, s2) / 100,
fuzz.token_set_ratio(s1, s2) / 100,
fuzz.partial_token_set_ratio(s1, s2) / 100,
fuzz.QRatio(s1, s2) / 100,
fuzz.WRatio(s1, s2) / 100]
data['fuzz_WRatio'] = data.apply(lambda x: fuzz.WRatio(str(x['question1']), str(x['question2'])), axis=1)
data['fuzz_partial_ratio'] = data.apply(lambda x: fuzz.partial_ratio(str(x['question1']), str(x['question2'])), axis=1)
#!/usr/bin/env python
# encoding: utf-8
from . import fuzz
from . import utils
import heapq
import logging
from functools import partial
default_scorer = fuzz.WRatio
default_processor = utils.full_process
def extractWithoutOrder(query, choices, processor=default_processor, scorer=default_scorer, score_cutoff=0):
"""Select the best match in a list or dictionary of choices.
Find best matches in a list or dictionary of choices, return a
generator of tuples containing the match and its score. If a dictionary
is used, also returns the key for each match.
Arguments:
query: An object representing the thing we want to find.
choices: An iterable or dictionary-like object containing choices
to be matched against the query. Dictionary arguments of