|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Inflector\Dictionary\English; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Inflector\Rules\Pattern; |
|
8
|
|
|
use Doctrine\Inflector\Rules\Regex; |
|
9
|
|
|
use Doctrine\Inflector\Rules\Transformation; |
|
10
|
|
|
use Doctrine\Inflector\Rules\Word; |
|
11
|
|
|
use Doctrine\Inflector\Rules\Substitution; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class Inflectible |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @return Substitution[]|Regex[] |
|
17
|
|
|
*/ |
|
18
|
|
|
public static function all() : iterable |
|
19
|
|
|
{ |
|
20
|
|
|
yield from self::irregular(); |
|
21
|
|
|
yield from self::regular(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return Substitution[]|Regex[] |
|
26
|
|
|
*/ |
|
27
|
|
|
public static function irregular() : iterable |
|
28
|
|
|
{ |
|
29
|
|
|
yield new Substitution(new Word('belief'), new Word('beliefs')); |
|
30
|
|
|
yield new Substitution(new Word('halo'), new Word('halos')); |
|
31
|
|
|
yield new Substitution(new Word('photo'), new Word('photos')); |
|
32
|
|
|
yield new Substitution(new Word('piano'), new Word('pianos')); |
|
33
|
|
|
yield new Substitution(new Word('roof'), new Word('roofs')); |
|
34
|
|
|
yield new Transformation( |
|
35
|
|
|
new Regex(new Pattern('~chi?ef~i'), '\0s'), |
|
36
|
|
|
new Regex(new Pattern('~(chi?ef)s~i'), '\1') |
|
37
|
|
|
); |
|
38
|
|
|
yield new Substitution(new Word('wife'), new Word('wives')); |
|
39
|
|
|
yield new Substitution(new Word('wolf'), new Word('wolves')); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return Substitution[]|Regex[] |
|
44
|
|
|
*/ |
|
45
|
|
|
private static function regular() : iterable |
|
46
|
|
|
{ |
|
47
|
|
|
yield new Transformation( |
|
48
|
|
|
new Regex(new Pattern('~on$~i'), 'a'), |
|
49
|
|
|
new Regex(new Pattern('~a$~i'), 'on') |
|
50
|
|
|
); |
|
51
|
|
|
yield new Transformation( |
|
52
|
|
|
new Regex(new Pattern('~us$~i'), 'i'), |
|
53
|
|
|
new Regex(new Pattern('~i$~i'), 'us') |
|
54
|
|
|
); |
|
55
|
|
|
yield new Transformation( |
|
56
|
|
|
new Regex(new Pattern('~o$~i'), 'oes'), |
|
57
|
|
|
new Regex(new Pattern('~oes$~i'), 'oe') |
|
58
|
|
|
); |
|
59
|
|
|
yield new Transformation( |
|
60
|
|
|
new Regex(new Pattern('~is$~i'), 'es'), |
|
61
|
|
|
new Regex(new Pattern('~es$~i'), 'is') |
|
62
|
|
|
); |
|
63
|
|
|
yield new Transformation( |
|
64
|
|
|
new Regex(new Pattern('~[bcdfghjklmnpqrstvwxz]y$~i'), '\0s'), |
|
65
|
|
|
new Regex(new Pattern('~([bcdfghjklmnpqrstvwxz]y)s~i'), '\1') |
|
66
|
|
|
); |
|
67
|
|
|
yield new Transformation( |
|
68
|
|
|
new Regex(new Pattern('~fe?$~i'), 'ves'), |
|
69
|
|
|
new Regex(new Pattern('~ves$~i'), 'f') |
|
70
|
|
|
); |
|
71
|
|
|
yield new Transformation( |
|
72
|
|
|
new Regex(new Pattern('~(s[sh]?|ch|[xz])$~i'), '\1es'), |
|
73
|
|
|
new Regex(new Pattern('~(s[sh]?|ch|[xz])es$~i'), '\1') |
|
74
|
|
|
); |
|
75
|
|
|
yield new Transformation( |
|
76
|
|
|
new Regex(new Pattern('/$/'), 's'), |
|
77
|
|
|
new Regex(new Pattern('/s$/i'), '') |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|