1
|
|
|
<?php
|
2
|
|
|
namespace morphos;
|
3
|
|
|
|
4
|
|
|
trait Russian {
|
5
|
|
|
static public $vowels = array(
|
6
|
|
|
'А',
|
7
|
|
|
'Е',
|
8
|
|
|
'Ё',
|
9
|
|
|
'И',
|
10
|
|
|
'О',
|
11
|
|
|
'У',
|
12
|
|
|
'Ы',
|
13
|
|
|
'Э',
|
14
|
|
|
'Ю',
|
15
|
|
|
'Я',
|
16
|
|
|
);
|
17
|
|
|
|
18
|
|
|
static public $consonants = array(
|
19
|
|
|
'Б',
|
20
|
|
|
'В',
|
21
|
|
|
'Г',
|
22
|
|
|
'Д',
|
23
|
|
|
'Ж',
|
24
|
|
|
'З',
|
25
|
|
|
'Й',
|
26
|
|
|
'К',
|
27
|
|
|
'Л',
|
28
|
|
|
'М',
|
29
|
|
|
'Н',
|
30
|
|
|
'П',
|
31
|
|
|
'Р',
|
32
|
|
|
'С',
|
33
|
|
|
'Т',
|
34
|
|
|
'Ф',
|
35
|
|
|
'Х',
|
36
|
|
|
'Ц',
|
37
|
|
|
'Ч',
|
38
|
|
|
'Ш',
|
39
|
|
|
'Щ',
|
40
|
|
|
);
|
41
|
|
|
|
42
|
|
|
static public $pairs = array(
|
43
|
|
|
'Б' => 'П',
|
44
|
|
|
'В' => 'Ф',
|
45
|
|
|
'Г' => 'К',
|
46
|
|
|
'Д' => 'Т',
|
47
|
|
|
'Ж' => 'Ш',
|
48
|
|
|
'З' => 'С',
|
49
|
|
|
);
|
50
|
|
|
|
51
|
|
|
private function isHissingConsonant($consonant) {
|
52
|
|
|
return in_array(lower($consonant), array('ж', 'ш', 'ч', 'щ'));
|
53
|
|
|
}
|
54
|
|
|
|
55
|
|
|
private function isVelarConsonant($consonant) {
|
56
|
|
|
return in_array(lower($consonant), array('г', 'к', 'х'));
|
57
|
|
|
}
|
58
|
|
|
|
59
|
|
|
private function isConsonant($consonant) {
|
60
|
|
|
return in_array(upper($consonant), self::$consonants);
|
61
|
|
|
}
|
62
|
|
|
|
63
|
|
|
public function countSyllables($string) {
|
64
|
|
|
return chars_count($string, array_map(__NAMESPACE__.'\\lower', self::$vowels));
|
65
|
|
|
}
|
66
|
|
|
|
67
|
|
|
public function isPaired($consonant) {
|
68
|
|
|
$consonant = lower($consonant);
|
69
|
|
|
return array_key_exists($consonant, self::$pairs) || (array_search($consonant, self::$pairs) !== false);
|
70
|
|
|
}
|
71
|
|
|
|
72
|
|
|
public function checkLastConsonantSoftness($word) {
|
73
|
|
|
if (($substring = last_position_for_one_of_chars(lower($word), array_map(__NAMESPACE__.'\\lower', self::$consonants))) !== false) {
|
74
|
|
|
if (in_array(slice($substring, 0, 1), ['й', 'ч', 'щ'])) // always soft consonants
|
75
|
|
|
return true;
|
76
|
|
|
else if (length($substring) > 1 && in_array(slice($substring, 1, 2), ['е', 'ё', 'и', 'ю', 'я', 'ь'])) // consonants are soft if they are trailed with these vowels
|
77
|
|
|
return true;
|
78
|
|
|
}
|
79
|
|
|
return false;
|
80
|
|
|
}
|
81
|
|
|
|
82
|
|
|
public function choosePrepositionByFirstLetter($word, $prepositionWithVowel, $preposition) {
|
83
|
|
|
if (in_array(upper(slice($word, 0, 1)), self::$vowels))
|
84
|
|
|
return $prepositionWithVowel;
|
85
|
|
|
else
|
86
|
|
|
return $preposition;
|
87
|
|
|
}
|
88
|
|
|
}
|
89
|
|
|
|