You are here

protected static function Porter2::step1b in Porter-Stemmer 8

Handles various suffixes, of which the longest is replaced.

Parameters

string $word: The word to stem.

Return value

string The modified word.

1 call to Porter2::step1b()
Porter2::stem in src/Porter2.php
Computes the stem of the word.

File

src/Porter2.php, line 153

Class

Porter2
PHP Implementation of the Porter2 Stemming Algorithm.

Namespace

Drupal\porterstemmer

Code

protected static function step1b($word) {
  $exceptions = [
    'inning',
    'outing',
    'canning',
    'herring',
    'earring',
    'proceed',
    'exceed',
    'succeed',
  ];
  if (in_array($word, $exceptions)) {
    return $word;
  }
  $checks = [
    'eedly',
    'eed',
  ];
  foreach ($checks as $check) {
    if (self::hasEnding($word, $check)) {
      if (self::r($word, 1) !== strlen($word)) {
        $word = self::removeEnding($word, $check) . 'ee';
      }
      return $word;
    }
  }
  $checks = [
    'ingly',
    'edly',
    'ing',
    'ed',
  ];
  $second_endings = [
    'at',
    'bl',
    'iz',
  ];
  foreach ($checks as $check) {

    // If the ending is present and the previous part contains a vowel.
    if (self::hasEnding($word, $check) && self::containsVowel(substr($word, 0, -strlen($check)))) {
      $word = self::removeEnding($word, $check);
      foreach ($second_endings as $ending) {
        if (self::hasEnding($word, $ending)) {
          return $word . 'e';
        }
      }

      // If the word ends with a double, remove the last letter.
      $double_removed = self::removeDoubles($word);
      if ($double_removed != $word) {
        $word = $double_removed;
      }
      elseif (self::isShort($word)) {

        // If the word is short, add e (so hop -> hope).
        $word .= 'e';
      }
      return $word;
    }
  }
  return $word;
}