You are here

protected function SearchApiPorter2::step1b in Search API 7

Handles various suffixes, of which the longest is replaced.

Implements step 1b of the Porter2 algorithm.

1 call to SearchApiPorter2::step1b()
SearchApiPorter2::stem in includes/processor_stemmer.inc
Computes the stem of the word.

File

includes/processor_stemmer.inc, line 268
Contains SearchApiPorterStemmer and SearchApiPorter2.

Class

SearchApiPorter2
Implements the Porter2 stemming algorithm.

Code

protected function step1b() {
  $exceptions = array(
    'inning',
    'outing',
    'canning',
    'herring',
    'earring',
    'proceed',
    'exceed',
    'succeed',
  );
  if (in_array($this->word, $exceptions)) {
    return;
  }
  $checks = array(
    'eedly',
    'eed',
  );
  foreach ($checks as $check) {
    if ($this
      ->hasEnding($check)) {
      if ($this->r1 !== $this
        ->length()) {
        $this
          ->removeEnding($check);
        $this
          ->addEnding('ee');
      }
      return;
    }
  }
  $checks = array(
    'ingly',
    'edly',
    'ing',
    'ed',
  );
  $second_endings = array(
    '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;
    }
  }
}