Transform integers to correctly inflected Ukrainian words (3 → третьої)
Project description
ukr_numbers
[!WARNING]
This is a side project. Sometimes it WILL be wrong, especially for longer numbers. You have been warned.
→
Basics
What?
Convert int numbers (3) to (Ukrainian-language) words in
a specific declination (третій/три/третьому/третьої).
The target declination is given using natural language, in other words you show the target declination instead of describing it.
FOR EXAMPLE, if you need "1→в першому вагоні", "2→в другому вагоні", "-1→в останньому вагоні", you can just enter "першому" as your target declension, and all your integers will be transformed to ordinals in the dative case.
It additionally supports -1 as code for last, the output will be останній declined in the same shape as the numeral would be.
Why?
Declension target as natural language is neat
- I find this easier than remembering the names of everything for an explicit target declension (is it ordinal or cardinal? do I write
dativeordatv? ..) - Automatic templating! I use this package to replace numbers in strings without the need to explicitly parse each one!
More features
Even without the natural language target bit, I found no packages that could convert integers to natural language while:
- handling both cardinals and ordinals
- in different (grammatical) cases
- agreeing to numbers and genders.
Examples
>>> from ukr_numbers import Numbers
>>> Numbers().convert_to_auto(231300,"другий")
WARNING:ukr_numbers.nums:Support for multi-word numbers (231300) is bad, errors are likely to happen, you're warned.
'двістітридцятьоднатисячатрьохсотий'
python3 -m ukr_numbers 8 два
вісім
python3 -m ukr_numbers 8 другої
восьмої
# `-1` is a special number denoting "last":
python3 -m ukr_numbers -1 два #! can't decline it into a number
None
python3 -m ukr_numbers -1 другої
останньої
python3 -m ukr_numbers 124 першою
WARNING:ukr_numbers.nums:Support for multi-word numbers (124) is bad, errors are likely to happen, you're warned.
сто двадцять четвертою
python3 -m ukr_numbers -124 першою
WARNING:ukr_numbers.nums:Support for multi-word numbers (-124) is bad, errors are likely to happen, you're warned.
мінус сто двадцять четвертою
Errors handling
- if "останній"/last can't be inflected in the required way, (e.g. "перший"→"останній" is OK, "один"→??? isn't) None will be returned.
- if anything goes wrong and
graceful_failureis enabled, in the worst case scenario the number itself will be returned as string (2 →'2')
Drawbacks
Explicitly unsupported
- Nouns, like десятка, десяток
- Fractions (дві з половиною тисячі)
Known bugs
- Numbers that take multiple words in Ukrainian (23 → двадцять три) now have weak support, but..
- numbers composed of multiple words in certain cases (pun intended) are only partially correct
- e.g. (currently) 2000000+двома → два мільйонами, not двома мільйонами
- Please write tickets for edge cases you find!
Similar projects
Both used in this package:
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
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 ukr_numbers-0.1.3.tar.gz.
File metadata
- Download URL: ukr_numbers-0.1.3.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.13.1 Linux/6.6.69-1-lts
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f23f12ad07ae1c19c86330814391b05db88f8e6ddf380df8e0fd6eff710de3dc
|
|
| MD5 |
f79c0bc0a5c83f598afaaba8b07b687b
|
|
| BLAKE2b-256 |
3ddc274b917d56515977171d75bbe60de5396e112ca108bea464282a9267dbff
|
File details
Details for the file ukr_numbers-0.1.3-py3-none-any.whl.
File metadata
- Download URL: ukr_numbers-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.13.1 Linux/6.6.69-1-lts
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9724a26d11311fb35cb39b6147088ee4726a89a051b2bf9545945a726a61d1d8
|
|
| MD5 |
2422910c3933dfde828a25bc94becebc
|
|
| BLAKE2b-256 |
8c1605805747f1f6484a449853f660d3700d8bef6cc70ce20daf09fd308fc75b
|