Skip to main content

A `set` subclass providing fuzzy search based on N-grams.

Reason this release was yanked:

Missing ngram.py due to setup.cfg error

Project description

The NGram class extends the Python ‘set’ class with efficient fuzzy search for members by means of an N-gram similarity measure. It also has static methods to compare a pair of strings.

The N-grams are character based not word-based, and the class does not implement a language model, merely searching for members by string similarity.

The documentation, tutorial and release notes are on the PyPI package documentation site. Please use the GitHub issue tracker to report issues.

Installation

Install python-ngram from PyPI using pip installer:

pip install ngram

It should run on Python 2.6, Python 2.7 and Python 3.6

How does it work?

The set stores arbitrary items, but for non-string items a key function (such as str) must be specified to provide a string represenation. The key function can also be used to normalise string items (e.g. lower-casing) prior to N-gram indexing.

To index a string it pads the string with a specified dummy character, then splits it into overlapping substrings of N (default N=3) characters in length and associates each N-gram to the items that use it.

To find items similar to a query string, it splits the query into N-grams, collects all items sharing at least one N-gram with the query, and ranks the items by score based on the ratio of shared to unshared N-grams between strings.

History

In 2007, Michel Albert (exhuma) wrote the python-ngram module based on Perl’s String::Trigram module by Tarek Ahmed, and committed the code for 2.0.0b2 to a now-disused Sourceforge subversion repo.

Since late 2008, Graham Poulter has maintained python-ngram, initially refactoring it to build on the set class, and also adding features, documentation, tests, performance improvements and Python 3 support.

Development

Development takes place on Github. On checking out the repo run tox to build the Sphinx documentation and run tests. Run pip install -e . to install the module in editable mode, inside a virtualenv.

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

ngram-4.0.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ngram-4.0.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file ngram-4.0.0.tar.gz.

File metadata

  • Download URL: ngram-4.0.0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for ngram-4.0.0.tar.gz
Algorithm Hash digest
SHA256 992b0eb9aa2764cf6c3a85c6e36d6b54e438e1ebf56d13ca5b3c222dbf395dc7
MD5 0dce8d6a65f1fe797083f841f01a00b6
BLAKE2b-256 f183117777501a07e34fa47792ce7981e6b31fcf01b8dc77be1199b98830cdae

See more details on using hashes here.

File details

Details for the file ngram-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: ngram-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.11

File hashes

Hashes for ngram-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 393a4e69ecd65ab42f7e8fabc989f71e462ad883304afe9329efba49fbc3c7eb
MD5 68771ccbc92c7f183eff3ec81e4ed051
BLAKE2b-256 bc816bb904286acadf53ab7192cee39f486f8267820ee620afb8b8e5306f506e

See more details on using hashes here.

Supported by

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