No Description

Sergey d228767097 Merge pull request #152 from alex-storchak/fix-cases-for-cardinal-num-1000-russian 2 months ago
.github 3f943c33c9 Github Actions tests 2 years ago
bin 1489454f9a PSR code style 2 years ago
src d228767097 Merge pull request #152 from alex-storchak/fix-cases-for-cardinal-num-1000-russian 2 months ago
tests d228767097 Merge pull request #152 from alex-storchak/fix-cases-for-cardinal-num-1000-russian 2 months ago
web 4182da324e Added service description in docs, expose all valuable functions to it 1 year ago
.gitignore 18c897d109 Fix Deprecated: Calling static trait method in php8.1 2 years ago
.rr.yaml 7c3f75de42 Add max_jobs passing for rr 1 year ago
.scrutinizer.yml 965ac53cb1 Create .scrutinizer.yml 6 years ago
.travis.yml aa2930a33b Phpunit 9.5 and some names testing fixes 2 years ago
CONTRIBUTING.md 18bbe5d17f Update CONTRIBUTING.md 5 years ago
Dockerfile 4182da324e Added service description in docs, expose all valuable functions to it 1 year ago
LICENSE.md 0e36003aba Create LICENSE.md 8 years ago
README-en.md 4182da324e Added service description in docs, expose all valuable functions to it 1 year ago
README-ru.md 4182da324e Added service description in docs, expose all valuable functions to it 1 year ago
README.md 302b56636c Update README.md 8 months ago
_config.yml 21297f9fa0 Set theme jekyll-theme-cayman 2 years ago
composer.json aa2930a33b Phpunit 9.5 and some names testing fixes 2 years ago
phpstan.neon 58c6b5e80c Fix the types 4 years ago
phpunit.xml.dist aa2930a33b Phpunit 9.5 and some names testing fixes 2 years ago

README-en.md

English

English morphology shortcuts:

  • morphos\English\NounPluralization::pluralize($word, $count)
  • morphos\English\CardinalNumeralGenerator::generate($number)
  • morphos\English\OrdinalNumeralGenerator::generate($number)
  • morphos\English\TimeSpeller::spellInterval(DateInterval $interval)

English class hierarchy:

morphos\
        English\
                CardinalNumeralGenerator
                OrdinalNumeralGenerator
                NounPluralization
                TimeSpeller

Pluralization

Pluralization a word in English is possible with NounPluralization class:

use function morphos\English\pluralize;
use morphos\English\NounPluralization;

echo '10 '.NounPluralization::pluralize('foot') => '10 feet'
// or if you don't know count of objects

// or you can use shortcut
$n = 1;
echo pluralize($n, 'foot') => '1 foot'
// or API: GET /en/pluralize?count=...&word=...

Numerals

All number creation classes are similar and have one common methods:

  • OrdinalNumeralGenerator::generate($number, bool $short= false) - Generates an ordinal numeral for a number.
    • API: GET /en/ordinal?number=...
  • CardinalNumeralGenerator::generate($number) - Generates a cardinal numeral for a number.
    • API: GET /en/cardinal?number=...

Cardinal

Creation of cardinal numerals in english language (CardinalNumeralGenerator).

use morphos\English\CardinalNumeralGenerator;

// Get text representation of a number:
$number = 4351;

CardinalNumeralGenerator::generate($number) => 'four thousand, three hundred fifty-one'

Ordinal

Creation of ordinal numerals in english language (OrdinalNumeralGenerator).

use morphos\English\OrdinalNumeralGenerator;

// Get text representation of a number or short form:
$number = 4351;

OrdinalNumeralGenerator::generate($number) => 'four thousand, three hundred fifty-first'
// short form of ordinal numeral
OrdinalNumeralGenerator::generate($number, true) => '4351st'

Time units and intervals

You can generate text representation of time interval with TimeSpeller class:

use morphos\English\TimeSpeller;

// generate text representation of 5 years and 2 months
$interval = new DateInterval('P5Y2M');

TimeSpeller::spellInterval($interval) => '5 years 2 months'
TimeSpeller::spellInterval($interval, TimeSpeller::SEPARATE) => '5 years and 2 months'

// or with API: GET /en/time/spellDifference?dateTime=...&options=...&limit=...
// or with API: GET /en/time/spellInterval?interval=...&options=...&limit=...