You are here

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

Implements step 4 of the Porter2 algorithm.

Parameters

string $word: The word to stem.

Return value

string The modified word.

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

File

src/Porter2.php, line 315

Class

Porter2
PHP Implementation of the Porter2 Stemming Algorithm.

Namespace

Drupal\porterstemmer

Code

protected static function step4($word) {
  $checks = [
    'ement',
    'ment',
    'ance',
    'ence',
    'able',
    'ible',
    'ant',
    'ent',
    'ion',
    'ism',
    'ate',
    'iti',
    'ous',
    'ive',
    'ize',
    'al',
    'er',
    'ic',
  ];
  foreach ($checks as $check) {

    // Among the suffixes, if found and in R2, delete.
    if (self::hasEnding($word, $check)) {
      if (self::inR2($word, $check)) {
        if ($check !== 'ion' || in_array(self::charAt(-4, $word), [
          's',
          't',
        ])) {
          $word = self::removeEnding($word, $check);
        }
      }
      return $word;
    }
  }
  return $word;
}