Esempio n. 1
0
def name_fuzzy_partial_score(product1, product2):
    product1 = _filter_name(product1)
    product2 = _filter_name(product2)

    s1 = utils.full_process(product1)
    s2 = utils.full_process(product2)
    return partial_ratio(s1, s2)
Esempio n. 2
0
def WRatio(s1, s2):
    p1 = utils.full_process(s1)
    p2 = utils.full_process(s2)
    if not utils.validate_string(p1): return 0
    if not utils.validate_string(p2): return 0

    # should we look at partials?
    try_partial = True
    unbase_scale = .95
    partial_scale = .90

    base = ratio(p1, p2)
    len_ratio = float(max(len(p1), len(p2))) / min(len(p1), len(p2))

    # if strings are similar length, don't use partials
    if len_ratio < 1.5: try_partial = False

    # if one string is much much shorter than the other
    if len_ratio > 8: partial_scale = .6

    if try_partial:
        partial = partial_ratio(p1, p2) * partial_scale
        ptsor = partial_token_sort_ratio(p1, p2) * unbase_scale * partial_scale
        ptser = partial_token_set_ratio(p1, p2) * unbase_scale * partial_scale

        return int(max(base, partial, ptsor, ptser))
    else:
        tsor = token_sort_ratio(p1, p2) * unbase_scale
        tser = token_set_ratio(p1, p2) * unbase_scale

        return int(max(base, tsor, tser))
Esempio n. 3
0
def QRatio(s1, s2):
    if not utils.validate_string(s1): return 0
    if not utils.validate_string(s2): return 0

    p1 = utils.full_process(s1)
    p2 = utils.full_process(s2)

    return ratio(p1, p2)
Esempio n. 4
0
def brand_fuzzy_match(product_name, brand):
    from product_spiders.fuzzywuzzy.fuzz import ratio, partial_ratio
    from product_spiders.fuzzywuzzy import utils

    s1 = utils.full_process(product_name)
    s2 = utils.full_process(brand)

    if ratio(s1, s2) > 80:
        return True
    if partial_ratio(s1, s2) > 80:
        return True
    return False
Esempio n. 5
0
 def testCaseInsensitive(self):
     self.assertNotEqual(ratio(self.s1, self.s2),100)
     self.assertEqual(ratio(utils.full_process(self.s1), utils.full_process(self.s2)),100)
Esempio n. 6
0
 def test_fullProcess(self):
     for s in self.mixed_strings:
         utils.full_process(s)