Skip to content

Commit

Permalink
bug 3056: quick search - added english inflections for -ing / -er for…
Browse files Browse the repository at this point in the history
… example searching for 'runner', 'runners' or 'running' will yield the same results for all terms (unless specifically quoted)

git-svn-id: http://piwigo.org/svn/trunk@28182 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Apr 14, 2014
1 parent 8f9d441 commit c218168
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions include/inflectors/en.php
Expand Up @@ -38,7 +38,9 @@ function __construct()
'move' => 'moves',
'mouse' => 'mice',
'ox' => 'oxen',
'zombie' => 'zombies',
'zombie' => 'zombies', // pl->sg exc.
'serie' => 'series', // pl->sg exc.
'movie' => 'movies', // pl->sg exc.
);

$this->exceptions = $tmp;
Expand Down Expand Up @@ -71,7 +73,6 @@ function __construct()
$this->singularizers = array_reverse(array(
'/s$/' => '',
'/(ss)$/' => '\1',
'/(n)ews$/' => '\1ews',
'/([ti])a$/' => '\1um',
'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/' => '\1sis',
'/(^analy)(sis|ses)$/' => '\1sis',
Expand All @@ -80,8 +81,6 @@ function __construct()
'/(tive)s$/' => '\1',
'/([lr])ves$/' => '\1f',
'/([^aeiouy]|qu)ies$/' => '\1y',
'/(s)eries$/' => '\1eries',
'/(m)ovies$/' => '\1ovie',
'/(x|ch|ss|sh)es$/' => '\1',
'/(bus)(es)?$/' => '\1',
'/(o)es$/' => '\1',
Expand All @@ -94,43 +93,56 @@ function __construct()
'/(quiz)zes$/' => '\1',
'/(database)s$/' => '\1',
));

$this->er2ing = array_reverse(array(
'/ers?$/' => 'ing',
'/((be|riv)ers?)$/' => '\1'
));

$this->ing2er = array_reverse(array(
'/ing$/' => 'er',
'/(being)$/' => '\1'
));

}

function get_variants($word)
{
$res = array();

$word = strtolower($word);
$lword = strtolower($word);

$rc = @$this->exceptions[$word];
$rc = @$this->exceptions[$lword];
if ( isset($rc) )
{
if (!empty($rc))
$res[] = $rc;
return $res;
}

foreach ($this->pluralizers as $rule => $replacement)
self::run($this->pluralizers, $word, $res);
self::run($this->singularizers, $word, $res);
self::run($this->er2ing, $word, $res);
$rc = self::run($this->ing2er, $word, $res);
if ($rc !== false)
{
$rc = preg_replace($rule, $replacement, $word, -1, $count);
if ($count)
{
$res[] = $rc;
break;
}
self::run($this->pluralizers, $rc, $res);
}
return $res;
}

foreach ($this->singularizers as $rule => $replacement)
private static function run($rules, $word, &$res)
{
foreach ($rules as $rule => $replacement)
{
$rc = preg_replace($rule, $replacement, $word, -1, $count);
$rc = preg_replace($rule.'i', $replacement, $word, -1, $count);
if ($count)
{
$res[] = $rc;
break;
return $rc;
}
}

return $res;
return false;
}
}
?>

0 comments on commit c218168

Please sign in to comment.