You are here

function step1ab in Porter-Stemmer 6

Same name and namespace in other branches
  1. 5 porterstemmer.module \step1ab()

Step 1

1 call to step1ab()
stem in ./porterstemmer.module
Stems a word. Simple huh?

File

./porterstemmer.module, line 78

Code

function step1ab($word) {

  // Part a
  if (substr($word, -1) == 's') {
    replace($word, 'sses', 'ss') or replace($word, 'ies', 'i') or replace($word, 'ss', 'ss') or replace($word, 's', '');
  }

  // Part b
  if (substr($word, -2, 1) != 'e' or !replace($word, 'eed', 'ee', 0)) {

    // First rule
    $v = regex_vowel;

    // ing and ed
    if (preg_match("#{$v}+#", substr($word, 0, -3)) && replace($word, 'ing', '') or preg_match("#{$v}+#", substr($word, 0, -2)) && replace($word, 'ed', '')) {

      // Note use of && and OR, for precedence reasons
      // If one of above two test successful
      if (!replace($word, 'at', 'ate') and !replace($word, 'bl', 'ble') and !replace($word, 'iz', 'ize')) {

        // Double consonant ending
        if (doubleConsonant($word) and substr($word, -2) != 'll' and substr($word, -2) != 'ss' and substr($word, -2) != 'zz') {
          $word = substr($word, 0, -1);
        }
        else {
          if (m($word) == 1 and cvc($word)) {
            $word .= 'e';
          }
        }
      }
    }
  }
  return $word;
}