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