Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| GrammarOs | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
240 | |
0.00% |
0 / 1 |
| process | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
240 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace Wikimedia\Leximorph\Handler\Overrides\Grammar; |
| 8 | |
| 9 | use Wikimedia\Leximorph\Handler\Overrides\IGrammarTransformer; |
| 10 | |
| 11 | /** |
| 12 | * GrammarOs |
| 13 | * |
| 14 | * Implements grammar transformations for Ossetic (os). |
| 15 | * |
| 16 | * These rules don't cover the whole grammar of the language. |
| 17 | * This logic was originally taken from MediaWiki Core. |
| 18 | * Thanks to all contributors. |
| 19 | * |
| 20 | * @since 1.45 |
| 21 | * @author Soslan Khubulov |
| 22 | * @author Doğu Abaris (abaris@null.net) |
| 23 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
| 24 | */ |
| 25 | class GrammarOs implements IGrammarTransformer { |
| 26 | /** |
| 27 | * Applies Ossetic-specific grammatical transformations. |
| 28 | * |
| 29 | * Convert from the nominative form of a noun to other cases |
| 30 | * Invoked with {{grammar:case|word}} |
| 31 | * |
| 32 | * Depending on the word, there are four different ways of converting to other cases. |
| 33 | * 1) Words consist of not Cyrillic letters or is an abbreviation. |
| 34 | * Then result word is: word + hyphen + case ending. |
| 35 | * |
| 36 | * 2) Word consist of Cyrillic letters. |
| 37 | * 2.1) Word is in plural. |
| 38 | * Then result word is: word - last letter + case ending. Ending of the allative case here is 'æм'. |
| 39 | * |
| 40 | * 2.2) Word is in singular form. |
| 41 | * 2.2.1) Word ends on consonant. |
| 42 | * Then result word is: word + case ending. |
| 43 | * |
| 44 | * 2.2.2) Word ends on vowel. |
| 45 | * The resultant word is: word + 'й' + case ending for cases != allative or comitative |
| 46 | * and word + case ending for allative or comitative. Ending of the allative case here is 'æ'. |
| 47 | * |
| 48 | * @param string $word The word to process. |
| 49 | * @param string $case The grammatical case. |
| 50 | * |
| 51 | * @since 1.45 |
| 52 | * @return string The processed word. |
| 53 | */ |
| 54 | public function process( string $word, string $case ): string { |
| 55 | # Ending for the allative case |
| 56 | $end_allative = 'мæ'; |
| 57 | # Variable for 'j' between vowels |
| 58 | $jot = ''; |
| 59 | # Variable for "-" for not Ossetic words |
| 60 | $hyphen = ''; |
| 61 | # Variable for ending |
| 62 | $ending = ''; |
| 63 | |
| 64 | # Checking if the $word is in plural form |
| 65 | if ( preg_match( '/тæ$/u', $word ) ) { |
| 66 | $word = mb_substr( $word, 0, -1 ); |
| 67 | $end_allative = 'æм'; |
| 68 | } elseif ( preg_match( "/[аæеёиоыэюя]$/u", $word ) ) { |
| 69 | # Works if $word is in singular form. |
| 70 | # Checking if $word ends on one of the vowels: е, ё, и, о, ы, э, ю, я. |
| 71 | $jot = 'й'; |
| 72 | } elseif ( preg_match( "/у$/u", $word ) ) { |
| 73 | # Checking if $word ends on 'у'. 'У' |
| 74 | # can be either consonant 'W' or vowel 'U' in Cyrillic Ossetic. |
| 75 | # Examples: {{grammar:genitive|аунеу}} = аунеуы, {{grammar:genitive|лæппу}} = лæппуйы. |
| 76 | if ( !preg_match( "/[аæеёиоыэюя]$/u", mb_substr( $word, -2, 1 ) ) ) { |
| 77 | $jot = 'й'; |
| 78 | } |
| 79 | } elseif ( !preg_match( "/[бвгджзйклмнопрстфхцчшщьъ]$/u", $word ) ) { |
| 80 | $hyphen = '-'; |
| 81 | } |
| 82 | |
| 83 | switch ( $case ) { |
| 84 | case 'genitive': |
| 85 | $ending = $hyphen . $jot . 'ы'; |
| 86 | break; |
| 87 | |
| 88 | case 'dative': |
| 89 | $ending = $hyphen . $jot . 'æн'; |
| 90 | break; |
| 91 | |
| 92 | case 'allative': |
| 93 | $ending = $hyphen . $end_allative; |
| 94 | break; |
| 95 | |
| 96 | case 'ablative': |
| 97 | if ( $jot == 'й' ) { |
| 98 | $ending = $hyphen . $jot . 'æ'; |
| 99 | } else { |
| 100 | $ending = $hyphen . $jot . 'æй'; |
| 101 | } |
| 102 | break; |
| 103 | |
| 104 | case 'superessive': |
| 105 | $ending = $hyphen . $jot . 'ыл'; |
| 106 | break; |
| 107 | |
| 108 | case 'equative': |
| 109 | $ending = $hyphen . $jot . 'ау'; |
| 110 | break; |
| 111 | |
| 112 | case 'comitative': |
| 113 | $ending = $hyphen . 'имæ'; |
| 114 | break; |
| 115 | |
| 116 | default: |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | return $word . $ending; |
| 121 | } |
| 122 | } |