diff --git a/project-structure.md b/project-structure.md index eda6d2d5..e39e0d98 100644 --- a/project-structure.md +++ b/project-structure.md @@ -10,15 +10,18 @@ ├─ internal.py ├─ time.py * ├─ parse.py * + ├─ utils.py * ├─ lang/ (localized functions and basic language data) │ ├─ common_data_<>.py (data structures related to language '<>') │ ├─ format_<>.py (localized formatters) │ ├─ parse_<>.py (localized parsers) + │ ├─ utils_<>.py (localized utilities) ├─ res/ (fully localized data, 'en-us' vs 'en-au' and etc.) │ ├─ text/ │ │ ├─ / │ │ │ ├─ date_time.json - │ │ │ ├─ common words + │ │ │ ├─ durations.json + │ │ │ ├─ connectors.json ---- diff --git a/readme.md b/readme.md index 753340a9..40510428 100644 --- a/readme.md +++ b/readme.md @@ -21,6 +21,9 @@ Lingua Franca (_noun_)
- [Extract numbers](#extract-numbers) - [Extract durations](#extract-durations) - [Extract dates](#extract-dates) + - [Utils](#utils) + - [Get plural category](#get-plural-category) + - [Get plural form](#get-plural-form) - [Contributing to this project](#contributing-to-this-project) - [0. Sign a Contributor Licensing Agreement](#0-sign-a-contributor-licensing-agreement) - [1. Setup a local copy of the project](#1-setup-a-local-copy-of-the-project) @@ -211,6 +214,33 @@ testExtract("on the evening of june 5th 2017 remind me to call my mother", ``` +## Utils + +Common utils that can be used for formatting and parsing + +### Get plural category + +get one of [Unicode CLDR plural categories](http://cldr.unicode.org/index/cldr-spec/plural-rules) according +to the [pluralization rules](https://unicode-org.github.io/cldr-staging/charts/37/supplemental/language_plural_rules.html) of the language + +```python +from lingua_franca.utils import get_plural_category + +assert get_plural_category(1) == "one" +assert get_plural_category(2) == "other" + +assert get_plural_category(1, type="ordinal") == "one" +assert get_plural_category(2, type="ordinal") == "two" +assert get_plural_category(3, type="ordinal") == "few" +assert get_plural_category(4, type="ordinal") == "other" +``` + +### Get plural form + +pluralize the word + +*Note:* Not implemented yet in any language. + ## Getting Started ### Loading a language @@ -329,6 +359,7 @@ Each language should have two test files: - `test_format_lang.py` - `test_parse_lang.py` +- `test_utils_lang.py` ### 4. Run tests to confirm they fail @@ -348,6 +379,8 @@ Now we can add our new code. There are three main files for each language: All formatting functions for this language. - `parse_lang.py` All parsing functions for this language. +- `utils_lang.py` + All util functions for this language. Since we have already written our unit tests, we can run these regularly to see our progress.