Skip to content

Commit

Permalink
Merge branch 'master' of github.com:anoriar/Morphos into fix-male-ek-etz
Browse files Browse the repository at this point in the history
  • Loading branch information
anoriar committed Sep 26, 2024
2 parents 4ad81d6 + 1065704 commit 015f123
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Russian/FirstNamesInflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ public static function getCases($name, $gender = null)
*/
public static function isMutable($name, $gender = null)
{
if (S::length($name) === 1) {
return false;
}

$name = S::lower($name);

if (in_array($name, static::$immutableNames, true)) {
Expand Down
22 changes: 21 additions & 1 deletion src/Russian/LastNamesInflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public static function getCase($name, $case, $gender = null)
*/
public static function isMutable($name, $gender = null)
{
if (S::length($name) === 1) {
return false;
}

$name = S::lower($name);

if ($gender === null) {
$gender = static::detectGender($name);
}
Expand Down Expand Up @@ -176,7 +181,9 @@ public static function getCases($name, $gender = null)
// similar to next if
if (in_array(S::slice($name, -2), ['ой', 'ый', 'ий'], true)) {
$last_consonant = S::slice($name, -3, -2);
$last_sonority = (RussianLanguage::isSonorousConsonant($last_consonant) && $last_consonant !== 'н') || $last_consonant === 'ц';
$last_sonority = (RussianLanguage::isSonorousConsonant($last_consonant) &&
in_array($last_consonant, ['н', 'в'], true) === false) || $last_consonant === 'ц';

if ($last_sonority) {
$prefix = S::name(S::slice($name, 0, -1));
return [
Expand Down Expand Up @@ -212,6 +219,19 @@ public static function getCases($name, $gender = null)
];
}

if (S::length($name) > 3 && in_array(S::slice($name, -2), ['ок'], true)) {
$prefix = S::name(S::slice($name, 0, -2)) . S::slice($name, -1);

return [
static::IMENIT => S::name($name),
static::RODIT => $prefix . 'а',
static::DAT => $prefix . 'у',
static::VINIT => $prefix . 'а',
static::TVORIT => $prefix . 'ом',
static::PREDLOJ => $prefix . 'е',
];
}

if (S::length($name) > 3 && in_array(S::slice($name, -2), ['ек', 'ец'], true)) {
$last_consonant = S::slice($name, -3, -2);
if (in_array($last_consonant, ['л'])) {
Expand Down
5 changes: 5 additions & 0 deletions src/Russian/MiddleNamesInflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public static function detectGender($name)
*/
public static function isMutable($name, $gender = null)
{
if (S::length($name) === 1) {
return false;
}

$name = S::lower($name);

if (in_array(S::slice($name, -2), ['ич', 'на'], true)) {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Russian/FirstNamesInflecionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ public function immutableNamesProvider()
['Грегори', FirstNamesInflection::MALE],
['Гиви', FirstNamesInflection::MALE],
['Франсуа', FirstNamesInflection::MALE],
['А', NamesInflection::FEMALE],
];
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Russian/LastNamesInflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function lastNamesProvider()
return [
['Смирнов', NamesInflection::MALE, 'Смирнова', 'Смирнову', 'Смирнова', 'Смирновым', 'Смирнове'],
['Кромской', NamesInflection::MALE, 'Кромского', 'Кромскому', 'Кромского', 'Кромским', 'Кромском'],
['Ольховой', NamesInflection::MALE, 'Ольхового', 'Ольховому', 'Ольхового', 'Ольховым', 'Ольховом'],
['Ус', NamesInflection::MALE, 'Уса', 'Усу', 'Уса', 'Усом', 'Усе'],
['Кузьмич', NamesInflection::MALE, 'Кузьмича', 'Кузьмичу', 'Кузьмича', 'Кузьмичом', 'Кузьмиче'],
['Берг', NamesInflection::MALE, 'Берга', 'Бергу', 'Берга', 'Бергом', 'Берге'],
Expand All @@ -77,6 +78,9 @@ public function lastNamesProvider()
// ['Зоя', NamesInflection::FEMALE, 'Зои', 'Зое', 'Зою', 'Зоей', 'Зое'],
// ['Молодыха', NamesInflection::FEMALE, 'Молодыхи', 'Молодыхе', 'Молодыху', 'Молодыхой', 'Молодыхе'],
['Стальная', NamesInflection::FEMALE, 'Стальной', 'Стальной', 'Стальную', 'Стальной', 'Стальной'],
['Янушонок', NamesInflection::MALE, 'Янушонка', 'Янушонку', 'Янушонка', 'Янушонком', 'Янушонке'],
['Оборок', NamesInflection::MALE, 'Оборка', 'Оборку', 'Оборка', 'Оборком', 'Оборке'],
['Бок', NamesInflection::MALE, 'Бока', 'Боку', 'Бока', 'Боком', 'Боке'],
['Неборачек', NamesInflection::MALE, 'Неборачка', 'Неборачку', 'Неборачка', 'Неборачком', 'Неборачке'],
['Городец', NamesInflection::MALE, 'Городца', 'Городцу', 'Городца', 'Городцом', 'Городце'],
['Малец', NamesInflection::MALE, 'Мальца', 'Мальцу', 'Мальца', 'Мальцом', 'Мальце'],
Expand Down Expand Up @@ -121,6 +125,7 @@ public function immutableNamesProvider()
['Хитрово', NamesInflection::MALE],
['Бози', NamesInflection::MALE],
['Цой', NamesInflection::FEMALE],
['А', NamesInflection::FEMALE],
];
}
}
16 changes: 16 additions & 0 deletions tests/Russian/MiddleNamesInflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use morphos\NamesInflection;
use morphos\Russian\Cases;
use morphos\Russian\LastNamesInflection;
use morphos\Russian\MiddleNamesInflection;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -90,4 +91,19 @@ public function testGetCase($name, $gender, $case2)
{
$this->assertEquals($case2, MiddleNamesInflection::getCase($name, Cases::RODIT, $gender));
}

/**
* @dataProvider immutableNamesProvider()
*/
public function testImmutable($name, $gender)
{
$this->assertFalse(MiddleNamesInflection::isMutable($name, $gender));
}

public function immutableNamesProvider()
{
return [
['А', NamesInflection::FEMALE],
];
}
}

0 comments on commit 015f123

Please sign in to comment.