Ignore:
Timestamp:
Apr 14, 2014, 11:33:51 PM (10 years ago)
Author:
rvelices
Message:

bug 3056: quick search - added english inflections for -ing / -er for example searching for 'runner', 'runners' or 'running' will yield the same results for all terms (unless specifically quoted)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/inflectors/en.php

    r27884 r28182  
    3939      'mouse' => 'mice',
    4040      'ox' => 'oxen',
    41       'zombie' => 'zombies',
     41      'zombie' => 'zombies', // pl->sg exc.
     42                        'serie' => 'series', // pl->sg exc.
     43                        'movie' => 'movies', // pl->sg exc.
    4244    );
    4345
     
    7274      '/s$/' => '',
    7375      '/(ss)$/' => '\1',
    74       '/(n)ews$/' => '\1ews',
    7576      '/([ti])a$/' => '\1um',
    7677      '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/' => '\1sis',
     
    8182      '/([lr])ves$/' => '\1f',
    8283      '/([^aeiouy]|qu)ies$/' => '\1y',
    83       '/(s)eries$/' => '\1eries',
    84       '/(m)ovies$/' => '\1ovie',
    8584      '/(x|ch|ss|sh)es$/' => '\1',
    8685      '/(bus)(es)?$/' => '\1',
     
    9594      '/(database)s$/' => '\1',
    9695      ));
     96
     97    $this->er2ing = array_reverse(array(
     98      '/ers?$/' => 'ing',
     99      '/((be|riv)ers?)$/' => '\1'
     100    ));
     101
     102    $this->ing2er = array_reverse(array(
     103      '/ing$/' => 'er',
     104      '/(being)$/' => '\1'
     105    ));
     106
    97107  }
    98108
     
    101111    $res = array();
    102112
    103     $word = strtolower($word);
     113    $lword = strtolower($word);
    104114
    105     $rc = @$this->exceptions[$word];
     115    $rc = @$this->exceptions[$lword];
    106116    if ( isset($rc) )
    107117    {
     
    111121    }
    112122
    113     foreach ($this->pluralizers as $rule => $replacement)
     123    self::run($this->pluralizers, $word, $res);
     124    self::run($this->singularizers, $word, $res);
     125    self::run($this->er2ing, $word, $res);
     126    $rc = self::run($this->ing2er, $word, $res);
     127    if ($rc !== false)
    114128    {
    115       $rc = preg_replace($rule, $replacement, $word, -1, $count);
     129      self::run($this->pluralizers, $rc, $res);
     130    }
     131    return $res;
     132  }
     133
     134  private static function run($rules, $word, &$res)
     135  {
     136    foreach ($rules as $rule => $replacement)
     137    {
     138      $rc = preg_replace($rule.'i', $replacement, $word, -1, $count);
    116139      if ($count)
    117140      {
    118141        $res[] = $rc;
    119         break;
     142        return $rc;
    120143      }
    121144    }
    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;
     145    return false;
    134146  }
    135147}
Note: See TracChangeset for help on using the changeset viewer.