Singularize or pluralize a given word useing 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 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
Hashes for pluralizer-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87cff86ddf9b2c9612a331ef24e16ffd4584b75d76a632f8ae0611bacd76f7e4 |
|
MD5 | e96c4f5682c29761f61764185d50475b |
|
BLAKE2b-256 | 9557822c364a6c020e8be6c9b8a81c8c039a07dee81a17fa246e24dd25eb4234 |