1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | class Inflector_fr |
---|
25 | { |
---|
26 | private $exceptions; |
---|
27 | private $pluralizers; |
---|
28 | private $singularizers; |
---|
29 | |
---|
30 | function __construct() |
---|
31 | { |
---|
32 | $tmp = array ('monsieur' => 'messieurs', |
---|
33 | 'madame' => 'mesdames', |
---|
34 | 'mademoiselle' => 'mesdemoiselles', |
---|
35 | ); |
---|
36 | |
---|
37 | $this->exceptions = $tmp; |
---|
38 | foreach ($tmp as $k => $v) |
---|
39 | $this->exceptions[$v] = $k; |
---|
40 | |
---|
41 | $this->pluralizers = array_reverse(array( '/$/' => 's', |
---|
42 | '/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)$/' => '\1x', |
---|
43 | '/(bleu|émeu|landau|lieu|pneu|sarrau)$/' => '\1s', |
---|
44 | '/al$/' => 'aux', |
---|
45 | '/ail$/' => 'ails', |
---|
46 | '/(b|cor|ém|gemm|soupir|trav|vant|vitr)ail$/' => '\1aux', |
---|
47 | '/(s|x|z)$/' => '\1', |
---|
48 | )); |
---|
49 | |
---|
50 | $this->singularizers = array_reverse(array( |
---|
51 | '/s$/' => '', |
---|
52 | '/(bijou|caillou|chou|genou|hibou|joujou|pou|au|eu|eau)x$/' => '\1', |
---|
53 | '/(journ|chev)aux$/' => '\1al', |
---|
54 | '/ails$/' => 'ail', |
---|
55 | '/(b|cor|ém|gemm|soupir|trav|vant|vitr)aux$/' => '\1ail', |
---|
56 | )); |
---|
57 | } |
---|
58 | |
---|
59 | function get_variants($word) |
---|
60 | { |
---|
61 | $res = array(); |
---|
62 | |
---|
63 | $word = strtolower($word); |
---|
64 | |
---|
65 | $rc = @$this->exceptions[$word]; |
---|
66 | if ( isset($rc) ) |
---|
67 | { |
---|
68 | if (!empty($rc)) |
---|
69 | $res[] = $rc; |
---|
70 | return $res; |
---|
71 | } |
---|
72 | |
---|
73 | foreach ($this->pluralizers as $rule => $replacement) |
---|
74 | { |
---|
75 | $rc = preg_replace($rule, $replacement, $word, -1, $count); |
---|
76 | if ($count) |
---|
77 | { |
---|
78 | $res[] = $rc; |
---|
79 | break; |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | foreach ($this->singularizers as $rule => $replacement) |
---|
84 | { |
---|
85 | $rc = preg_replace($rule, $replacement, $word, -1, $count); |
---|
86 | if ($count) |
---|
87 | { |
---|
88 | $res[] = $rc; |
---|
89 | break; |
---|
90 | } |
---|
91 | } |
---|
92 | |
---|
93 | return $res; |
---|
94 | } |
---|
95 | } |
---|
96 | ?> |
---|