You are here

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

Determines whether the word ends in a "vowel-consonant" suffix.

Unless the word is only two characters long, it also checks that the third-last character is neither "w", "x" nor "Y".

Parameters

string $word: The word to check.

int|null $position: (optional) If given, do not check the end of the word, but the character at the given position, and the next one.

Return value

bool TRUE if the word has the described suffix, FALSE otherwise.

2 calls to Porter2::isShortSyllable()
Porter2::isShort in src/Porter2.php
Determines whether the word is short.
Porter2::step5 in src/Porter2.php
Implements step 5 of the Porter2 algorithm.

File

src/Porter2.php, line 453

Class

Porter2
PHP Implementation of the Porter2 Stemming Algorithm.

Namespace

Drupal\porterstemmer

Code

protected static function isShortSyllable($word, $position = NULL) {
  if ($position === NULL) {
    $position = strlen($word) - 2;
  }

  // A vowel at the beginning of the word followed by a non-vowel.
  if ($position === 0) {
    return self::isVowel(0, $word) && !self::isVowel(1, $word);
  }

  // Vowel followed by non-vowel other than w, x, Y and preceded by
  // non-vowel.
  $additional = [
    'w',
    'x',
    'Y',
  ];
  return !self::isVowel($position - 1, $word) && self::isVowel($position, $word) && !self::isVowel($position + 1, $word, $additional);
}