You are here

public static function Porter2::stem in Porter-Stemmer 8

Computes the stem of the word.

Return value

string The word's stem.

7 calls to Porter2::stem()
Porter2Test1::testStem in tests/src/Unit/Porter2Test1.php
Test Porter2::stem() with a data provider method.
Porter2Test2::testStem in tests/src/Unit/Porter2Test2.php
Test Porter2::stem() with a data provider method.
Porter2Test3::testStem in tests/src/Unit/Porter2Test3.php
Test Porter2::stem() with a data provider method.
Porter2Test4::testStem in tests/src/Unit/Porter2Test4.php
Test Porter2::stem() with a data provider method.
Porter2Test5::testStem in tests/src/Unit/Porter2Test5.php
Test Porter2::stem() with a data provider method.

... See full list

File

src/Porter2.php, line 18

Class

Porter2
PHP Implementation of the Porter2 Stemming Algorithm.

Namespace

Drupal\porterstemmer

Code

public static function stem($word) {
  $exceptions = [
    'skis' => 'ski',
    'skies' => 'sky',
    'dying' => 'die',
    'lying' => 'lie',
    'tying' => 'tie',
    'idly' => 'idl',
    'gently' => 'gentl',
    'ugly' => 'ugli',
    'early' => 'earli',
    'only' => 'onli',
    'singly' => 'singl',
    'sky' => 'sky',
    'news' => 'news',
    'howe' => 'howe',
    'atlas' => 'atlas',
    'cosmos' => 'cosmos',
    'bias' => 'bias',
    'andes' => 'andes',
  ];

  // Process exceptions.
  if (isset($exceptions[$word])) {
    $word = $exceptions[$word];
  }
  elseif (strlen($word) > 2) {

    // Only execute algorithm on words that are longer than two letters.
    $word = self::prepare($word);
    $word = self::step0($word);
    $word = self::step1a($word);
    $word = self::step1b($word);
    $word = self::step1c($word);
    $word = self::step2($word);
    $word = self::step3($word);
    $word = self::step4($word);
    $word = self::step5($word);
  }
  return strtolower($word);
}