You are here

protected function Porter2::step1b in Search API 8

Handles various suffixes, of which the longest is replaced.

Implements step 1b of the Porter2 algorithm.

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

File

src/Plugin/search_api/processor/Resources/Porter2.php, line 185

Class

Porter2
Implements the Porter2 stemming algorithm.

Namespace

Drupal\search_api\Plugin\search_api\processor\Resources

Code

protected function step1b() {
  $exceptions = [
    'inning',
    'outing',
    'canning',
    'herring',
    'earring',
    'proceed',
    'exceed',
    'succeed',
  ];
  if (in_array($this->word, $exceptions)) {
    return;
  }
  $checks = [
    'eedly',
    'eed',
  ];
  foreach ($checks as $check) {
    if ($this
      ->hasEnding($check)) {
      if ($this->r1 !== $this
        ->length()) {
        $this
          ->removeEnding($check);
        $this
          ->addEnding('ee');
      }
      return;
    }
  }
  $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 ($this
      ->hasEnding($check) && $this
      ->containsVowel(substr($this->word, 0, -strlen($check)))) {
      $this
        ->removeEnding($check);
      foreach ($second_endings as $ending) {
        if ($this
          ->hasEnding($ending)) {
          $this
            ->addEnding('e');
          return;
        }
      }

      // If the word ends with a double, remove the last letter.
      $found = $this
        ->removeDoubles();

      // If the word is short, add e (so hop -> hope).
      if (!$found && $this
        ->isShort()) {
        $this
          ->addEnding('e');
      }
      return;
    }
  }
}