wapmorgan / morphos
A morphological solution for Russian and English language written completely in PHP. Provides classes to inflect personal names, geographical names, decline and pluralize nouns, generate cardinal and ordinal numerals, spell out money amounts and time.
Installs: 888 945
Dependents: 10
Suggesters: 0
Security: 0
Stars: 787
Watchers: 41
Forks: 105
Open Issues: 17
Requires
- php: >=5.4.0
- ext-mbstring: *
Requires (Dev)
- php: >=7.3
- phpunit/phpunit: ~9.5.20
Suggests
- ext-readline: For using interactive version of script
- dev-master
- 3.2.29
- 3.2.28
- 3.2.27
- 3.2.26
- 3.2.25
- 3.2.24
- 3.2.23
- 3.2.22
- 3.2.21
- 3.2.20
- 3.2.19
- 3.2.18
- 3.2.17
- 3.2.16
- 3.2.15
- 3.2.14
- 3.2.13
- 3.2.12
- 3.2.11
- 3.2.10
- 3.2.9
- 3.2.8
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.9
- 2.2.8
- 2.2.7
- 2.2.6
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.0
This package is auto-updated.
Last update: 2024-10-26 12:51:11 UTC
README
A morphological solution for Russian and English language written completely in PHP and delivered as a PHP library or docker image to integrate in non-PHP stack.
Features
- [✓] Inflection of Personal names (Фамилия, Имя, Отчество) (Russian)
- [✓] Inflection of Geographical names (Страны/Города) (Russian)
- [✓] Declension/Pluralization of nouns and adjectives (Russian, English)
- [✓] Generation numerals of numbers (количественные и порядковые) (Russian, English)
- [✓] Spelling out amounts of money (Russian)
- [✓] Spelling out time units and intervals (Russian, English)
Table of contents
- Installation
- Quick start
- Documentation
- Contributing
Installation
As PHP library
- Download library through composer:
composer require wapmorgan/morphos
or install via adapter:
- Adapter for Blade: wapmorgan/morphos-blade
- Adapter for Twig: wapmorgan/morphos-twig
- Adapter for Yii2: wapmorgan/yii2-inflection
As a separate service
The server starts in a container from docker image and listens 8080 port for GET-requests.
Integrate service into your stack (for example, docker compose)
services: morphos: image: wapmorgan/morphos:3.2.29 ports: - 8093:8080
or standalone container:
docker run --env NUM_WORKERS=4 --rm --publish 8093:8080 -v wapmorgan/morphos:3.2.29
Tip: adjust NUM_WORKERS
env variable if you will send a lot of load to service. By default, it's 4.
There are API: marks in documentation for functions, that exposed as service endpoints. Just pass them the same arguments as to PHP-functions/methods.
Quick Start
Russian
// Inflect russian names: morphos\Russian\inflectName('Иванов Петр', 'родительный') => 'Иванова Петра' // Inflect geographical names: morphos\Russian\GeographicalNamesInflection::getCase('Москва', 'родительный') => 'Москвы' // Pluralize russian nouns and adjectives: morphos\Russian\pluralize(10, 'новый дом') => '10 новых домов' // Generate russian cardinal numerals: morphos\Russian\CardinalNumeralGenerator::getCase(567, 'именительный') => 'пятьсот шестьдесят семь' // Generate russian ordinal numerals: morphos\Russian\OrdinalNumeralGenerator::getCase(961, 'именительный') => 'девятьсот шестьдесят первый' // Generate russian time difference morphos\Russian\TimeSpeller::spellDifference(time() + 3600, morphos\TimeSpeller::DIRECTION) => 'через 1 час' // other functions described in README-ru.md
English
// Pluralize english nouns: morphos\English\pluralize(10, 'house') => '10 houses' // Generate english cardinal numerals: morphos\English\CardinalNumeralGenerator::generate(567) => 'five hundred sixty-seven' // Generate english ordinal numerals: morphos\English\OrdinalNumeralGenerator::generate(961) => 'nine hundred sixty-first' // Generate english time difference morphos\English\TimeSpeller::spellDifference(time() + 3600, morphos\TimeSpeller::DIRECTION) => 'in 1 hour'
Documentation
- Русская морфология в файле README-ru.md
- English morphology in file README-en.md
Contributing
See CONTRIBUTING.md for this.