Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 44 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
LanguageOs | |
0.00% |
0 / 44 |
|
0.00% |
0 / 1 |
272 | |
0.00% |
0 / 1 |
convertGrammar | |
0.00% |
0 / 44 |
|
0.00% |
0 / 1 |
272 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | * @author Soslan Khubulov |
20 | */ |
21 | |
22 | use MediaWiki\MainConfigNames; |
23 | use MediaWiki\MediaWikiServices; |
24 | |
25 | /** |
26 | * Ossetian (Ирон) |
27 | * |
28 | * @ingroup Languages |
29 | */ |
30 | class LanguageOs extends Language { |
31 | |
32 | /** |
33 | * Convert from the nominative form of a noun to other cases |
34 | * Invoked with {{grammar:case|word}} |
35 | * |
36 | * Depending on the word, there are four different ways of converting to other cases. |
37 | * 1) Words consist of not Cyrillic letters or is an abbreviation. |
38 | * Then result word is: word + hyphen + case ending. |
39 | * |
40 | * 2) Word consist of Cyrillic letters. |
41 | * 2.1) Word is in plural. |
42 | * Then result word is: word - last letter + case ending. Ending of the allative case here is 'æм'. |
43 | * |
44 | * 2.2) Word is in singular form. |
45 | * 2.2.1) Word ends on consonant. |
46 | * Then result word is: word + case ending. |
47 | * |
48 | * 2.2.2) Word ends on vowel. |
49 | * The resultant word is: word + 'й' + case ending for cases != allative or comitative |
50 | * and word + case ending for allative or comitative. Ending of the allative case here is 'æ'. |
51 | * |
52 | * @param string $word |
53 | * @param string $case |
54 | * @return string |
55 | */ |
56 | public function convertGrammar( $word, $case ) { |
57 | $grammarForms = |
58 | MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::GrammarForms ); |
59 | if ( isset( $grammarForms['os'][$case][$word] ) ) { |
60 | return $grammarForms['os'][$case][$word]; |
61 | } |
62 | # Ending for the allative case |
63 | $end_allative = 'мæ'; |
64 | # Variable for 'j' between vowels |
65 | $jot = ''; |
66 | # Variable for "-" for not Ossetic words |
67 | $hyphen = ''; |
68 | # Variable for ending |
69 | $ending = ''; |
70 | |
71 | # Checking if the $word is in plural form |
72 | if ( preg_match( '/тæ$/u', $word ) ) { |
73 | $word = mb_substr( $word, 0, -1 ); |
74 | $end_allative = 'æм'; |
75 | } elseif ( preg_match( "/[аæеёиоыэюя]$/u", $word ) ) { |
76 | # Works if $word is in singular form. |
77 | # Checking if $word ends on one of the vowels: е, ё, и, о, ы, э, ю, я. |
78 | $jot = 'й'; |
79 | } elseif ( preg_match( "/у$/u", $word ) ) { |
80 | # Checking if $word ends on 'у'. 'У' |
81 | # can be either consonant 'W' or vowel 'U' in Cyrillic Ossetic. |
82 | # Examples: {{grammar:genitive|аунеу}} = аунеуы, {{grammar:genitive|лæппу}} = лæппуйы. |
83 | if ( !preg_match( "/[аæеёиоыэюя]$/u", mb_substr( $word, -2, 1 ) ) ) { |
84 | $jot = 'й'; |
85 | } |
86 | } elseif ( !preg_match( "/[бвгджзйклмнопрстфхцчшщьъ]$/u", $word ) ) { |
87 | $hyphen = '-'; |
88 | } |
89 | |
90 | switch ( $case ) { |
91 | case 'genitive': |
92 | $ending = $hyphen . $jot . 'ы'; |
93 | break; |
94 | |
95 | case 'dative': |
96 | $ending = $hyphen . $jot . 'æн'; |
97 | break; |
98 | |
99 | case 'allative': |
100 | $ending = $hyphen . $end_allative; |
101 | break; |
102 | |
103 | case 'ablative': |
104 | if ( $jot == 'й' ) { |
105 | $ending = $hyphen . $jot . 'æ'; |
106 | } else { |
107 | $ending = $hyphen . $jot . 'æй'; |
108 | } |
109 | break; |
110 | |
111 | case 'inessive': |
112 | break; |
113 | |
114 | case 'superessive': |
115 | $ending = $hyphen . $jot . 'ыл'; |
116 | break; |
117 | |
118 | case 'equative': |
119 | $ending = $hyphen . $jot . 'ау'; |
120 | break; |
121 | |
122 | case 'comitative': |
123 | $ending = $hyphen . 'имæ'; |
124 | break; |
125 | } |
126 | return $word . $ending; |
127 | } |
128 | } |