You are here

protected function Porter2::step2 in Search API 8

Implements step 2 of the Porter2 algorithm.

1 call to Porter2::step2()
Porter2::stem in src/Plugin/search_api/processor/Resources/Porter2.php
Computes the stem of the word.

File

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

Class

Porter2
Implements the Porter2 stemming algorithm.

Namespace

Drupal\search_api\Plugin\search_api\processor\Resources

Code

protected function step2() {
  $checks = [
    "ization" => "ize",
    "iveness" => "ive",
    "fulness" => "ful",
    "ational" => "ate",
    "ousness" => "ous",
    "biliti" => "ble",
    "tional" => "tion",
    "lessli" => "less",
    "fulli" => "ful",
    "entli" => "ent",
    "ation" => "ate",
    "aliti" => "al",
    "iviti" => "ive",
    "ousli" => "ous",
    "alism" => "al",
    "abli" => "able",
    "anci" => "ance",
    "alli" => "al",
    "izer" => "ize",
    "enci" => "ence",
    "ator" => "ate",
    "bli" => "ble",
    "ogi" => "og",
  ];
  foreach ($checks as $find => $replace) {
    if ($this
      ->hasEnding($find)) {
      if ($this
        ->inR1($find)) {
        $this
          ->removeEnding($find);
        $this
          ->addEnding($replace);
      }
      return;
    }
  }
  if ($this
    ->hasEnding('li')) {
    if ($this
      ->length() > 4 && $this
      ->validLi($this
      ->charAt(-3))) {
      $this
        ->removeEnding('li');
    }
  }
}