How to use the uszipcode.pkg.fuzzywuzzy.process.extract function in uszipcode

To help you get started, we’ve selected a few uszipcode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MacHu-GWU / uszipcode-project / tests / pkg / test_fuzzywuzzy.py View on Github external
def test_all():
    text = "playboy"
    choice = ["a cow boy", "play boy", "playboy magazine"]
    res = process.extract(text, choice)
    assert res[0][0] == "play boy"
    assert res[1][0] == "playboy magazine"
    assert res[2][0] == "a cow boy"
github MacHu-GWU / uszipcode-project / uszipcode / search.py View on Github external
"""
        result_state_short_list = list()

        # check if it is a abbreviate name
        if state.upper() in STATE_ABBR_SHORT_TO_LONG:
            result_state_short_list.append(state.upper())

        # if not, find out what is the state that user looking for
        else:
            if best_match:
                state_long, confidence = extractOne(state, self.state_list)
                if confidence >= min_similarity:
                    result_state_short_list.append(
                        STATE_ABBR_LONG_TO_SHORT[state_long])
            else:
                for state_long, confidence in extract(state, self.state_list):
                    if confidence >= min_similarity:
                        result_state_short_list.append(
                            STATE_ABBR_LONG_TO_SHORT[state_long])

        if len(result_state_short_list) == 0:
            message = ("'%s' is not a valid state name, use 2 letter "
                       "short name or correct full name please.")
            raise ValueError(message % state)

        return result_state_short_list
github MacHu-GWU / uszipcode-project / uszipcode / search.py View on Github external
"""
        # find out what is the city that user looking for
        if state:
            state_sort = self.find_state(state, best_match=True)[0]
            city_pool = self.state_to_city_mapper[state_sort.upper()]
        else:
            city_pool = self.city_list

        result_city_list = list()

        if best_match:
            city, confidence = extractOne(city, city_pool)
            if confidence >= min_similarity:
                result_city_list.append(city)
        else:
            for city, confidence in extract(city, city_pool):
                if confidence >= min_similarity:
                    result_city_list.append(city)

        if len(result_city_list) == 0:
            raise ValueError("'%s' is not a valid city name" % city)

        return result_city_list