in(mb_substr($osnova, -1, 1, 'utf-8'), $this->vowels . 'ь')) { $stack[] = mb_substr($osnova, -1, 1, 'utf-8'); $osnova = mb_substr($osnova, 0, mb_strlen($osnova, 'utf-8') - 1, 'utf-8'); } $stacksize = count($stack); $Last = 'Z'; //нульове закінчення if ($stacksize) { $Last = $stack[count($stack) - 1]; } $osnovaEnd = mb_substr($osnova, -1, 1, 'utf-8'); if ($this->in($osnovaEnd, $this->neshyplyachi) and !$this->in($Last, $this->myaki)) { return 1; } elseif ($this->in($osnovaEnd, $this->shyplyachi) and !$this->in($Last, $this->myaki)) { return 2; } else { return 3; } } /* * Повертає перший з кінця голосний * * @return char */ private function FirstLastVowel($word, $vowels) { $length = mb_strlen($word, 'utf-8'); for ($i = $length - 1; $i > 0; $i--) { $char = mb_substr($word, $i, 1, 'utf-8'); if ($this->in($char, $vowels)) { return $char; } } } /* * Повертає основу слова * * @return boolean */ private function getOsnova($word) { $osnova = $word; //Ріжемо слово поки не зустрінемо приголосний while ($this->in(mb_substr($osnova, -1, 1, 'utf-8'), $this->vowels . 'ь')) { $osnova = mb_substr($osnova, 0, mb_strlen($osnova, 'utf-8') - 1, 'utf-8'); } return $osnova; } /* * Функция, которая склоняет имя записаное в $this->firstName, по правилам склонения мужских имен. * * @return boolean */ protected function manFirstName() { /* Українські чоловічі та жіночі імена, що в називному відмінку однини закінчуються на -а (-я), відмінються як відповідні іменники І відміни Примітка 1. Кінцеві приголосні основи г, к, х у жіночих іменах у давальному та місцевому відмінках однини перед закінченням -і змінюються на з, ц, с: Ольга - Ользі, Палажка - Палажці, Солоха - Солосі. Примітка 2. У жіночих іменах типу Одарка, Параска в родовому відмінку множини в кінці основи між приголосними з'являється звук о: Одарок, Парасок */ //Последний символ $LastSymbol = mb_substr($this->firstName, -1, 1, 'utf-8'); //Предпоследний символ $BeforeLast = mb_substr($this->firstName, -2, 1, 'utf-8'); //Останні літера або а або я if ($LastSymbol == 'а') { $this->firstResult = $this->padeg($this->firstName, array($BeforeLast . 'и', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'у', $BeforeLast . 'ою', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'о'), false, true); $this->frule = 101; return true; } elseif ($LastSymbol == 'я') { if ($BeforeLast == 'і') { $this->firstResult = $this->padeg($this->firstName, array('ї', 'ї', 'ю', 'єю', 'ї', 'є'), true); $this->frule = 103; return true; } else { $this->firstResult = $this->padeg($this->firstName, array($BeforeLast . 'і', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'ю', $BeforeLast . 'ею', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'е'), false, true); $this->frule = 102; return true; } } //Примітка 2. Імена, що в називному відмінку закінчуються на -р, у родовому мають закінчення -а: Віктор - Віктора, Макар - Макара, але: Ігор - Ігоря, Лазар - Лазаря. elseif ($LastSymbol == 'р') { if ($this->firstName == 'Ігор' or $this->firstName == 'Лазар') { $this->firstResult = $this->padeg($this->firstName, array('я', 'еві', 'я', 'ем', 'еві', 'е')); $this->frule = 201; return true; } else { $osnova = $this->firstName; if (mb_substr($osnova, -2, 1, 'utf-8') == 'і') { $osnova = mb_substr($osnova, 0, mb_strlen($osnova, 'utf-8') - 2, 'utf-8') . 'о' . mb_substr($osnova, -1, 1, 'utf-8'); } $this->firstResult = $this->padeg($osnova, array('а', 'ові', 'а', 'ом', 'ові', 'е')); $this->frule = 202; return true; } } //2. Українські чоловічі імена, що в називному відмінку однини закінчуються на приголосний та -о , відмінюються як відповідні іменники ІІ відміни. elseif ($this->in($LastSymbol, $this->consonant . 'оь')) { $group = $this->detect2Group($this->firstName); $osnova = $this->getOsnova($this->firstName); //В іменах типу Антін, Нестір, Нечипір, Прокіп, Сидір, Тиміш, Федір голосний і виступає тільки в називному відмінку, у непрямих - о: Антона, Антонові //Чергування і -» о всередині $osLast = mb_substr($osnova, -1, 1, 'utf-8'); if ($osLast != 'й' and mb_substr($osnova, -2, 1, 'utf-8') == 'і' and !in_array(mb_substr(mb_strtolower($osnova, 'utf-8'), -4, 4, 'utf-8'), array('світ', 'цвіт')) and !in_array($this->firstName, array('Гліб'))) { $osnova = mb_substr($osnova, 0, mb_strlen($osnova, 'utf-8') - 2, 'utf-8') . 'о' . mb_substr($osnova, -1, 1, 'utf-8'); } //Випадання букви е при відмінюванні слів типу Орел if (mb_substr($osnova, 0, 1, 'utf-8') == 'О' and $this->FirstLastVowel($osnova, $this->vowels . 'гк') == 'е' and $BeforeLast . $LastSymbol != 'сь') { $delim = mb_strrpos($osnova, 'е', null, 'utf-8'); $osnova = mb_substr($osnova, 0, $delim, 'utf-8') . mb_substr($osnova, $delim + 1, mb_strlen($osnova, 'utf-8') - $delim, 'utf-8'); } if ($group == 1) { //Тверда група $this->firstResult = $this->padeg($osnova, array($osLast . 'а', $osLast . 'ові', $osLast . 'а', $osLast . 'ом', $osLast . 'ові', $this->inverse2($osLast) . 'е'), true); $this->frule = 301; return true; } if ($group == 2) { //Мішана група $this->firstResult = $this->padeg($osnova, array('а', 'еві', 'а', 'ем', 'еві', 'е')); $this->frule = 302; return true; } if ($group == 3) { //М’яка група //Соловей if (mb_substr($this->firstName, -3, 2, 'utf-8') == 'ве') { $osnova = mb_substr($this->firstName, 0, mb_strlen($this->firstName, 'utf-8') - 2, 'utf-8') . '`'; $this->firstResult = $this->padeg($osnova, array('я', 'єві', 'я', 'єм', 'єві', 'ю')); $this->frule = 305; return true; } elseif ($BeforeLast == 'і' or $LastSymbol == 'й') { $this->firstResult = $this->padeg($this->firstName, array('я', 'єві', 'я', 'єм', 'єві', 'ю'), true); $this->frule = 304; return true; } else { $this->firstResult = $this->padeg($osnova, array('я', 'еві', 'я', 'ем', 'еві', 'ю')); $this->frule = 303; return true; } } } else { $this->makeFirstTheSame(); } } /* * Функция, которая склоняет имя записаное в $this->firstName, по правилам склонения женских имен. * * @return boolean */ protected function womanFirstName() { /* Українські чоловічі та жіночі імена, що в називному відмінку однини закінчуються на -а (-я), відмінються як відповідні іменники І відміни Примітка 1. Кінцеві приголосні основи г, к, х у жіночих іменах у давальному та місцевому відмінках однини перед закінченням -і змінюються на з, ц, с: Ольга - Ользі, Палажка - Палажці, Солоха - Солосі. Примітка 2. У жіночих іменах типу Одарка, Параска в родовому відмінку множини в кінці основи між приголосними з'являється звук о: Одарок, Парасок */ //Последний символ $LastSymbol = mb_substr($this->firstName, -1, 1, 'utf-8'); //Предпоследний символ $BeforeLast = mb_substr($this->firstName, -2, 1, 'utf-8'); //Якщо закінчується на ніга -» нога if (mb_substr($this->firstName, -4, 4, 'utf-8') == 'ніга') { $osnova = mb_substr($this->firstName, 0, mb_strlen($this->firstName, 'utf-8')-3, 'utf-8').'о'; $this->firstResult = $this->padeg($osnova, array('ги', 'зі', 'гу', 'гою', 'зі', 'го')); $this->frule = 101; return true; } //Останні літера або а або я elseif ($LastSymbol == 'а') { $this->firstResult = $this->padeg($this->firstName, array($BeforeLast . 'и', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'у', $BeforeLast . 'ою', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'о'), false, true); $this->frule = 101; return true; } elseif ($LastSymbol == 'я') { if ($this->in($BeforeLast, $this->vowels)) { $this->firstResult = $this->padeg($this->firstName, array('ї', 'ї', 'ю', 'єю', 'ї', 'є'), true); $this->frule = 103; return true; } else { $this->firstResult = $this->padeg($this->firstName, array($BeforeLast . 'і', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'ю', $BeforeLast . 'ею', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'е'), false, true); $this->frule = 102; return true; } } //2. Українські жіночі імена, що в називному відмінку однини закінчуються на приголосний, відмінюються як відповідні іменники ІІІ відміни elseif ($this->in($LastSymbol, $this->consonant . 'ь')) { $osnova = $this->getOsnova($this->firstName); $apostrof = ''; $duplicate=''; $osLast = mb_substr($osnova, -1, 1, 'utf-8'); $osBeforeLast = mb_substr($osnova, -2, 1, 'utf-8'); //Чи треба ставити апостроф if ($this->in($osLast, 'мвпбф') and ($this->in($BeforeLast, $this->vowels))) { $apostrof = '`'; } //Чи треба подвоювати if ($this->in($osLast, 'дтзсцлн')) { $duplicate=$osLast; } if ($LastSymbol == 'ь') { $this->firstResult = $this->padeg($osnova, array('і', 'і', 'ь', $duplicate.$apostrof. 'ю', 'і', 'е')); $this->frule = 402; return true; } else { $this->firstResult = $this->padeg($osnova, array('і', 'і', '', $duplicate.$apostrof. 'ю', 'і', 'е')); $this->frule = 401; return true; } } else { $this->makeFirstTheSame(); } } /* * Функция, которая склоняет фамилию записаное в $this->secondName, по правилам склонения мужских фамилий. * * @return boolean */ protected function manSecondName() { /* Українські чоловічі та жіночі імена, що в називному відмінку однини закінчуються на -а (-я), відмінються як відповідні іменники І відміни Примітка 1. Кінцеві приголосні основи г, к, х у жіночих іменах у давальному та місцевому відмінках однини перед закінченням -і змінюються на з, ц, с: Ольга - Ользі, Палажка - Палажці, Солоха - Солосі. Примітка 2. У жіночих іменах типу Одарка, Параска в родовому відмінку множини в кінці основи між приголосними з'являється звук о: Одарок, Парасок */ //Последний символ $LastSymbol = mb_substr($this->secondName, -1, 1, 'utf-8'); //Предпоследний символ $BeforeLast = mb_substr($this->secondName, -2, 1, 'utf-8'); //Якщо закінчується на ий if($BeforeLast.$LastSymbol=='ий' or $BeforeLast.$LastSymbol=='ой') { $this->secondResult = $this->padeg($this->secondName, array('ого', 'ому', 'ого', 'им', 'ому', 'ий'),true,true); $this->srule = 9; return true; } //Останні літера або а або я elseif ($LastSymbol == 'а') { $this->secondResult = $this->padeg($this->secondName, array($BeforeLast . 'и', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'у', $BeforeLast . 'ою', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'о'), false, true); $this->srule = 101; return true; } elseif ($LastSymbol == 'я') { if ($BeforeLast == 'і') { $this->secondResult = $this->padeg($this->secondName, array('ї', 'ї', 'ю', 'єю', 'ї', 'є'), true); $this->srule = 103; return true; } else { $this->secondResult = $this->padeg($this->secondName, array($BeforeLast . 'і', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'ю', $BeforeLast . 'ею', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'е'), false, true); $this->srule = 102; return true; } } //Примітка 2. Імена, що в називному відмінку закінчуються на -р, у родовому мають закінчення -а: Віктор - Віктора, Макар - Макара, але: Ігор - Ігоря, Лазар - Лазаря. elseif ($LastSymbol == 'р') { if ($this->secondName == 'Ігор' or $this->secondName == 'Лазар') { $this->secondResult = $this->padeg($this->secondName, array('я', 'еві', 'я', 'ем', 'еві', 'е')); $this->srule = 201; return true; } else { $osnova = $this->secondName; if (mb_substr($osnova, -2, 1, 'utf-8') == 'і') { $osnova = mb_substr($osnova, 0, mb_strlen($osnova, 'utf-8') - 2, 'utf-8') . 'о' . mb_substr($osnova, -1, 1, 'utf-8'); } $this->secondResult = $this->padeg($osnova, array('а', 'ові', 'а', 'ом', 'ові', 'е')); $this->srule = 202; return true; } } //2. Українські чоловічі імена, що в називному відмінку однини закінчуються на приголосний та -о , відмінюються як відповідні іменники ІІ відміни. elseif ($this->in($LastSymbol, $this->consonant . 'оь')) { $group = $this->detect2Group($this->secondName); $osnova = $this->getOsnova($this->secondName); //В іменах типу Антін, Нестір, Нечипір, Прокіп, Сидір, Тиміш, Федір голосний і виступає тільки в називному відмінку, у непрямих - о: Антона, Антонові //Чергування і -» о всередині $osLast = mb_substr($osnova, -1, 1, 'utf-8'); if ($osLast != 'й' and mb_substr($osnova, -2, 1, 'utf-8') == 'і' and !in_array(mb_substr(mb_strtolower($osnova, 'utf-8'), -4, 4, 'utf-8'), array('світ', 'цвіт')) and !in_array($this->secondName, array('Гліб'))) { $osnova = mb_substr($osnova, 0, mb_strlen($osnova, 'utf-8') - 2, 'utf-8') . 'о' . mb_substr($osnova, -1, 1, 'utf-8'); } //Випадання букви е при відмінюванні слів типу Орел if (mb_substr($osnova, 0, 1, 'utf-8') == 'О' and $this->FirstLastVowel($osnova, $this->vowels . 'гк') == 'е' and $BeforeLast . $LastSymbol != 'сь') { $delim = mb_strrpos($osnova, 'е', null, 'utf-8'); $osnova = mb_substr($osnova, 0, $delim, 'utf-8') . mb_substr($osnova, $delim + 1, mb_strlen($osnova, 'utf-8') - $delim, 'utf-8'); } if ($group == 1) { //Слова що закінчуються на ок if (mb_substr($this->secondName, -2, 2, 'utf-8')=='ок') { $this->secondResult = $this->padeg(mb_substr($this->secondName,0,(mb_strlen($this->secondName, 'utf-8')-2), 'utf-8'), array('ка', 'кові', 'ка', 'ком', 'кові', 'че')); $this->srule = 30101; return true; } //Російські прізвища на ов, ев, єв elseif (in_array(mb_substr($this->secondName, -2, 2, 'utf-8'),array('ов','ев','єв'))) { $this->secondResult = $this->padeg($osnova, array($osLast . 'а', $osLast . 'у', $osLast . 'а', $osLast . 'им', $osLast . 'у', $this->inverse2($osLast) . 'е'), true); $this->srule = 30102; return true; } //Російські прізвища на ін elseif (in_array(mb_substr($this->secondName, -2, 2, 'utf-8'),array('ін'))) { $this->secondResult = $this->padeg($this->secondName, array('а', 'у', 'а', 'ом', 'у', 'е')); $this->srule = 30103; return true; } else { //Тверда група $this->secondResult = $this->padeg($osnova, array($osLast . 'а', $osLast . 'ові', $osLast . 'а', $osLast . 'ом', $osLast . 'ові', $this->inverse2($osLast) . 'е'), true); $this->srule = 301; return true; } } if ($group == 2) { //Мішана група $this->secondResult = $this->padeg($osnova, array('а', 'еві', 'а', 'ем', 'еві', 'е')); $this->srule = 302; return true; } if ($group == 3) { //М’яка група //Соловей if (mb_substr($this->secondName, -2, 2, 'utf-8') == 'ей' and $this->in(mb_substr($this->secondName, -3, 1, 'utf-8'),$this->gubni)) { $osnova = mb_substr($this->secondName, 0, mb_strlen($this->secondName, 'utf-8') - 2, 'utf-8') . '’'; $this->secondResult = $this->padeg($osnova, array('я', 'єві', 'я', 'єм', 'єві', 'ю')); $this->srule = 305; return true; } elseif ($BeforeLast == 'і' or $LastSymbol == 'й') { $this->secondResult = $this->padeg($this->secondName, array('я', 'єві', 'я', 'єм', 'єві', 'ю'), true); $this->srule = 304; return true; } //Слова що закінчуються на ець elseif (mb_substr($this->secondName, -3, 3, 'utf-8')=='ець') { $this->secondResult = $this->padeg(mb_substr($this->secondName,0,(mb_strlen($this->secondName, 'utf-8')-3), 'utf-8').'ц', array('я', 'еві', 'я', 'ем', 'еві', 'ю')); $this->srule = 305; return true; } //Слова що закінчуються на єць яць elseif (in_array(mb_substr($this->secondName, -3, 3, 'utf-8'),array('єць','яць'))) { $this->secondResult = $this->padeg(mb_substr($this->secondName,0,(mb_strlen($this->secondName, 'utf-8')-3), 'utf-8').'йц', array('я', 'еві', 'я', 'ем', 'еві', 'ю')); $this->srule = 306; return true; } else { $this->secondResult = $this->padeg($osnova, array('я', 'еві', 'я', 'ем', 'еві', 'ю')); $this->srule = 303; return true; } } } elseif ($LastSymbol=='і') { $this->secondResult = $this->padeg($this->secondName, array('их', 'им', 'их', 'ими', 'их', 'і'), true); $this->srule = 4; return true; } else { $this->makeSecondTheSame(); } } /* * Функция, которая склоняет фамилию записаное в $this->secondName, по правилам склонения женских фамилий. * * @return boolean */ protected function womanSecondName() { /* Українські чоловічі та жіночі імена, що в називному відмінку однини закінчуються на -а (-я), відмінються як відповідні іменники І відміни Примітка 1. Кінцеві приголосні основи г, к, х у жіночих іменах у давальному та місцевому відмінках однини перед закінченням -і змінюються на з, ц, с: Ольга - Ользі, Палажка - Палажці, Солоха - Солосі. Примітка 2. У жіночих іменах типу Одарка, Параска в родовому відмінку множини в кінці основи між приголосними з'являється звук о: Одарок, Парасок */ //Последний символ $LastSymbol = mb_substr($this->secondName, -1, 1, 'utf-8'); //Предпоследний символ $BeforeLast = mb_substr($this->secondName, -2, 1, 'utf-8'); //Якщо закінчується на ніга -» нога if (mb_substr($this->secondName, -4, 4, 'utf-8') == 'ніга') { $osnova = mb_substr($this->secondName, 0, mb_strlen($this->secondName, 'utf-8')-3, 'utf-8').'о'; $this->secondResult = $this->padeg($osnova, array('ги', 'зі', 'гу', 'гою', 'зі', 'го')); $this->srule = 10101; return true; } //Ті що на ськ elseif ($LastSymbol == 'а' and (in_array(mb_substr($this->secondName, -3, 2, 'utf-8'),array('ов','ев','єв','ив','ьк','тн','рн')))) { $this->secondResult = $this->padeg($this->secondName, array($BeforeLast . 'ої', $BeforeLast . 'ій', $BeforeLast . 'у', $BeforeLast . 'ою', $BeforeLast . 'ій', $BeforeLast . 'о'), false, true); $this->srule = 101; return true; } //Останні літера або а або я elseif ($LastSymbol == 'а') { $this->secondResult = $this->padeg($this->secondName, array($BeforeLast . 'и', $BeforeLast . 'і', $BeforeLast . 'у', $BeforeLast . 'ою', $BeforeLast . 'і', $BeforeLast . 'о'), false, true); $this->srule = 101; return true; } elseif ($LastSymbol == 'я') { if ($this->in($BeforeLast, $this->vowels)) { $this->secondResult = $this->padeg($this->secondName, array('ї', 'ї', 'ю', 'єю', 'ї', 'є'), true); $this->srule = 103; return true; } else { $this->secondResult = $this->padeg($this->secondName, array($BeforeLast . 'і', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'ю', $BeforeLast . 'ею', $this->inverseGKH($BeforeLast) . 'і', $BeforeLast . 'е'), false, true); $this->srule = 102; return true; } } else { $this->makeSecondTheSame(); } } /* * Функция, которая склоняет отчество записаное в $this->secondName, по правилам склонения мужских отчеств. * * @return boolean */ protected function manFatherName() { $ending = mb_substr($this->fatherName, -2, 2, 'utf-8'); if ($ending == 'ич' or $ending== 'іч') { $this->fatherResult = $this->padeg($this->fatherName, array('а', 'у', 'а', 'ем', 'у', 'у'), false, false); return true; } else { $this->makeFatherTheSame(); return false; } } /* * Функция, которая склоняет отчество записаное в $this->fatherName, по правилам склонения женских отчеств. * * @return boolean */ protected function womanFatherName() { if (mb_substr($this->fatherName, -3, 3, 'utf-8') == 'вна') { $this->fatherResult = $this->padeg($this->fatherName, array('и', 'і', 'у', 'ою', 'і', 'о'), true, false); return true; } else { $this->makeFatherTheSame(); return false; } } /* * Автоматическое определение пола * @return void */ protected function genderDetect() { //$this->gender = NCL::$MAN; // мужчина return true; } /* * Определение текущее слово есть фамилией, именем или отчеством * @return integer $number - 1-фамили 2-имя 3-отчество */ protected function detectNamePart($namepart) { return 'N'; } } ?>