You are here

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

Set initial y, or y after a vowel, to Y.

Parameters

string $word: The word to stem.

Return value

string The prepared word.

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

File

src/Porter2.php, line 69

Class

Porter2
PHP Implementation of the Porter2 Stemming Algorithm.

Namespace

Drupal\porterstemmer

Code

protected static function prepare($word) {
  $inc = 0;
  if (strpos($word, "'") === 0) {
    $word = substr($word, 1);
  }
  while ($inc <= strlen($word)) {
    if (substr($word, $inc, 1) === 'y' && ($inc == 0 || self::isVowel($inc - 1, $word))) {
      $word = substr_replace($word, 'Y', $inc, 1);
    }
    $inc++;
  }
  return $word;
}