source: trunk/include/inflectors/en.php @ 27884

Last change on this file since 27884 was 27884, checked in by rvelices, 10 years ago

bug 3056: quick search

  • added inflectors for english and french languages
  • current quick search is kept in the quick search input box
  • small fixes
File size: 4.6 KB
Line 
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
24class Inflector_en
25{
26  private $exceptions;
27  private $pluralizers;
28  private $singularizers;
29
30  function __construct()
31  {
32    $tmp =      array ('octopus' => 'octopuses',
33      'virus' => 'viruses',
34      'person' => 'people',
35      'man' => 'men',
36      'woman' => 'women',
37      'child' => 'children',
38      'move' => 'moves',
39      'mouse' => 'mice',
40      'ox' => 'oxen',
41      'zombie' => 'zombies',
42    );
43
44    $this->exceptions = $tmp;
45    foreach ($tmp as $k => $v)
46      $this->exceptions[$v] = $k;
47
48    foreach ( explode(' ', 'new news advice art coal baggage butter clothing cotton currency deer energy equipment experience fish flour food furniture gas homework impatience information jeans knowledge leather love luggage money oil patience police polish progress research rice series sheep silk soap species sugar talent toothpaste travel vinegar weather wood wool work')
49      as $v)
50    {
51      $this->exceptions[$v] = 0;
52    }
53
54    $this->pluralizers = array_reverse(array( '/$/' => 's',
55      '/s$/' => 's',
56      '/^(ax|test)is$/' => '\1es',
57      '/(alias|status)$/' => '\1es',
58      '/(bu)s$/' => '\1ses',
59      '/(buffal|tomat)o$/' => '\1oes',
60      '/([ti])um$/' => '\1a',
61      '/([ti])a$/' => '\1a',
62      '/sis$/' => 'ses',
63      '/(?:([^f])fe|([lr])f)$/' => '\1\2ves',
64      '/(hive)$/' => '\1s',
65      '/([^aeiouy]|qu)y$/' => '\1ies',
66      '/(x|ch|ss|sh)$/' => '\1es',
67      '/(matr|vert|ind)(?:ix|ex)$/' => '\1ices',
68      '/(quiz)$/' => '\1zes',
69      ));
70
71    $this->singularizers = array_reverse(array(
72      '/s$/' => '',
73      '/(ss)$/' => '\1',
74      '/(n)ews$/' => '\1ews',
75      '/([ti])a$/' => '\1um',
76      '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/' => '\1sis',
77      '/(^analy)(sis|ses)$/' => '\1sis',
78      '/([^f])ves$/' => '\1fe',
79      '/(hive)s$/' => '\1',
80      '/(tive)s$/' => '\1',
81      '/([lr])ves$/' => '\1f',
82      '/([^aeiouy]|qu)ies$/' => '\1y',
83      '/(s)eries$/' => '\1eries',
84      '/(m)ovies$/' => '\1ovie',
85      '/(x|ch|ss|sh)es$/' => '\1',
86      '/(bus)(es)?$/' => '\1',
87      '/(o)es$/' => '\1',
88      '/(shoe)s$/' => '\1',
89      '/(cris|test)(is|es)$/' => '\1is',
90      '/^(a)x[ie]s$/' => '\1xis',
91      '/(alias|status)(es)?$/' => '\1',
92      '/(vert|ind)ices$/' => '\1ex',
93      '/(matr)ices$/' => '\1ix',
94      '/(quiz)zes$/' => '\1',
95      '/(database)s$/' => '\1',
96      ));
97  }
98
99  function get_variants($word)
100  {
101    $res = array();
102
103    $word = strtolower($word);
104
105    $rc = @$this->exceptions[$word];
106    if ( isset($rc) )
107    {
108      if (!empty($rc))
109        $res[] = $rc;
110      return $res;
111    }
112
113    foreach ($this->pluralizers as $rule => $replacement)
114    {
115      $rc = preg_replace($rule, $replacement, $word, -1, $count);
116      if ($count)
117      {
118        $res[] = $rc;
119        break;
120      }
121    }
122
123    foreach ($this->singularizers as $rule => $replacement)
124    {
125      $rc = preg_replace($rule, $replacement, $word, -1, $count);
126      if ($count)
127      {
128        $res[] = $rc;
129        break;
130      }
131    }
132
133    return $res;
134  }
135}
136?>
Note: See TracBrowser for help on using the repository browser.