Skip to main content

Some collections types for working with rapidfuzz library

Project description

RapidFuzzCollections

License PyPI version Python versions

Description

A collection of datatypes, using rapidfuzz to allow for fuzzy-string matching:

  • RapidFuzzList
  • RapidFuzzTuple
  • RapidFuzzSet
  • RapidFuzzFrozenSet
  • RapidFuzzDict

Default collection's classes extended by methods for fuzzy-string matching.
The main idea is using additional memory for keep normalized values of collection.

Requirements

Installation

Can be installed with pip the following way:

pip install rapidfuzz_collections

License

RapidFuzzCollections is licensed under the MIT license.

Usage

Example:

from rapidfuzz_collections import (
    Normalizer,
    RapidFuzzDict
)


# key is country name, value is country code
data_dict = {
    'Aruba': "ABW",
    'Afghanistan': "AFG",
    'Australia': "AUS",
    'Austria': "AUT",
    # ...
}

normalizer = Normalizer().isinstance_str().strip().casefold().min_length(3)
rapidfuzz_dict = RapidFuzzDict(data_dict, normalizer=normalizer, score_cutoff=90)

rapidfuzz_dict.fuzzy_contains('Gondor')  # False
rapidfuzz_dict.fuzzy_get('Ustralia')  # True
rapidfuzz_dict.fuzzy_get('Ustralia')  # ( 'Australia', 'AUS', )
rapidfuzz_dict.get_fuzzy_scores('Austraia')  # [ ( 'AUS', 94.11764705882352, 'Australia', ), ( 'AUT', 93.33333333333333, 'Austria', ), ( 'ABW', None, 'Aruba', ), ( 'AFG', None, 'Afghanistan', ), ... ]

result = set()
for choice, score, index in rapidfuzz_dict.get_fuzzy_score_iter('Austraia'):
    if score is not None:
        result.add(( choice, score, index, ))
# result == { ( 'AUS', 94.11764705882352, 'Australia', ), ( 'AUT', 93.33333333333333, 'Austria', ), }

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rapidfuzz_collections-0.1.0.tar.gz (14.5 kB view hashes)

Uploaded Source

Built Distribution

rapidfuzz_collections-0.1.0-py3-none-any.whl (3.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page