You are here

function porterstemmer_suffix in Porter-Stemmer 7

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

Replaces one word ending with another, if tests pass.

The return value is TRUE of the ending is present at the end of the word, and FALSE if the ending is not present. The found word ending is also replaced with the given replacement, only if the additional regular expression (if present) matches and if the word is at least the given length.

Parameters

string $word: Word to performm search/replace on.

string $oldend: Ending to check for.

string $newend: Replacement ending.

bool $didit: Set to TRUE in the case that a replacement is done; left alone otherwise.

string $other: Extra regular expression; must match to allow ending replacement.

int $minlen: Minimum word length required to allow ending replacement. For instance, to see if a particular ending is in the R1 region, pass in $r1 + length of ending as the minimum word length.

Return value

bool TRUE if ending was at the end of the word, FALSE if not.

9 calls to porterstemmer_suffix()
porterstemmer_sbp_excerpt_match in ./porterstemmer.module
Implements hook_sbp_excerpt_match().
porterstemmer_step0 in includes/standard-stemmer.inc
Step 0 of the algorithm: remove possessive endings.
porterstemmer_step1a in includes/standard-stemmer.inc
Step 1a of algorithm: plurals, etc.
porterstemmer_step1b in includes/standard-stemmer.inc
Step 1b of algorithm: eed, eedly, ed, edly, ing, ingly.
porterstemmer_step1c in includes/standard-stemmer.inc
Step 1c of algorithm: y suffixes.

... See full list

File

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

Code

function porterstemmer_suffix(&$word, $oldend, $newend, &$didit, $other = NULL, $minlen = 1) {

  // Check to see if the ending is there.
  $end_regexp = '/' . $oldend . '$/';
  if (!preg_match($end_regexp, $word)) {

    // Ending isn't even there.
    return FALSE;
  }

  // Does word match other regular expression?
  if ($other && !preg_match($other, $word)) {

    // No match, so just return without replacing.
    return TRUE;
  }

  // Is word long enough?
  if (drupal_strlen($word) < $minlen) {

    // Too short, so just return without replacing.
    return TRUE;
  }

  // Replace word ending.
  $word = preg_replace($end_regexp, $newend, $word);
  $didit = TRUE;
  return TRUE;
}