You are here

function porterstemmer_step1b in Porter-Stemmer 7

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

Step 1b of algorithm: eed, eedly, ed, edly, ing, ingly.

Parameters

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

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

Return value

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

3 calls to porterstemmer_step1b()
PorterStemmerInternalsUnitTest::testAdministered in ./porterstemmer.test
Test internal steps on the word "administered".
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 350
This is an implementation of the Porter 2 Stemming algorithm.

Code

function porterstemmer_step1b(&$word, $r1) {
  $tmp = $word;
  $didit = FALSE;

  // Replace these endings if in R1 region.
  $done = (porterstemmer_suffix($tmp, 'eedly', 'ee', $didit, NULL, $r1 + 5) or porterstemmer_suffix($tmp, 'eed', 'ee', $didit, NULL, $r1 + 3));

  // Delete these endings if there's a vowel before the ending.
  $didit = FALSE;
  if (!$done) {
    porterstemmer_suffix($tmp, 'edly', '', $didit, '/' . PORTERSTEMMER_VOWEL . '.*edly$/') or porterstemmer_suffix($tmp, 'ed', '', $didit, '/' . PORTERSTEMMER_VOWEL . '.*ed$/') or porterstemmer_suffix($tmp, 'ingly', '', $didit, '/' . PORTERSTEMMER_VOWEL . '.*ingly$/') or porterstemmer_suffix($tmp, 'ing', '', $didit, '/' . PORTERSTEMMER_VOWEL . '.*ing$/');
  }

  // If we did one of these replacements, post-process...
  if ($didit) {
    $done = porterstemmer_suffix($tmp, 'at', 'ate', $didit) or porterstemmer_suffix($tmp, 'bl', 'ble', $didit) or porterstemmer_suffix($tmp, 'iz', 'ize', $didit);
    if (!$done && preg_match('/' . PORTERSTEMMER_DOUBLE . '$/', $tmp)) {

      // Drop last letter if it's a double-letter ending.
      $tmp = drupal_substr($tmp, 0, -1);
      $done = TRUE;
    }
    if (!$done && porterstemmer_short_word($tmp, $r1)) {
      $tmp = $tmp . 'e';
    }
  }
  return porterstemmer_step_ending($word, $tmp);
}