You are here

protected function SearchApiPorter2::R in Search API 7

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

int $type: (optional) 1 or 2. If 2, then calculate the R after the R1.

Return value

int The R position.

1 call to SearchApiPorter2::R()
SearchApiPorter2::__construct in includes/processor_stemmer.inc
Constructs a SearchApiPorter2 object.

File

includes/processor_stemmer.inc, line 576
Contains SearchApiPorterStemmer and SearchApiPorter2.

Class

SearchApiPorter2
Implements the Porter2 stemming algorithm.

Code

protected function R($type = 1) {
  $inc = 1;
  if ($type === 2) {
    $inc = $this->r1;
  }
  elseif ($this
    ->length() > 5) {
    $prefix_5 = substr($this->word, 0, 5);
    if ($prefix_5 === 'gener' || $prefix_5 === 'arsen') {
      return 5;
    }
    if ($this
      ->length() > 6 && substr($this->word, 0, 6) === 'commun') {
      return 6;
    }
  }
  while ($inc <= $this
    ->length()) {
    if (!$this
      ->isVowel($inc) && $this
      ->isVowel($inc - 1)) {
      $position = $inc;
      break;
    }
    $inc++;
  }
  if (!isset($position)) {
    $position = $this
      ->length();
  }
  else {

    // We add one, as this is the position AFTER the first non-vowel.
    $position++;
  }
  return $position;
}