You are here

function porterstemmer_step5 in Porter-Stemmer 7

Same name and namespace in other branches
  1. 6.2 porterstemmer.module \porterstemmer_step5()

Step 5 of algorithm: e, l endings in region R1/R2.

Parameters

string $word: Word to stem, modified in place if successful.

int $r1: Position of start of R1 region in word.

int $r2: Position of start of R2 region in word.

Return value

bool TRUE if it is time to stop stemming, FALSE to continue.

2 calls to porterstemmer_step5()
PorterStemmerInternalsUnitTest::testBaked in ./porterstemmer.test
Test internal steps on the word "baked".
porterstemmer_stem in includes/standard-stemmer.inc
Stems a word, using the Porter Stemmer 2 algorithm.

File

includes/standard-stemmer.inc, line 540
This is an implementation of the Porter 2 Stemming algorithm.

Code

function porterstemmer_step5(&$word, $r1, $r2) {
  $tmp = $word;
  $didit = FALSE;
  $done = FALSE;

  // Delete l at end of word if in R2 and preceded by another l.
  $done = porterstemmer_suffix($tmp, 'll', 'l', $didit, NULL, $r2 + 1);

  // Delete e at end of word if in R2, or in R1 and not preceded by
  // a short syllable.
  $len = drupal_strlen($tmp);
  if (!$done && preg_match('/e$/', $tmp) && ($len > $r2 || $len > $r1 && !preg_match('/^' . PORTERSTEMMER_VOWEL . PORTERSTEMMER_NOT_VOWEL . 'e$/', $tmp) && !preg_match('/' . PORTERSTEMMER_NOT_VOWEL . PORTERSTEMMER_VOWEL . PORTERSTEMMER_NOT_VOWEL_WXY . 'e$/', $tmp))) {
    $tmp = drupal_substr($tmp, 0, -1);
  }
  return porterstemmer_step_ending($word, $tmp);
}