Skip to main content

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.2

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.

Download files

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

Source Distribution

ngram-3.3.0.tar.gz (8.8 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: ngram-3.3.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ngram-3.3.0.tar.gz
Algorithm Hash digest
SHA256 ea848fa3dfabbd5a1afdee4fe1871337c6c6a7225cac9ec5f2de8223ac2223db
MD5 7874f4b7daba5680e9dadda889ebf007
BLAKE2b-256 78ff4a7a88047fe50ab9806446488730ab3f74fc277be2357ac46f6f0c9b0227

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