You are here

public function Porter2::__construct in Search API 8

Constructs a SearchApiPorter2 object.

Parameters

string $word: The word to stem.

string[] $custom_exceptions: (optional) A custom list of exceptions.

File

src/Plugin/search_api/processor/Resources/Porter2.php, line 52

Class

Porter2
Implements the Porter2 stemming algorithm.

Namespace

Drupal\search_api\Plugin\search_api\processor\Resources

Code

public function __construct($word, array $custom_exceptions = []) {
  $this->word = $word;
  $this->exceptions = $custom_exceptions + [
    'skis' => 'ski',
    'skies' => 'sky',
    'dying' => 'die',
    'lying' => 'lie',
    'tying' => 'tie',
    'idly' => 'idl',
    'gently' => 'gentl',
    'ugly' => 'ugli',
    'early' => 'earli',
    'only' => 'onli',
    'singly' => 'singl',
    'sky' => 'sky',
    'news' => 'news',
    'howe' => 'howe',
    'atlas' => 'atlas',
    'cosmos' => 'cosmos',
    'bias' => 'bias',
    'andes' => 'andes',
  ];

  // Set initial y, or y after a vowel, to Y.
  $inc = 0;
  while ($inc <= $this
    ->length()) {
    if (substr($this->word, $inc, 1) === 'y' && ($inc == 0 || $this
      ->isVowel($inc - 1))) {
      $this->word = substr_replace($this->word, 'Y', $inc, 1);
    }
    $inc++;
  }

  // Establish the regions R1 and R2. See function R().
  $this->r1 = $this
    ->R(1);
  $this->r2 = $this
    ->R(2);
}