function porterstemmer_suffix in Porter-Stemmer 6.2
Same name and namespace in other branches
- 7 includes/standard-stemmer.inc \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
$word: Word to performm search/replace on.
$oldend: Ending to check for.
$newend: Replacement ending.
$didit: Set to TRUE in the case that a replacement is done; left alone otherwise.
$other: Extra regular expression; must match to allow ending replacement.
$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
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 - Implementation of hook_sbp_excerpt_match().
- porterstemmer_step0 in ./
porterstemmer.module - Step 0 of the algorithm: remove possessive endings.
- porterstemmer_step1a in ./
porterstemmer.module - Step 1a of algorithm: plurals, etc.
- porterstemmer_step1b in ./
porterstemmer.module - Step 1b of algorithm: eed, eedly, ed, edly, ing, ingly
- porterstemmer_step1c in ./
porterstemmer.module - Step 1c of algorithm: y suffixes
File
- ./
porterstemmer.module, line 265 - This is an implementation of the Porter 2 Stemming algorithm from http://snowball.tartarus.org/algorithms/english/stemmer.html by Jennifer Hodgdon of Poplar ProductivityWare, www.poplarware.com
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;
}