Convert numbers to Hebrew.
Project description
hebrew-numbers
Overview
This library provides a comprehensive solution for working with Hebrew numbers in various contexts. Hebrew has unique and complex rules for number representation that vary based on gender, definiteness, and usage context. This library aims to simplify these complexities by providing intuitive functions for converting numerical values to their proper Hebrew textual representation.
Usage
Install the package using pip, or with a dependency manager like uv:
pip install hebrew-numbers
and import the package in your code:
import hebrew_numbers
Indefinite Number -- מספר סתמי
When counting without specific nouns, but rather in a general sense, we use the indefinite number.
>>> [indefinite_number(n) for n in [1, 2, 3]]
['אחת', 'שתיים', 'שָלוש']
>>> indefinite_number(0)
'אפס'
>>> indefinite_number(-3)
'מינוס שָלוש'
>>> indefinite_number(1234567890)
'מיליארד מאתיים שלושים וארבעה מיליון חמש מאות שישים ושבעה אלף שמונֶה מאות ותשעים'
Ordinal Number -- מספר סודר
A number that describes the position of an object in a series is called an ordinal number. This number can be masculine (זכר) or feminine (נקבה).
>>> [ordinal_number(n, "M") for n in [1, 2, 3]]
['ראשון', 'שני', 'שלישי']
>>> [ordinal_number(n, "F") for n in [1, 2, 3]]
['ראשונה', 'שנייה', 'שלישית']
Cardinal Number -- מספר מונה
Usage with noun
Cardinal numbers are used to indicate quantities. Their form depends on the following factors:
- The gender of the noun (masculine or feminine).
- Whether the noun is definite (מיודע) or indefinite (סתמי).
To specify a quantity with a noun, use count_noun(n, singular_form, plural_form, gender, definite)
.
Number | Masculine, Indefinite | Masculine, Definite | Feminine, Indefinite | Feminine, Definite |
---|---|---|---|---|
n |
count_noun(n, "ילד", "ילדים", "M", definite=False) |
count_noun(n, "הילד", "הילדים", "M", definite=True) |
count_noun(n, "ילדה", "ילדות", "F", definite=False) |
count_noun(n, "הילדה", "הילדות", "F", definite=True) |
1 | ילד אֶחָד | הילד האֶחָד | ילדה אחת | הילדה האחת |
2 | שני ילדים | שני הילדים | שתי ילדות | שתי הילדות |
3 | שלושה ילדים | שלושת הילדים | שָלוש ילדות | שְלוש הילדות |
If you only need the numerical prefix, use count_prefix(n, gender, definite)
.
Absolute and Construct Forms
The number itself can be masculine (זכר) or feminine (נקבה), and absolute (נפרד) or construct (נסמך).
If you know the gender and construct state, you can the number itself with cardinal_number(n, gender, construct)
Number | Masculine, Absolute | Masculine, Construct | Feminine, Absolute | Feminine, Construct |
---|---|---|---|---|
n |
cardinal_number(n, "M", construct=False) |
cardinal_number(n, "M", construct=True) |
cardinal_number(n, "F", construct=False) |
cardinal_number(n, "F", construct=True) |
1 | אֶחָד | אַחַד | אחת | אחת |
2 | שניים | שני | שתיים | שתי |
3 | שלושה | שלושת | שָלוש | שְלוש |
Notes
- The indefinite number is the feminine-absolute form.
- The form of the number following "פי" (times/multiplied by) to be in the masculine-absolute form: פי שניים, פי שלושה, פי ארבעה.
- Use the masculine-absolute form to indicate the days of the month: אחד בכסלו, עשרה בטבת, אחד באפריל, שניים ביוני.
Development
Getting started
Tests and code quality
- use
uv run just format
to format the code. - use
uv run just lint
to see linting errors. - use
uv run just test
to run tests. - use
uv run just check
to run all the checks (format, lint, test, and pre-commit). - Run a specific tool directly, with
uv run pytest
/ruff
/mypy
/black
/...
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file hebrew_numbers-0.1.0.tar.gz
.
File metadata
- Download URL: hebrew_numbers-0.1.0.tar.gz
- Upload date:
- Size: 77.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78b29562fb0a459fe57bfa5405cd0ede1fae3301b6bce2b2304b2428bdeda24e |
|
MD5 | 60776fa323bd5adf51f763cf9e74199a |
|
BLAKE2b-256 | 4259ffacfe4deddcf1977cde4416e6841d2684432d5e71331ad2091c0622cbca |
File details
Details for the file hebrew_numbers-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: hebrew_numbers-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccf19c8cf93b4538066a8cb6b6e2ea6e158e5ae53d6f35be46f56805b43ea4ab |
|
MD5 | 6951f4954109e1de0ca165bdbe88efa5 |
|
BLAKE2b-256 | 30c7cdb26dc714f82975dd5da257e7f890a296dc9c9b2636004e2421d6b5ed82 |