protected static function Porter2::r in Porter-Stemmer 8
Determines the start of a certain "R" region.
R is a region after the first non-vowel following a vowel, or end of word.
Parameters
string $word: The word to check.
int $type: (optional) 1 or 2. If 2, then calculate the R after the R1.
Return value
int The R position.
4 calls to Porter2::r()
- Porter2::inR1 in src/
Porter2.php - Checks whether the given string is contained in R1.
- Porter2::inR2 in src/
Porter2.php - Checks whether the given string is contained in R2.
- Porter2::isShort in src/
Porter2.php - Determines whether the word is short.
- Porter2::step1b in src/
Porter2.php - Handles various suffixes, of which the longest is replaced.
File
- src/
Porter2.php, line 495
Class
- Porter2
- PHP Implementation of the Porter2 Stemming Algorithm.
Namespace
Drupal\porterstemmerCode
protected static function r($word, $type = 1) {
$inc = 1;
if ($type === 2) {
$inc = self::r($word, 1);
}
elseif (strlen($word) > 5) {
$prefix_5 = substr($word, 0, 5);
if ($prefix_5 === 'gener' || $prefix_5 === 'arsen') {
return 5;
}
if (strlen($word) > 5 && substr($word, 0, 6) === 'commun') {
return 6;
}
}
while ($inc <= strlen($word)) {
if (!self::isVowel($inc, $word) && self::isVowel($inc - 1, $word)) {
$position = $inc;
break;
}
$inc++;
}
if (!isset($position)) {
$position = strlen($word);
}
else {
// We add one, as this is the position AFTER the first non-vowel.
$position++;
}
return $position;
}