You are here

protected function Porter2::step1a in Search API 8

Handles various suffixes, of which the longest is replaced.

Implements step 1a of the Porter2 algorithm.

1 call to Porter2::step1a()
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 150

Class

Porter2
Implements the Porter2 stemming algorithm.

Namespace

Drupal\search_api\Plugin\search_api\processor\Resources

Code

protected function step1a() {
  $found = FALSE;
  if ($this
    ->hasEnding('sses')) {
    $this
      ->removeEnding('sses');
    $this
      ->addEnding('ss');
    $found = TRUE;
  }
  $checks = [
    'ied',
    'ies',
  ];
  foreach ($checks as $check) {
    if (!$found && $this
      ->hasEnding($check)) {
      $length = $this
        ->length();
      $this
        ->removeEnding($check);
      if ($length > 4) {
        $this
          ->addEnding('i');
      }
      else {
        $this
          ->addEnding('ie');
      }
      $found = TRUE;
    }
  }
  if ($this
    ->hasEnding('us') || $this
    ->hasEnding('ss')) {
    $found = TRUE;
  }

  // Delete if preceding word part has a vowel not immediately before the s.
  if (!$found && $this
    ->hasEnding('s') && $this
    ->containsVowel(substr($this->word, 0, -2))) {
    $this
      ->removeEnding('s');
  }
}