1
|
|
|
<?php |
2
|
|
|
namespace morphos\English; |
3
|
|
|
|
4
|
|
|
use morphos\S; |
5
|
|
|
|
6
|
|
|
class NounPluralization extends \morphos\NounPluralization |
7
|
|
|
{ |
8
|
|
|
private static $exceptions = [ |
9
|
|
|
'chief' => 'chiefs', |
10
|
|
|
'basis' => 'bases', |
11
|
|
|
'crisis' => 'crises', |
12
|
|
|
'radius' => 'radii', |
13
|
|
|
'nucleus' => 'nuclei', |
14
|
|
|
'curriculum' => 'curricula', |
15
|
|
|
'man' => 'men', |
16
|
|
|
'woman' => 'women', |
17
|
|
|
'child' => 'children', |
18
|
|
|
'foot' => 'feet', |
19
|
|
|
'tooth' => 'teeth', |
20
|
|
|
'ox' => 'oxen', |
21
|
|
|
'goose' => 'geese', |
22
|
|
|
'mouse' => 'mice' |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
private static $without_paired_form = [ |
26
|
|
|
'knowledge', |
27
|
|
|
'progress', |
28
|
|
|
'advise', |
29
|
|
|
'ink', |
30
|
|
|
'money', |
31
|
|
|
'scissors', |
32
|
|
|
'spectacles', |
33
|
|
|
'trousers', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
public static $consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'x', 'z', 'w']; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $word |
40
|
|
|
* @param int $count |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
47 |
|
public static function pluralize($word, $count = 2) |
44
|
|
|
{ |
45
|
47 |
|
if ($count == 1) { |
46
|
7 |
|
return $word; |
47
|
|
|
} |
48
|
|
|
|
49
|
46 |
|
$word = S::lower($word); |
|
|
|
|
50
|
46 |
|
if (in_array($word, self::$without_paired_form)) { |
51
|
8 |
|
return $word; |
52
|
38 |
|
} elseif (isset(self::$exceptions[$word])) { |
53
|
14 |
|
return self::$exceptions[$word]; |
54
|
|
|
} |
55
|
|
|
|
56
|
24 |
|
if (in_array(S::slice($word, -1), ['s', 'x']) || in_array(S::slice($word, -2), array('sh', 'ch'))) { |
|
|
|
|
57
|
2 |
|
return $word.'es'; |
58
|
22 |
|
} elseif (S::slice($word, -1) == 'o') { |
|
|
|
|
59
|
1 |
|
return $word.'es'; |
60
|
21 |
|
} elseif (S::slice($word, -1) == 'y' && in_array(S::slice($word, -2, -1), self::$consonants)) { |
|
|
|
|
61
|
2 |
|
return S::slice($word, 0, -1).'ies'; |
|
|
|
|
62
|
19 |
|
} elseif (S::slice($word, -2) == 'fe' || S::slice($word, -1) == 'f') { |
|
|
|
|
63
|
2 |
|
if (S::slice($word, -1) == 'f') { |
|
|
|
|
64
|
1 |
|
return S::slice($word, 0, -1).'ves'; |
|
|
|
|
65
|
|
|
} else { |
66
|
1 |
|
return S::slice($word, 0, -2).'ves'; |
|
|
|
|
67
|
|
|
} |
68
|
|
|
} else { |
69
|
17 |
|
return $word.'s'; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|