Singularize or pluralize a given word using a pre-defined list of rules
Project description
Why this project?
This repo is simply a Python port of https://github.com/blakeembrey/pluralize which has > 1.4m github usages and 3.5 million downloads per week when I evaluating different libraries.
This module uses a pre-defined list of rules, applied in order, to singularize or pluralize a given word. There are many cases where this is useful, such as any automation based on user input. For applications where the word(s) are known ahead of time, you can use a simple ternary (or function) which would be a much lighter alternative.
I have compared the following alternatives and found https://github.com/blakeembrey/pluralize is the best one for me (most accurate), so ported it into the Python world.
- TextBlob: https://github.com/sloria/TextBlob
- inflect: https://github.com/jazzband/inflect
- NLTK Wordnet: https://www.nltk.org/howto/wordnet.html
Installation
pip install pluralizer
Usage
from pluralizer import Pluralizer
pluralizer = Pluralizer()
assert pluralizer.pluralize('apple', 1, False) == 'apple'
assert pluralizer.pluralize('apple', 1, True) == '1 apple'
assert pluralizer.pluralize('apple', 2, False) == 'apples'
assert pluralizer.pluralize('apple', 2, True) == '2 apples'
assert pluralizer.plural('apple') == 'apples'
assert pluralizer.singular('apples') == 'apple'
assert pluralizer.isPlural('apples') == True
assert pluralizer.isPlural('apple') == False
assert pluralizer.isSingular('apples') == False
assert pluralizer.isSingular('apple') == True
License
MIT
All credits to https://github.com/blakeembrey/pluralize.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pluralizer-2.0.0.tar.gz.
File metadata
- Download URL: pluralizer-2.0.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d48412c17397f52fb5b5485cbb5427b687d6e21daca0e65d9dfc16a989ec0c9
|
|
| MD5 |
f095539233d687bcab749708f7ea9447
|
|
| BLAKE2b-256 |
77b3bf7fe8341d5eb6b86f9b99d0419efe431b83be105db4d70646138fbadd30
|
File details
Details for the file pluralizer-2.0.0-py3-none-any.whl.
File metadata
- Download URL: pluralizer-2.0.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
282e536f989cc30eeb4db69b63539030b2e50f1c93d737b783a924fe486d8141
|
|
| MD5 |
7c5cfb8c3888b58e42e7255512725fb1
|
|
| BLAKE2b-256 |
8eefac208cfa9d708d246aca64192fca9bd6518618998c4efa8e765ceac34405
|