From 87a41fe7a6ef406c50c8f86a058f534653153208 Mon Sep 17 00:00:00 2001 From: Dom Morgan Date: Mon, 15 Jun 2026 14:29:40 +0100 Subject: [PATCH 1/5] Add rector config --- composer.json | 3 ++- rector.php | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index b190dda..dd5d178 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "voku/portable-utf8": "^5.4|^6.0" }, "require-dev":{ - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.0", + "rector/rector": "^2.4" }, "autoload": { "psr-4": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..74e5e82 --- /dev/null +++ b/rector.php @@ -0,0 +1,26 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/test', + ]) + // uncomment to reach your current PHP version + ->withPhpSets( + php85: true + ) + ->withPreparedSets( + codeQuality: true, + deadCode: true, + typeDeclarations: true, + ) + ->withComposerBased( + phpunit: true, + ) + // ->withTypeCoverageLevel(100) + // ->withDeadCodeLevel(100) + ; From b9312d13e7205f93c6d8bd2c77fdb696d6cd02b1 Mon Sep 17 00:00:00 2001 From: Dom Morgan Date: Mon, 15 Jun 2026 14:31:11 +0100 Subject: [PATCH 2/5] dead code and code quality --- rector.php | 2 +- src/NotFoundException.php | 2 + src/Stemmer/Catalan.php | 10 ++- src/Stemmer/Danish.php | 20 +++--- src/Stemmer/Dutch.php | 76 +++++++++----------- src/Stemmer/English.php | 111 +++++++++++++--------------- src/Stemmer/Finnish.php | 89 ++++++++++++----------- src/Stemmer/French.php | 92 ++++++++++++------------ src/Stemmer/German.php | 42 +++++------ src/Stemmer/Italian.php | 64 ++++++++--------- src/Stemmer/Norwegian.php | 19 ++--- src/Stemmer/Portuguese.php | 57 +++++++-------- src/Stemmer/Romanian.php | 55 +++++++------- src/Stemmer/Russian.php | 143 +++++++++++++++---------------------- src/Stemmer/Spanish.php | 71 +++++++++--------- src/Stemmer/Stem.php | 11 +-- src/Stemmer/Stemmer.php | 3 + src/Stemmer/Swedish.php | 20 +++--- src/StemmerManager.php | 7 +- test/CsvFileIterator.php | 2 +- test/FactoryTest.php | 88 ++++++++++++----------- test/ManagerTest.php | 2 + 22 files changed, 468 insertions(+), 518 deletions(-) diff --git a/rector.php b/rector.php index 74e5e82..894587f 100644 --- a/rector.php +++ b/rector.php @@ -16,7 +16,7 @@ ->withPreparedSets( codeQuality: true, deadCode: true, - typeDeclarations: true, + // typeDeclarations: true, ) ->withComposerBased( phpunit: true, diff --git a/src/NotFoundException.php b/src/NotFoundException.php index b26fe39..a18c717 100644 --- a/src/NotFoundException.php +++ b/src/NotFoundException.php @@ -1,5 +1,7 @@ word == $word) { + if ($this->word === $word) { $this->step1b(); } @@ -125,11 +125,9 @@ public function stem($word) private function step0() { - if (($position = $this->search(static::$attached_pronoun)) !== false) { - if ($this->inR1($position)) { - $this->word = UTF8::substr($this->word, 0, $position); - return true; - } + if ($position = $this->search(static::$attached_pronoun) !== false && $this->inR1($position)) { + $this->word = UTF8::substr($this->word, 0, $position); + return true; } return false; } diff --git a/src/Stemmer/Danish.php b/src/Stemmer/Danish.php index c539fdb..335cce1 100644 --- a/src/Stemmer/Danish.php +++ b/src/Stemmer/Danish.php @@ -15,7 +15,7 @@ class Danish extends Stem /** * All danish vowels */ - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'y', 'æ', 'å', 'ø'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'y', 'æ', 'å', 'ø']; /** * {@inheritdoc} @@ -57,7 +57,7 @@ public function stem($word): string private function hasValidSEnding($word) { $lastLetter = UTF8::substr($word, -1, 1); - return in_array($lastLetter, array('a', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'v', 'y', 'z', 'å')); + return in_array($lastLetter, ['a', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'v', 'y', 'z', 'å']); } /** @@ -69,24 +69,25 @@ private function step1() // hed ethed ered e erede ende erende ene erne ere en heden eren er heder erer // heds es endes erendes enes ernes eres ens hedens erens ers ets erets et eret // delete - if ( ($position = $this->searchIfInR1(array( + if ( ($position = $this->searchIfInR1([ 'erendes', 'erende', 'hedens', 'erede', 'ethed', 'heden', 'endes', 'erets', 'heder', 'ernes', 'erens', 'ered', 'ende', 'erne', 'eres', 'eren', 'eret', 'erer', 'enes', 'heds', 'ens', 'ene', 'ere', 'ers', 'ets', 'hed', 'es', 'et', 'er', 'en', 'e' - ))) !== false) { + ])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); return true; } // s // delete if preceded by a valid s-ending - if ( ($position = $this->searchIfInR1(array('s'))) !== false) { + if ( ($position = $this->searchIfInR1(['s'])) !== false) { $word = UTF8::substr($this->word, 0, $position); if ($this->hasValidSEnding($word)) { $this->word = $word; } return true; } + return null; } /** @@ -96,7 +97,7 @@ private function step1() */ private function step2() { - if ($this->searchIfInR1(array('gd', 'dt', 'gt', 'kt')) !== false) { + if ($this->searchIfInR1(['gd', 'dt', 'gt', 'kt']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); } } @@ -107,14 +108,14 @@ private function step2() private function step3() { // If the word ends igst, remove the final st. - if ($this->search(array('igst')) !== false) { + if ($this->search(['igst']) !== false) { $this->word = UTF8::substr($this->word, 0, -2); } // Search for the longest among the following suffixes in R1, and perform the action indicated. // ig lig elig els // delete, and then repeat step 2 - if ( ($position = $this->searchIfInR1(array('elig', 'lig', 'ig', 'els'))) !== false) { + if ( ($position = $this->searchIfInR1(['elig', 'lig', 'ig', 'els'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); $this->step2(); return true; @@ -122,9 +123,10 @@ private function step3() // løst // replace with løs - if ($this->searchIfInR1(array('løst')) !== false) { + if ($this->searchIfInR1(['løst']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); } + return null; } /** diff --git a/src/Stemmer/Dutch.php b/src/Stemmer/Dutch.php index 8fba0d6..8e03aed 100644 --- a/src/Stemmer/Dutch.php +++ b/src/Stemmer/Dutch.php @@ -15,7 +15,7 @@ class Dutch extends Stem /** * All dutch vowels */ - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'y', 'è'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'y', 'è']; /** * {@inheritdoc} @@ -31,8 +31,8 @@ public function stem($word) // First, remove all umlaut and acute accents. $this->word = str_replace( - array('ä', 'ë', 'ï', 'ö', 'ü', 'á', 'é', 'í', 'ó', 'ú'), - array('a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u'), + ['ä', 'ë', 'ï', 'ö', 'ü', 'á', 'é', 'í', 'ó', 'ú'], + ['a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u'], $this->word); $this->plainVowels = implode('', self::$vowels); @@ -72,7 +72,7 @@ public function stem($word) private function hasValidSEnding($word) { $lastLetter = UTF8::substr($word, -1, 1); - return !in_array($lastLetter, array_merge(self::$vowels, array('j'))); + return !in_array($lastLetter, array_merge(self::$vowels, ['j'])); } /** @@ -88,10 +88,7 @@ private function hasValidEnEnding($word) } $threeLastLetters = UTF8::substr($word, -3, 3); - if ($threeLastLetters == 'gem') { - return false; - } - return true; + return $threeLastLetters != 'gem'; } /** @@ -99,7 +96,7 @@ private function hasValidEnEnding($word) */ private function unDoubling() { - if ($this->search(array('kk', 'dd', 'tt')) !== false) { + if ($this->search(['kk', 'dd', 'tt']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); } } @@ -112,7 +109,7 @@ private function step1() { // heden // replace with heid if in R1 - if ( ($position = $this->search(array('heden'))) !== false) { + if ( ($position = $this->search(['heden'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(heden)$#u', 'heid', $this->word); } @@ -121,7 +118,7 @@ private function step1() // en ene // delete if in R1 and preceded by a valid en-ending, and then undouble the ending - if ( ($position = $this->search(array('ene', 'en'))) !== false) { + if ( ($position = $this->search(['ene', 'en'])) !== false) { if ($this->inR1($position)) { $word = UTF8::substr($this->word, 0, $position); if ($this->hasValidEnEnding($word)) { @@ -134,7 +131,7 @@ private function step1() // s se // delete if in R1 and preceded by a valid s-ending - if ( ($position = $this->search(array('se', 's'))) !== false) { + if ( ($position = $this->search(['se', 's'])) !== false) { if ($this->inR1($position)) { $word = UTF8::substr($this->word, 0, $position); if ($this->hasValidSEnding($word)) { @@ -153,15 +150,13 @@ private function step1() */ private function step2() { - if ( ($position = $this->search(array('e'))) !== false) { - if ($this->inR1($position)) { - $letter = UTF8::substr($this->word, -2, 1); - if (!in_array($letter, self::$vowels)) { - $this->word = UTF8::substr($this->word, 0, $position); - $this->unDoubling(); + if ($position = $this->search(['e']) !== false && $this->inR1($position)) { + $letter = UTF8::substr($this->word, -2, 1); + if (!in_array($letter, self::$vowels)) { + $this->word = UTF8::substr($this->word, 0, $position); + $this->unDoubling(); - return true; - } + return true; } } @@ -174,20 +169,16 @@ private function step2() */ private function step3a() { - if ( ($position = $this->search(array('heid'))) !== false) { - if ($this->inR2($position)) { - $letter = UTF8::substr($this->word, -5, 1); - if ($letter !== 'c') { - $this->word = UTF8::substr($this->word, 0, $position); + if ($position = $this->search(['heid']) !== false && $this->inR2($position)) { + $letter = UTF8::substr($this->word, -5, 1); + if ($letter !== 'c') { + $this->word = UTF8::substr($this->word, 0, $position); - if ( ($position = $this->search(array('en'))) !== false) { - if ($this->inR1($position)) { - $word = UTF8::substr($this->word, 0, $position); - if ($this->hasValidEnEnding($word)) { - $this->word = $word; - $this->unDoubling(); - } - } + if ($position = $this->search(['en']) !== false && $this->inR1($position)) { + $word = UTF8::substr($this->word, 0, $position); + if ($this->hasValidEnEnding($word)) { + $this->word = $word; + $this->unDoubling(); } } } @@ -204,11 +195,11 @@ private function step3b($removedE) // end ing // delete if in R2 // if preceded by ig, delete if in R2 and not preceded by e, otherwise undouble the ending - if ( ($position = $this->search(array('end', 'ing'))) !== false) { + if ( ($position = $this->search(['end', 'ing'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); - if ( ($position2 = $this->searchIfInR2(array('ig'))) !== false) { + if ( ($position2 = $this->searchIfInR2(['ig'])) !== false) { $letter = UTF8::substr($this->word, -3, 1); if ($letter !== 'e') { $this->word = UTF8::substr($this->word, 0, $position2); @@ -224,7 +215,7 @@ private function step3b($removedE) // ig // delete if in R2 and not preceded by e - if ( ($position = $this->search(array('ig'))) !== false) { + if ( ($position = $this->search(['ig'])) !== false) { if ($this->inR2($position)) { $letter = UTF8::substr($this->word, -3, 1); if ($letter !== 'e') { @@ -236,7 +227,7 @@ private function step3b($removedE) // lijk // delete if in R2, and then repeat step 2 - if ( ($position = $this->search(array('lijk'))) !== false) { + if ( ($position = $this->search(['lijk'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); $this->step2(); @@ -246,7 +237,7 @@ private function step3b($removedE) // baar // delete if in R2 - if ( ($position = $this->search(array('baar'))) !== false) { + if ( ($position = $this->search(['baar'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -255,7 +246,7 @@ private function step3b($removedE) // bar // delete if in R2 and if step 2 actually removed an e - if ( ($position = $this->search(array('bar'))) !== false) { + if ( ($position = $this->search(['bar'])) !== false) { if ($this->inR2($position) && $removedE) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -274,13 +265,13 @@ private function step4() { // D is a non-vowel other than I $d = UTF8::substr($this->word, -1, 1); - if (in_array($d, array_merge(self::$vowels, array('I')))) { + if (in_array($d, array_merge(self::$vowels, ['I']))) { return false; } // V is double a, e, o or u $v = UTF8::substr($this->word, -3, 2); - if (!in_array($v, array('aa', 'ee', 'oo', 'uu'))) { + if (!in_array($v, ['aa', 'ee', 'oo', 'uu'])) { return false; } $singleV = UTF8::substr($v, 0, 1); @@ -293,6 +284,7 @@ private function step4() $this->word = UTF8::substr($this->word, 0, -4); $this->word .= $c . $singleV .$d; + return null; } /** @@ -301,6 +293,6 @@ private function step4() */ private function finish() { - $this->word = str_replace(array('I', 'Y'), array('i', 'y'), $this->word); + $this->word = str_replace(['I', 'Y'], ['i', 'y'], $this->word); } } diff --git a/src/Stemmer/English.php b/src/Stemmer/English.php index 0e747d0..921d90d 100644 --- a/src/Stemmer/English.php +++ b/src/Stemmer/English.php @@ -16,11 +16,11 @@ class English extends Stem /** * All english vowels */ - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'y'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'y']; - protected static $doubles = array('bb', 'dd', 'ff', 'gg', 'mm', 'nn', 'pp', 'rr', 'tt'); + protected static $doubles = ['bb', 'dd', 'ff', 'gg', 'mm', 'nn', 'pp', 'rr', 'tt']; - protected static $liEnding = array('c', 'd', 'e', 'g', 'h', 'k', 'm', 'n', 'r', 't'); + protected static $liEnding = ['c', 'd', 'e', 'g', 'h', 'k', 'm', 'n', 'r', 't']; /** * {@inheritdoc} @@ -87,7 +87,7 @@ public function stem($word) */ private function step0() { - if ( ($position = $this->search(array("'s'", "'s", "'"))) !== false) { + if ( ($position = $this->search(["'s'", "'s", "'"])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); } } @@ -96,14 +96,14 @@ private function step1a() { // sses // replace by ss - if ( ($position = $this->search(array('sses'))) !== false) { + if ( ($position = $this->search(['sses'])) !== false) { $this->word = preg_replace('#(sses)$#u', 'ss', $this->word); return true; } // ied+ ies* // replace by i if preceded by more than one letter, otherwise by ie (so ties -> tie, cries -> cri) - if ( ($position = $this->search(array('ied', 'ies'))) !== false) { + if ( ($position = $this->search(['ied', 'ies'])) !== false) { if ($position > 1) { $this->word = preg_replace('#(ied|ies)$#u', 'i', $this->word); @@ -115,13 +115,13 @@ private function step1a() // us+ ss // do nothing - if ( ($position = $this->search(array('us', 'ss'))) !== false) { + if ( ($position = $this->search(['us', 'ss'])) !== false) { return true; } // s // delete if the preceding word part contains a vowel not immediately before the s (so gas and this retain the s, gaps and kiwis lose it) - if ( ($position = $this->search(array('s'))) !== false) { + if ( ($position = $this->search(['s'])) !== false) { for ($i=0; $i<$position-1; $i++) { $letter = UTF8::substr($this->word, $i, 1); @@ -143,7 +143,7 @@ private function step1b() { // eed eedly+ // replace by ee if in R1 - if ( ($position = $this->search(array('eedly', 'eed'))) !== false) { + if ( ($position = $this->search(['eedly', 'eed'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(eedly|eed)$#u', 'ee', $this->word); } @@ -155,14 +155,14 @@ private function step1b() // if the word ends at, bl or iz add e (so luxuriat -> luxuriate), or // if the word ends with a double remove the last letter (so hopp -> hop), or // if the word is short, add e (so hop -> hope) - if ( ($position = $this->search(array('edly', 'ingly', 'ed', 'ing'))) !== false) { + if ( ($position = $this->search(['edly', 'ingly', 'ed', 'ing'])) !== false) { for ($i=0; $i<$position; $i++) { $letter = UTF8::substr($this->word, $i, 1); if (in_array($letter, self::$vowels)) { $this->word = UTF8::substr($this->word, 0, $position); - if ($this->search(array('at', 'bl', 'iz')) !== false) { + if ($this->search(['at', 'bl', 'iz']) !== false) { $this->word .= 'e'; } elseif ( ($position2 = $this->search(self::$doubles)) !== false) { @@ -194,7 +194,7 @@ private function step1c() return true; } - if ( ($position = $this->search(array('y', 'Y'))) !== false) { + if ( ($position = $this->search(['y', 'Y'])) !== false) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); @@ -215,7 +215,7 @@ private function step1c() private function step2() { // iveness iviti: replace by ive - if ( ($position = $this->search(array('iveness', 'iviti'))) !== false) { + if ( ($position = $this->search(['iveness', 'iviti'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(iveness|iviti)$#u', 'ive', $this->word); } @@ -223,7 +223,7 @@ private function step2() } // ousli ousness: replace by ous - if ( ($position = $this->search(array('ousli', 'ousness'))) !== false) { + if ( ($position = $this->search(['ousli', 'ousness'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(ousli|ousness)$#u', 'ous', $this->word); } @@ -231,7 +231,7 @@ private function step2() } // izer ization: replace by ize - if ( ($position = $this->search(array('izer', 'ization'))) !== false) { + if ( ($position = $this->search(['izer', 'ization'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(izer|ization)$#u', 'ize', $this->word); } @@ -239,7 +239,7 @@ private function step2() } // ational ation ator: replace by ate - if ( ($position = $this->search(array('ational', 'ation', 'ator'))) !== false) { + if ( ($position = $this->search(['ational', 'ation', 'ator'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(ational|ation|ator)$#u', 'ate', $this->word); } @@ -247,7 +247,7 @@ private function step2() } // biliti bli+: replace by ble - if ( ($position = $this->search(array('biliti', 'bli'))) !== false) { + if ( ($position = $this->search(['biliti', 'bli'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(biliti|bli)$#u', 'ble', $this->word); } @@ -255,7 +255,7 @@ private function step2() } // lessli+: replace by less - if ( ($position = $this->search(array('lessli'))) !== false) { + if ( ($position = $this->search(['lessli'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(lessli)$#u', 'less', $this->word); } @@ -263,7 +263,7 @@ private function step2() } // fulness: replace by ful - if ( ($position = $this->search(array('fulness', 'fulli'))) !== false) { + if ( ($position = $this->search(['fulness', 'fulli'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(fulness|fulli)$#u', 'ful', $this->word); } @@ -271,7 +271,7 @@ private function step2() } // tional: replace by tion - if ( ($position = $this->search(array('tional'))) !== false) { + if ( ($position = $this->search(['tional'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(tional)$#u', 'tion', $this->word); } @@ -279,7 +279,7 @@ private function step2() } // alism aliti alli: replace by al - if ( ($position = $this->search(array('alism', 'aliti', 'alli'))) !== false) { + if ( ($position = $this->search(['alism', 'aliti', 'alli'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(alism|aliti|alli)$#u', 'al', $this->word); } @@ -287,7 +287,7 @@ private function step2() } // enci: replace by ence - if ( ($position = $this->search(array('enci'))) !== false) { + if ( ($position = $this->search(['enci'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(enci)$#u', 'ence', $this->word); } @@ -295,7 +295,7 @@ private function step2() } // anci: replace by ance - if ( ($position = $this->search(array('anci'))) !== false) { + if ( ($position = $this->search(['anci'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(anci)$#u', 'ance', $this->word); } @@ -303,7 +303,7 @@ private function step2() } // abli: replace by able - if ( ($position = $this->search(array('abli'))) !== false) { + if ( ($position = $this->search(['abli'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(abli)$#u', 'able', $this->word); } @@ -311,7 +311,7 @@ private function step2() } // entli: replace by ent - if ( ($position = $this->search(array('entli'))) !== false) { + if ( ($position = $this->search(['entli'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(entli)$#u', 'ent', $this->word); } @@ -319,7 +319,7 @@ private function step2() } // ogi+: replace by og if preceded by l - if ( ($position = $this->search(array('ogi'))) !== false) { + if ( ($position = $this->search(['ogi'])) !== false) { if ($this->inR1($position)) { $before = $position - 1; @@ -334,7 +334,7 @@ private function step2() } // li+: delete if preceded by a valid li-ending - if ( ($position = $this->search(array('li'))) !== false) { + if ( ($position = $this->search(['li'])) !== false) { if ($this->inR1($position)) { // a letter for you @@ -358,37 +358,37 @@ private function step2() private function step3() { // ational+: replace by ate - if ($this->searchIfInR1(array('ational')) !== false) { + if ($this->searchIfInR1(['ational']) !== false) { $this->word = preg_replace('#(ational)$#u', 'ate', $this->word); return true; } // tional+: replace by tion - if ($this->searchIfInR1(array('tional')) !== false) { + if ($this->searchIfInR1(['tional']) !== false) { $this->word = preg_replace('#(tional)$#u', 'tion', $this->word); return true; } // alize: replace by al - if ($this->searchIfInR1(array('alize')) !== false) { + if ($this->searchIfInR1(['alize']) !== false) { $this->word = preg_replace('#(alize)$#u', 'al', $this->word); return true; } // icate iciti ical: replace by ic - if ($this->searchIfInR1(array('icate', 'iciti', 'ical')) !== false) { + if ($this->searchIfInR1(['icate', 'iciti', 'ical']) !== false) { $this->word = preg_replace('#(icate|iciti|ical)$#u', 'ic', $this->word); return true; } // ful ness: delete - if ( ($position = $this->searchIfInR1(array('ful', 'ness'))) !== false) { + if ( ($position = $this->searchIfInR1(['ful', 'ness'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); return true; } // ative*: delete if in R2 - if ( (($position = $this->searchIfInR1(array('ative'))) !== false) && ($this->inR2($position)) ) { + if ( (($position = $this->searchIfInR1(['ative'])) !== false) && ($this->inR2($position)) ) { $this->word = UTF8::substr($this->word, 0, $position); return true; } @@ -404,9 +404,9 @@ private function step4() { // ement ance ence able ible ant ment ent ism ate iti ous ive ize al er ic // delete - if ( ($position = $this->search(array( + if ( ($position = $this->search([ 'ance', 'ence', 'ement', 'able', 'ible', 'ant', 'ment', 'ent', 'ism', - 'ate', 'iti', 'ous', 'ive', 'ize', 'al', 'er', 'ic'))) !== false) { + 'ate', 'iti', 'ous', 'ive', 'ize', 'al', 'er', 'ic'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); @@ -416,7 +416,7 @@ private function step4() // ion // delete if preceded by s or t - if ( ($position = $this->searchIfInR2(array('ion'))) !== false) { + if ( ($position = $this->searchIfInR2(['ion'])) !== false) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); @@ -438,7 +438,7 @@ private function step5() { // e // delete if in R2, or in R1 and not preceded by a short syllable - if ( ($position = $this->search(array('e'))) !== false) { + if ( ($position = $this->search(['e'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); @@ -453,7 +453,7 @@ private function step5() // l // delete if in R2 and preceded by l - if ( ($position = $this->searchIfInR2(array('l'))) !== false) { + if ( ($position = $this->searchIfInR2(['l'])) !== false) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); @@ -494,7 +494,7 @@ private function exceptionR1() */ private function exception1() { - $exceptions = array( + $exceptions = [ 'skis' => 'ski', 'skies' => 'sky', 'dying' => 'die', @@ -514,13 +514,9 @@ private function exception1() 'cosmos' => 'cosmos', 'bias' => 'bias', 'andes' => 'andes' - ); + ]; - if (isset($exceptions[$this->word])) { - return $exceptions[$this->word]; - } - - return null; + return $exceptions[$this->word] ?? null; } /** @@ -528,7 +524,7 @@ private function exception1() */ private function exception2() { - $exceptions = array( + $exceptions = [ 'inning' => 'inning', 'outing' => 'outing', 'canning' => 'canning', @@ -537,13 +533,9 @@ private function exception2() 'proceed' => 'proceed', 'exceed' => 'exceed', 'succeed' => 'succeed' - ); + ]; - if (isset($exceptions[$this->word])) { - return $exceptions[$this->word]; - } - - return null; + return $exceptions[$this->word] ?? null; } /** @@ -584,19 +576,12 @@ private function searchShortSyllabe($from, $nbLetters) $first = UTF8::substr($this->word, $from, 1); $second = UTF8::substr($this->word, ($from+1), 1); - if ($nbLetters == 2) { - if ( (in_array($first, self::$vowels)) && (!in_array($second, self::$vowels)) ) { - return true; - } + if ($nbLetters == 2 && (in_array($first, self::$vowels) && !in_array($second, self::$vowels))) { + return true; } $third = UTF8::substr($this->word, ($from+2), 1); - - if ( (!in_array($first, self::$vowels)) && (in_array($second, self::$vowels)) - && (!in_array($third, array_merge(self::$vowels, array('x', 'Y', 'w'))))) { - return true; - } - - return false; + return (!in_array($first, self::$vowels)) && (in_array($second, self::$vowels)) + && (!in_array($third, array_merge(self::$vowels, ['x', 'Y', 'w']))); } } diff --git a/src/Stemmer/Finnish.php b/src/Stemmer/Finnish.php index 25539b2..136bc7b 100644 --- a/src/Stemmer/Finnish.php +++ b/src/Stemmer/Finnish.php @@ -19,17 +19,17 @@ class Finnish extends Stem /** * All swedish vowels */ - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'y', 'ä', 'ö'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'y', 'ä', 'ö']; - protected static $consonants = array('b', 'c', 'd', 'f', 'g', 'h', 'j', - 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z'); + protected static $consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', + 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z']; - protected static $restrictedVowels = array('a', 'e', 'i', 'o', 'u', 'ä', 'ö'); + protected static $restrictedVowels = ['a', 'e', 'i', 'o', 'u', 'ä', 'ö']; /** * Long restricted vowels, ie. doubled vowels. */ - protected static $longVowels = array('aa', 'ee', 'ii', 'oo', 'uu', 'ää', 'öö'); + protected static $longVowels = ['aa', 'ee', 'ii', 'oo', 'uu', 'ää', 'öö']; private $_removedInStep3 = false; @@ -73,7 +73,7 @@ private function step1() { // (a) kin kaan kään ko kö han hän pa pä // delete if preceded by n, t or a vowel - if (($position = $this->searchIfInR1(array('kaan', 'kään', 'kin', 'han', 'hän', 'ko', 'kö', 'pa', 'pä'))) !== false) { + if (($position = $this->searchIfInR1(['kaan', 'kään', 'kin', 'han', 'hän', 'ko', 'kö', 'pa', 'pä'])) !== false) { $lastLetter = Utf8::substr($this->word, ($position-1), 1); if (in_array($lastLetter, array_merge(['t', 'n'], self::$vowels))) { @@ -87,7 +87,7 @@ private function step1() // sti // delete if in R2 - if (($position = $this->searchIfInR1(array('sti'))) !== false) { + if (($position = $this->searchIfInR1(['sti'])) !== false) { if ($this->inR2($position)) { $this->word = Utf8::substr($this->word, 0, $position); $this->r1(); @@ -96,6 +96,7 @@ private function step1() return true; } + return null; } /** @@ -110,7 +111,7 @@ private function step2() { // si // delete if not preceded by k - if (($position = $this->searchIfInR1(array('si'))) !== false) { + if (($position = $this->searchIfInR1(['si'])) !== false) { $lastLetter = Utf8::substr($this->word, ($position-1), 1); if ($lastLetter !== 'k') { @@ -123,10 +124,10 @@ private function step2() // ni // delete - if (($position = $this->searchIfInR1(array('ni'))) !== false) { + if (($position = $this->searchIfInR1(['ni'])) !== false) { $this->word = Utf8::substr($this->word, 0, $position); // if preceded by kse, replace with ksi - if ( ($position = $this->search(array('kse'))) !== false) { + if ( ($position = $this->search(['kse'])) !== false) { $this->word = preg_replace('#(kse)$#u', 'ksi', $this->word); } $this->r1(); @@ -136,7 +137,7 @@ private function step2() // nsa nsä mme nne // delete - if (($position = $this->searchIfInR1(array('nsa', 'nsä', 'mme', 'nne'))) !== false) { + if (($position = $this->searchIfInR1(['nsa', 'nsä', 'mme', 'nne'])) !== false) { $this->word = Utf8::substr($this->word, 0, $position); $this->r1(); $this->r2(); @@ -145,11 +146,11 @@ private function step2() // an // delete if preceded by one of ta ssa sta lla lta na - if (($position = $this->searchIfInR1(array('an'))) !== false) { + if (($position = $this->searchIfInR1(['an'])) !== false) { $word = Utf8::substr($this->word, 0, $position); $lastThreeLetters = Utf8::substr($word, -3, 3); $lastTwoLetters = Utf8::substr($word, -2, 2); - if (in_array($lastThreeLetters, array('ssa', 'sta', 'lla', 'lta'), true) || in_array($lastTwoLetters, array('na', 'ta'), true)) { + if (in_array($lastThreeLetters, ['ssa', 'sta', 'lla', 'lta'], true) || in_array($lastTwoLetters, ['na', 'ta'], true)) { $this->word = $word; $this->r1(); $this->r2(); @@ -159,11 +160,11 @@ private function step2() // än // delete if preceded by one of tä ssä stä llä ltä nä - if (($position = $this->searchIfInR1(array('än'))) !== false) { + if (($position = $this->searchIfInR1(['än'])) !== false) { $word = Utf8::substr($this->word, 0, $position); $lastThreeLetters = Utf8::substr($word, -3, 3); $lastTwoLetters = Utf8::substr($word, -2, 2); - if (in_array($lastThreeLetters, array('ssä', 'stä', 'llä', 'ltä'), true) || in_array($lastTwoLetters, array('nä', 'tä'), true)) { + if (in_array($lastThreeLetters, ['ssä', 'stä', 'llä', 'ltä'], true) || in_array($lastTwoLetters, ['nä', 'tä'], true)) { $this->word = $word; $this->r1(); $this->r2(); @@ -173,11 +174,11 @@ private function step2() // en // delete if preceded by one of lle ine - if (($position = $this->searchIfInR1(array('en'))) !== false) { + if (($position = $this->searchIfInR1(['en'])) !== false) { $word = Utf8::substr($this->word, 0, $position); if (Utf8::strlen($this->word) > 4) { $lastThreeLetters = Utf8::substr($this->word, -5, 3); - if (in_array($lastThreeLetters, array('lle', 'ine'), true)) { + if (in_array($lastThreeLetters, ['lle', 'ine'], true)) { $this->word = $word; $this->r1(); $this->r2(); @@ -185,6 +186,7 @@ private function step2() } } } + return null; } /** @@ -203,7 +205,7 @@ private function step3() if ($vowel === 'u') { continue; } - if (($position = $this->searchIfInR1(array('h' . $vowel . 'n'))) !== false) { + if (($position = $this->searchIfInR1(['h' . $vowel . 'n'])) !== false) { $lastLetter = Utf8::substr($this->word, $position-1, 1); if ($lastLetter === $vowel) { $this->word = Utf8::substr($this->word, 0, $position); @@ -217,7 +219,7 @@ private function step3() // siin den tten // delete if preceded by Vi - if (($position = $this->searchIfInR1(array('siin', 'den', 'tten'))) !== false) { + if (($position = $this->searchIfInR1(['siin', 'den', 'tten'])) !== false) { $lastLetter = Utf8::substr($this->word, ($position-1), 1); if ($lastLetter === 'i') { $nextLastLetter = Utf8::substr($this->word, ($position-2), 1); @@ -233,7 +235,7 @@ private function step3() // seen // delete if preceded by LV - if (($position = $this->searchIfInR1(array('seen'))) !== false) { + if (($position = $this->searchIfInR1(['seen'])) !== false) { $lastLetters = Utf8::substr($this->word, ($position-2), 2); if (in_array($lastLetters, self::$longVowels, true)) { @@ -247,7 +249,7 @@ private function step3() // tta ttä // delete if preceded by e - if (($position = $this->searchIfInR1(array('tta', 'ttä'))) !== false) { + if (($position = $this->searchIfInR1(['tta', 'ttä'])) !== false) { $lastLetter = Utf8::substr($this->word, ($position-1), 1); if ($lastLetter === 'e') { @@ -261,7 +263,7 @@ private function step3() // ta tä ssa ssä sta stä lla llä lta ltä lle na nä ksi ine // delete - if (($position = $this->searchIfInR1(array('ssa', 'ssä', 'sta', 'stä', 'lla', 'llä', 'lta', 'ltä', 'lle', 'ksi', 'na', 'nä', 'ine', 'ta', 'tä'))) !== false) { + if (($position = $this->searchIfInR1(['ssa', 'ssä', 'sta', 'stä', 'lla', 'llä', 'lta', 'ltä', 'lle', 'ksi', 'na', 'nä', 'ine', 'ta', 'tä'])) !== false) { $this->word = Utf8::substr($this->word, 0, $position); $this->_removedInStep3 = true; $this->r1(); @@ -271,7 +273,7 @@ private function step3() // a ä // delete if preceded by cv - if (($position = $this->searchIfInR1(array('a', 'ä'))) !== false) { + if (($position = $this->searchIfInR1(['a', 'ä'])) !== false) { $lastLetter = Utf8::substr($this->word, ($position-1), 1); $nextLastLetter = Utf8::substr($this->word, ($position-2), 1); @@ -286,7 +288,7 @@ private function step3() // n // delete, and if preceded by LV or ie, delete the last vowel - if (($position = $this->searchIfInR1(array('n'))) !== false) { + if (($position = $this->searchIfInR1(['n'])) !== false) { $lastLetters = Utf8::substr($this->word, ($position-2), 2); if (in_array($lastLetters, self::$longVowels, true) || $lastLetters === 'ie') { @@ -299,6 +301,7 @@ private function step3() $this->_removedInStep3 = true; return true; } + return null; } /** @@ -313,7 +316,7 @@ private function step4() { // mpi mpa mpä mmi mma mmä // delete if not preceded by po - if (($position = $this->searchIfInR2(array('mpi', 'mpa', 'mpä', 'mmi', 'mma', 'mmä'))) !== false) { + if (($position = $this->searchIfInR2(['mpi', 'mpa', 'mpä', 'mmi', 'mma', 'mmä'])) !== false) { $lastLetters = Utf8::substr($this->word, ($position-2), 2); if ($lastLetters !== 'po') { $this->word = Utf8::substr($this->word, 0, $position); @@ -325,12 +328,13 @@ private function step4() // impi impa impä immi imma immä eja ejä // delete - if (($position = $this->searchIfInR2(array('impi', 'impa', 'impä', 'immi', 'imma', 'immä', 'eja', 'ejä'))) !== false) { + if (($position = $this->searchIfInR2(['impi', 'impa', 'impä', 'immi', 'imma', 'immä', 'eja', 'ejä'])) !== false) { $this->word = Utf8::substr($this->word, 0, $position); $this->r1(); $this->r2(); return true; } + return null; } /** @@ -346,36 +350,35 @@ private function step4() private function step5() { if ($this->_removedInStep3) { - if (($position = $this->searchIfInR1(array('i', 'j'))) !== false) { + if (($position = $this->searchIfInR1(['i', 'j'])) !== false) { $this->word = Utf8::substr($this->word, 0, $position); $this->r1(); $this->r2(); return true; } - } else { - if (($position = $this->searchIfInR1(array('t'))) !== false) { - $lastLetter = Utf8::substr($this->word, ($position-1), 1); - if (in_array($lastLetter, self::$vowels, true)) { - $this->word = Utf8::substr($this->word, 0, $position); + } elseif (($position = $this->searchIfInR1(['t'])) !== false) { + $lastLetter = Utf8::substr($this->word, ($position-1), 1); + if (in_array($lastLetter, self::$vowels, true)) { + $this->word = Utf8::substr($this->word, 0, $position); + $this->r1(); + $this->r2(); + if (($position2 = $this->searchIfInR2(['imma'])) !== false) { + $this->word = Utf8::substr($this->word, 0, $position2); $this->r1(); $this->r2(); - if (($position2 = $this->searchIfInR2(array('imma'))) !== false) { + return true; + } elseif (($position2 = $this->searchIfInR2(['mma'])) !== false) { + $lastLetters = Utf8::substr($this->word, ($position2-2), 2); + if ($lastLetters !== 'po') { $this->word = Utf8::substr($this->word, 0, $position2); $this->r1(); $this->r2(); return true; - } elseif (($position2 = $this->searchIfInR2(array('mma'))) !== false) { - $lastLetters = Utf8::substr($this->word, ($position2-2), 2); - if ($lastLetters !== 'po') { - $this->word = Utf8::substr($this->word, 0, $position2); - $this->r1(); - $this->r2(); - return true; - } } } } } + return null; } @@ -399,7 +402,7 @@ private function step6() // delete the last letter $lastLetter = Utf8::substr($this->r1, -1, 1); $secondToLastLetter = Utf8::substr($this->r1, -2, 1); - if (in_array($secondToLastLetter, self::$consonants, true) && in_array($lastLetter, array('a', 'e', 'i', 'ä'))) { + if (in_array($secondToLastLetter, self::$consonants, true) && in_array($lastLetter, ['a', 'e', 'i', 'ä'])) { $this->word = Utf8::substr($this->word, 0, -1); $this->r1(); $this->r2(); @@ -408,7 +411,7 @@ private function step6() // c) If R1 ends oj or uj // delete the last letter $twoLastLetters = Utf8::substr($this->r1, -2, 2); - if (in_array($twoLastLetters, array('oj', 'uj'))) { + if (in_array($twoLastLetters, ['oj', 'uj'])) { $this->word = Utf8::substr($this->word, 0, -1); $this->r1(); $this->r2(); diff --git a/src/Stemmer/French.php b/src/Stemmer/French.php index cef305e..ed33897 100644 --- a/src/Stemmer/French.php +++ b/src/Stemmer/French.php @@ -15,7 +15,7 @@ class French extends Stem /** * All french vowels */ - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'y', 'â', 'à', 'ë', 'é', 'ê', 'è', 'ï', 'î', 'ô', 'û', 'ù'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'y', 'â', 'à', 'ë', 'é', 'ê', 'è', 'ï', 'î', 'ô', 'û', 'ù']; /** * {@inheritdoc} @@ -43,14 +43,14 @@ public function stem($word) $nextStep = $this->step1(); // Do step 2a if either no ending was removed by step 1, or if one of endings amment, emment, ment, ments was found. - if ( ($nextStep == 2) || ($this->originalWord == $this->word) ) { + if ( ($nextStep == 2) || ($this->originalWord === $this->word) ) { $modified = $this->step2a(); if (!$modified) { $this->step2b(); } } - if ($this->word != $this->originalWord) { + if ($this->word !== $this->originalWord) { $this->step3(); } else { @@ -94,7 +94,7 @@ private function step1() { // ance iqUe isme able iste eux ances iqUes ismes ables istes // delete if in R2 - if ( ($position = $this->search(array('ances', 'iqUes', 'ismes', 'ables', 'istes', 'ance', 'iqUe','isme', 'able', 'iste', 'eux'))) !== false) { + if ( ($position = $this->search(['ances', 'iqUes', 'ismes', 'ables', 'istes', 'ance', 'iqUe','isme', 'able', 'iste', 'eux'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -104,11 +104,11 @@ private function step1() // atrice ateur ation atrices ateurs ations // delete if in R2 // if preceded by ic, delete if in R2, else replace by iqU - if ( ($position = $this->search(array('atrices', 'ateurs', 'ations', 'atrice', 'ateur', 'ation'))) !== false) { + if ( ($position = $this->search(['atrices', 'ateurs', 'ations', 'atrice', 'ateur', 'ation'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); - if ( ($position2 = $this->searchIfInR2(array('ic'))) !== false) { + if ( ($position2 = $this->searchIfInR2(['ic'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position2); } else { $this->word = preg_replace('#(ic)$#u', 'iqU', $this->word); @@ -120,7 +120,7 @@ private function step1() // logie logies // replace with log if in R2 - if ( ($position = $this->search(array('logies', 'logie'))) !== false) { + if ( ($position = $this->search(['logies', 'logie'])) !== false) { if ($this->inR2($position)) { $this->word = preg_replace('#(logies|logie)$#u', 'log', $this->word); } @@ -129,7 +129,7 @@ private function step1() // usion ution usions utions // replace with u if in R2 - if ( ($position = $this->search(array('usions', 'utions', 'usion', 'ution'))) !== false) { + if ( ($position = $this->search(['usions', 'utions', 'usion', 'ution'])) !== false) { if ($this->inR2($position)) { $this->word = preg_replace('#(usion|ution|usions|utions)$#u', 'u', $this->word); } @@ -138,7 +138,7 @@ private function step1() // ence ences // replace with ent if in R2 - if ( ($position = $this->search(array('ences', 'ence'))) !== false) { + if ( ($position = $this->search(['ences', 'ence'])) !== false) { if ($this->inR2($position)) { $this->word = preg_replace('#(ence|ences)$#u', 'ent', $this->word); } @@ -147,7 +147,7 @@ private function step1() // issement issements // delete if in R1 and preceded by a non-vowel - if ( ($position = $this->search(array('issements', 'issement'))) != false) { + if ( ($position = $this->search(['issements', 'issement'])) != false) { if ($this->inR1($position)) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); @@ -164,7 +164,7 @@ private function step1() // if preceded by eus, delete if in R2, else replace by eux if in R1, otherwise, // if preceded by abl or iqU, delete if in R2, otherwise, // if preceded by ièr or Ièr, replace by i if in RV - if ( ($position = $this->search(array('ements', 'ement'))) !== false) { + if ( ($position = $this->search(['ements', 'ement'])) !== false) { // delete if in RV if ($this->inRv($position)) { @@ -172,14 +172,14 @@ private function step1() } // if preceded by iv, delete if in R2 (and if further preceded by at, delete if in R2), otherwise, - if ( ($position = $this->searchIfInR2(array('iv'))) !== false) { + if ( ($position = $this->searchIfInR2(['iv'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); - if ( ($position2 = $this->searchIfInR2(array('at'))) !== false) { + if ( ($position2 = $this->searchIfInR2(['at'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position2); } // if preceded by eus, delete if in R2, else replace by eux if in R1, otherwise, - } elseif ( ($position = $this->search(array('eus'))) !== false) { + } elseif ( ($position = $this->search(['eus'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); @@ -188,11 +188,11 @@ private function step1() } // if preceded by abl or iqU, delete if in R2, otherwise, - } elseif ( ($position = $this->searchIfInR2(array('abl', 'iqU'))) !== false) { + } elseif ( ($position = $this->searchIfInR2(['abl', 'iqU'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); // if preceded by ièr or Ièr, replace by i if in RV - } elseif ( ($position = $this->searchIfInRv(array('ièr', 'Ièr'))) !== false) { + } elseif ( ($position = $this->searchIfInRv(['ièr', 'Ièr'])) !== false) { $this->word = preg_replace('#(ièr|Ièr)$#u', 'i', $this->word); } return 3; @@ -203,7 +203,7 @@ private function step1() // if preceded by abil, delete if in R2, else replace by abl, otherwise, // if preceded by ic, delete if in R2, else replace by iqU, otherwise, // if preceded by iv, delete if in R2 - if ( ($position = $this->search(array('ités', 'ité'))) !== false) { + if ( ($position = $this->search(['ités', 'ité'])) !== false) { // delete if in R2 if ($this->inR2($position)) { @@ -211,7 +211,7 @@ private function step1() } // if preceded by abil, delete if in R2, else replace by abl, otherwise, - if ( ($position = $this->search(array('abil'))) !== false) { + if ( ($position = $this->search(['abil'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } else { @@ -219,7 +219,7 @@ private function step1() } // if preceded by ic, delete if in R2, else replace by iqU, otherwise, - } elseif ( ($position = $this->search(array('ic'))) !== false) { + } elseif ( ($position = $this->search(['ic'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } else { @@ -227,7 +227,7 @@ private function step1() } // if preceded by iv, delete if in R2 - } elseif ( ($position = $this->searchIfInR2(array('iv'))) !== false) { + } elseif ( ($position = $this->searchIfInR2(['iv'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -237,16 +237,16 @@ private function step1() // if ive ifs ives // delete if in R2 // if preceded by at, delete if in R2 (and if further preceded by ic, delete if in R2, else replace by iqU) - if ( ($position = $this->search(array('ifs', 'ives', 'if', 'ive'))) !== false) { + if ( ($position = $this->search(['ifs', 'ives', 'if', 'ive'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } - if ( ($position = $this->searchIfInR2(array('at'))) !== false) { + if ( ($position = $this->searchIfInR2(['at'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); - if ( ($position2 = $this->search(array('ic'))) !== false) { + if ( ($position2 = $this->search(['ic'])) !== false) { if ($this->inR2($position2)) { $this->word = UTF8::substr($this->word, 0, $position2); } else { @@ -260,14 +260,14 @@ private function step1() // eaux // replace with eau - if ( ($position = $this->search(array('eaux'))) !== false) { + if ( ($position = $this->search(['eaux'])) !== false) { $this->word = preg_replace('#(eaux)$#u', 'eau', $this->word); return 3; } // aux // replace with al if in R1 - if ( ($position = $this->search(array('aux'))) !== false) { + if ( ($position = $this->search(['aux'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(aux)$#u', 'al', $this->word); } @@ -276,7 +276,7 @@ private function step1() // euse euses // delete if in R2, else replace by eux if in R1 - if ( ($position = $this->search(array('euses', 'euse'))) !== false) { + if ( ($position = $this->search(['euses', 'euse'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); @@ -289,7 +289,7 @@ private function step1() // amment // replace with ant if in RV - if ( ($position = $this->search(array('amment'))) !== false) { + if ( ($position = $this->search(['amment'])) !== false) { if ($this->inRv($position)) { $this->word = preg_replace('#(amment)$#u', 'ant', $this->word); } @@ -298,7 +298,7 @@ private function step1() // emment // replace with ent if in RV - if ( ($position = $this->search(array('emment'))) !== false) { + if ( ($position = $this->search(['emment'])) !== false) { if ($this->inRv($position)) { $this->word = preg_replace('#(emment)$#u', 'ent', $this->word); } @@ -307,7 +307,7 @@ private function step1() // ment ments // delete if preceded by a vowel in RV - if ( ($position = $this->search(array('ments', 'ment'))) != false) { + if ( ($position = $this->search(['ments', 'ment'])) != false) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); if ( $this->inRv($before) && (in_array($letter, self::$vowels)) ) { @@ -331,10 +331,10 @@ private function step1() */ private function step2a() { - if ( ($position = $this->searchIfInRv(array( + if ( ($position = $this->searchIfInRv([ 'îmes', 'îtes', 'ît', 'ies', 'ie', 'iraIent', 'irais', 'irait', 'irai', 'iras', 'ira', 'irent', 'irez', 'iriez', 'irions', 'irons', 'iront', 'ir', 'issaIent', 'issais', 'issait', 'issant', 'issantes', 'issante', 'issants', - 'issent', 'isses', 'issez', 'isse', 'issiez', 'issions', 'issons', 'is', 'it', 'i'))) !== false) { + 'issent', 'isses', 'issez', 'isse', 'issiez', 'issions', 'issons', 'is', 'it', 'i'])) !== false) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); @@ -356,9 +356,9 @@ private function step2b() { // é ée ées és èrent er era erai eraIent erais erait eras erez eriez erions erons eront ez iez // delete - if ( ($position = $this->searchIfInRv(array( + if ( ($position = $this->searchIfInRv([ 'ées', 'èrent', 'erais', 'erait', 'erai', 'eraIent', 'eras', 'erez', 'eriez', - 'erions', 'erons', 'eront', 'era', 'er', 'iez', 'ez','és', 'ée', 'é'))) !== false) { + 'erions', 'erons', 'eront', 'era', 'er', 'iez', 'ez','és', 'ée', 'é'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); @@ -368,9 +368,9 @@ private function step2b() // âmes ât âtes a ai aIent ais ait ant ante antes ants as asse assent asses assiez assions // delete // if preceded by e, delete - if ( ($position = $this->searchIfInRv(array( + if ( ($position = $this->searchIfInRv([ 'âmes', 'âtes', 'ât', 'aIent', 'ais', 'ait', 'antes', 'ante', 'ants', 'ant', - 'assent', 'asses', 'assiez', 'assions', 'asse', 'as', 'ai', 'a'))) !== false) { + 'assent', 'asses', 'assiez', 'assions', 'asse', 'as', 'ai', 'a'])) !== false) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); @@ -386,7 +386,7 @@ private function step2b() // ions // delete if in R2 - if ( ($position = $this->searchIfInRv(array('ions'))) !== false) { + if ( ($position = $this->searchIfInRv(['ions'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -419,7 +419,7 @@ private function step4() // In the rest of step 4, all tests are confined to the RV region. // ion // delete if in R2 and preceded by s or t - if ( (($position = $this->searchIfInRv(array('ion'))) !== false) && ($this->inR2($position)) ) { + if ( (($position = $this->searchIfInRv(['ion'])) !== false) && ($this->inR2($position)) ) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); if ( $this->inRv($before) && (($letter == 's') || ($letter == 't')) ) { @@ -430,25 +430,23 @@ private function step4() // ier ière Ier Ière // replace with i - if ( ($this->searchIfInRv(array('ier', 'ière', 'Ier', 'Ière'))) !== false) { + if ( ($this->searchIfInRv(['ier', 'ière', 'Ier', 'Ière'])) !== false) { $this->word = preg_replace('#(ier|ière|Ier|Ière)$#u', 'i', $this->word); return true; } // e // delete - if ( ($this->searchIfInRv(array('e'))) !== false) { + if ( ($this->searchIfInRv(['e'])) !== false) { $this->word = UTF8::substr($this->word, 0, -1); return true; } // ë // if preceded by gu, delete - if ( ($position = $this->searchIfInRv(array('guë'))) !== false) { - if ($this->inRv($position+2)) { - $this->word = UTF8::substr($this->word, 0, -1); - return true; - } + if ($position = $this->searchIfInRv(['guë']) !== false && $this->inRv($position+2)) { + $this->word = UTF8::substr($this->word, 0, -1); + return true; } return false; @@ -460,7 +458,7 @@ private function step4() */ private function step5() { - if ($this->search(array('enn', 'onn', 'ett', 'ell', 'eill')) !== false) { + if ($this->search(['enn', 'onn', 'ett', 'ell', 'eill']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); } } @@ -480,7 +478,7 @@ private function step6() */ private function finish() { - $this->word = str_replace(array('I','U','Y'), array('i', 'u', 'y'), $this->word); + $this->word = str_replace(['I','U','Y'], ['i', 'u', 'y'], $this->word); } /** @@ -512,7 +510,7 @@ protected function rv() // (Exceptionally, par, col or tap, at the begining of a word is also taken to define RV as the region to their right.) $begin3 = UTF8::substr($this->word, 0, 3); - if (in_array($begin3, array('par', 'col', 'tap'))) { + if (in_array($begin3, ['par', 'col', 'tap'])) { $this->rv = UTF8::substr($this->word, 3); $this->rvIndex = 3; return true; diff --git a/src/Stemmer/German.php b/src/Stemmer/German.php index 2410ee7..764adc1 100644 --- a/src/Stemmer/German.php +++ b/src/Stemmer/German.php @@ -15,11 +15,11 @@ class German extends Stem /** * All German vowels */ - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'y', 'ä', 'ö', 'ü'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'y', 'ä', 'ö', 'ü']; - protected static $sEndings = array('b', 'd', 'f', 'g', 'h', 'k', 'l', 'm', 'n', 'r' ,'t'); + protected static $sEndings = ['b', 'd', 'f', 'g', 'h', 'k', 'l', 'm', 'n', 'r' ,'t']; - protected static $stEndings = array('b', 'd', 'f', 'g', 'h', 'k', 'l', 'm', 'n', 't'); + protected static $stEndings = ['b', 'd', 'f', 'g', 'h', 'k', 'l', 'm', 'n', 't']; /** * {@inheritdoc} @@ -66,7 +66,7 @@ public function stem($word) private function step1() { // delete if in R1 - if ( ($position = $this->search(array('em', 'ern', 'er'))) !== false) { + if ( ($position = $this->search(['em', 'ern', 'er'])) !== false) { if ($this->inR1($position)) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -74,12 +74,12 @@ private function step1() } // delete if in R1 - if ( ($position = $this->search(array('es', 'en', 'e'))) !== false) { + if ( ($position = $this->search(['es', 'en', 'e'])) !== false) { if ($this->inR1($position)) { $this->word = UTF8::substr($this->word, 0, $position); //If an ending of group (b) is deleted, and the ending is preceded by niss, delete the final s - if ($this->search(array('niss')) !== false) { + if ($this->search(['niss']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); } } @@ -87,7 +87,7 @@ private function step1() } // s (preceded by a valid s-ending) - if ( ($position = $this->search(array('s'))) !== false) { + if ( ($position = $this->search(['s'])) !== false) { if ($this->inR1($position)) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); @@ -109,7 +109,7 @@ private function step2() { // en er est // delete if in R1 - if ( ($position = $this->search(array('en', 'er', 'est'))) !== false) { + if ( ($position = $this->search(['en', 'er', 'est'])) !== false) { if ($this->inR1($position)) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -118,7 +118,7 @@ private function step2() // st (preceded by a valid st-ending, itself preceded by at least 3 letters) // delete if in R1 - if ( ($position = $this->search(array('st'))) !== false) { + if ( ($position = $this->search(['st'])) !== false) { if ($this->inR1($position)) { $before = $position - 1; if ($before >= 3) { @@ -142,12 +142,12 @@ private function step3() // end ung // delete if in R2 // if preceded by ig, delete if in R2 and not preceded by e - if ( ($position = $this->search(array('end', 'ung'))) !== false) { + if ( ($position = $this->search(['end', 'ung'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } - if ( ($position2 = $this->search(array('ig'))) !== false) { + if ( ($position2 = $this->search(['ig'])) !== false) { $before = $position2 - 1; $letter = UTF8::substr($this->word, $before, 1); @@ -160,7 +160,7 @@ private function step3() // ig ik isch // delete if in R2 and not preceded by e - if ( ($position = $this->search(array('ig', 'ik', 'isch'))) !== false) { + if ( ($position = $this->search(['ig', 'ik', 'isch'])) !== false) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); @@ -173,15 +173,13 @@ private function step3() // lich heit // delete if in R2 // if preceded by er or en, delete if in R1 - if ( ($position = $this->search(array('lich', 'heit'))) != false) { + if ( ($position = $this->search(['lich', 'heit'])) != false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } - if ( ($position2 = $this->search(array('er', 'en'))) !== false) { - if ($this->inR1($position2)) { - $this->word = UTF8::substr($this->word, 0, $position2); - } + if ( $position2 = $this->search(['er', 'en']) !== false && $this->inR1($position2)) { + $this->word = UTF8::substr($this->word, 0, $position2); } return true; } @@ -189,15 +187,13 @@ private function step3() // keit // delete if in R2 // if preceded by lich or ig, delete if in R2 - if ( ($position = $this->search(array('keit'))) != false) { + if ( ($position = $this->search(['keit'])) != false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } - if ( ($position2 = $this->search(array('lich', 'ig'))) !== false) { - if ($this->inR2($position2)) { - $this->word = UTF8::substr($this->word, 0, $position2); - } + if ( $position2 = $this->search(['lich', 'ig']) !== false && $this->inR2($position2)) { + $this->word = UTF8::substr($this->word, 0, $position2); } return true; } @@ -211,6 +207,6 @@ private function step3() private function finish() { // turn U and Y back into lower case, and remove the umlaut accent from a, o and u. - $this->word = str_replace(array('U', 'Y', 'ä', 'ü', 'ö'), array('u', 'y', 'a', 'u', 'o'), $this->word); + $this->word = str_replace(['U', 'Y', 'ä', 'ü', 'ö'], ['u', 'y', 'a', 'u', 'o'], $this->word); } } diff --git a/src/Stemmer/Italian.php b/src/Stemmer/Italian.php index 40c9d86..9749137 100644 --- a/src/Stemmer/Italian.php +++ b/src/Stemmer/Italian.php @@ -15,7 +15,7 @@ class Italian extends Stem /** * All Italian vowels */ - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'à', 'è', 'ì', 'ò', 'ù'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'à', 'è', 'ì', 'ò', 'ù']; /** * {@inheritdoc} @@ -32,7 +32,7 @@ public function stem($word) $this->word = UTF8::strtolower($word); // First, replace all acute accents by grave accents. - $this->word = str_replace(array('á', 'é', 'í', 'ó', 'ú'), array('à', 'è', 'ì', 'ò', 'ù'), $this->word); + $this->word = str_replace(['á', 'é', 'í', 'ó', 'ú'], ['à', 'è', 'ì', 'ò', 'ù'], $this->word); //And, as in French, put u after q, and u, i between vowels into upper case. (See note on vowel marking.) The vowels are then $this->word = preg_replace('#([q])u#u', '$1U', $this->word); @@ -66,17 +66,17 @@ public function stem($word) private function step0() { // Search for the longest among the following suffixes - if ( ($position = $this->search(array( + if ( ($position = $this->search([ 'gliela', 'gliele', 'glieli', 'glielo', 'gliene', 'sene', 'mela', 'mele', 'meli', 'melo', 'mene', 'tela', 'tele', 'teli', 'telo', 'tene', 'cela', 'cele', 'celi', 'celo', 'cene', 'vela', 'vele', 'veli', 'velo', 'vene', - 'gli', 'la', 'le', 'li', 'lo', 'mi', 'ne', 'si', 'ti', 'vi', 'ci'))) !== false) { + 'gli', 'la', 'le', 'li', 'lo', 'mi', 'ne', 'si', 'ti', 'vi', 'ci'])) !== false) { $suffixe = UTF8::substr($this->word, $position); // following one of (in RV) // a - $a = array('ando', 'endo'); + $a = ['ando', 'endo']; $a = array_map(function($item) use ($suffixe) { return $item . $suffixe; }, $a); @@ -86,7 +86,7 @@ private function step0() } //b - $b = array('ar', 'er', 'ir'); + $b = ['ar', 'er', 'ir']; $b = array_map(function($item) use ($suffixe) { return $item . $suffixe; }, $b); @@ -110,31 +110,31 @@ private function step1() // delete if in R1 // if preceded by iv, delete if in R2 (and if further preceded by at, delete if in R2), otherwise, // if preceded by os, ic or abil, delete if in R2 - if ( ($position = $this->search(array('amente'))) !== false) { + if ( ($position = $this->search(['amente'])) !== false) { if ($this->inR1($position)) { $this->word = UTF8::substr($this->word, 0, $position); } // if preceded by iv, delete if in R2 (and if further preceded by at, delete if in R2), otherwise, - if ( ($position2 = $this->searchIfInR2(array('iv'))) !== false) { + if ( ($position2 = $this->searchIfInR2(['iv'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position2); - if ( ($position3 = $this->searchIfInR2(array('at'))) !== false) { + if ( ($position3 = $this->searchIfInR2(['at'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position3); } // if preceded by os, ic or ad, delete if in R2 - } elseif ( ($position4 = $this->searchIfInR2(array('os', 'ic', 'abil'))) != false) { + } elseif ( ($position4 = $this->searchIfInR2(['os', 'ic', 'abil'])) != false) { $this->word = UTF8::substr($this->word, 0, $position4); } return true; } // delete if in R2 - if ( ($position = $this->search(array( + if ( ($position = $this->search([ 'ibili', 'atrice', 'abili', 'abile', 'ibile', 'atrici', 'mente', 'anza', 'anze', 'iche', 'ichi', 'ismo', 'ismi', 'ista', 'iste', 'isti', 'istà', 'istè', 'istì', 'ante', 'anti', 'ico', 'ici', 'ica', 'ice', 'oso', 'osi', 'osa', 'ose' - ))) !== false) { + ])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); @@ -145,14 +145,12 @@ private function step1() // azione azioni atore atori // delete if in R2 // if preceded by ic, delete if in R2 - if ( ($position = $this->search(array('azione', 'azioni', 'atore', 'atori'))) !== false) { + if ( ($position = $this->search(['azione', 'azioni', 'atore', 'atori'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); - if ( ($position2 = $this->search(array('ic'))) !== false) { - if ($this->inR2($position2)) { - $this->word = UTF8::substr($this->word, 0, $position2); - } + if ( $position2 = $this->search(['ic']) !== false && $this->inR2($position2)) { + $this->word = UTF8::substr($this->word, 0, $position2); } } return true; @@ -160,7 +158,7 @@ private function step1() // logia logie // replace with log if in R2 - if ( ($position = $this->search(array('logia', 'logie'))) !== false) { + if ( ($position = $this->search(['logia', 'logie'])) !== false) { if ($this->inR2($position)) { $this->word = preg_replace('#(logia|logie)$#u', 'log', $this->word); } @@ -169,7 +167,7 @@ private function step1() // uzione uzioni usione usioni // replace with u if in R2 - if ( ($position = $this->search(array('uzione', 'uzioni', 'usione', 'usioni'))) !== false) { + if ( ($position = $this->search(['uzione', 'uzioni', 'usione', 'usioni'])) !== false) { if ($this->inR2($position)) { $this->word = preg_replace('#(uzione|uzioni|usione|usioni)$#u', 'u', $this->word); } @@ -178,7 +176,7 @@ private function step1() // enza enze // replace with ente if in R2 - if ( ($position = $this->search(array('enza', 'enze'))) !== false) { + if ( ($position = $this->search(['enza', 'enze'])) !== false) { if ($this->inR2($position)) { $this->word = preg_replace('#(enza|enze)$#u', 'ente', $this->word); } @@ -187,7 +185,7 @@ private function step1() // amento amenti imento imenti // delete if in RV - if ( ($position = $this->search(array('amento', 'amenti', 'imento', 'imenti'))) !== false) { + if ( ($position = $this->search(['amento', 'amenti', 'imento', 'imenti'])) !== false) { if ($this->inRv($position)) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -197,12 +195,12 @@ private function step1() // ità // delete if in R2 // if preceded by abil, ic or iv, delete if in R2 - if ( ($position = $this->search(array('ità'))) !== false) { + if ( ($position = $this->search(['ità'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } - if ( ($position2 = $this->searchIfInR2(array('abil', 'ic', 'iv'))) != false) { + if ( ($position2 = $this->searchIfInR2(['abil', 'ic', 'iv'])) != false) { $this->word = UTF8::substr($this->word, 0, $position2); } return true; @@ -211,14 +209,14 @@ private function step1() // ivo ivi iva ive // delete if in R2 // if preceded by at, delete if in R2 (and if further preceded by ic, delete if in R2) - if ( ($position = $this->search(array('ivo', 'ivi', 'iva', 'ive'))) !== false) { + if ( ($position = $this->search(['ivo', 'ivi', 'iva', 'ive'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } - if ( ($position2 = $this->searchIfInR2(array('at'))) !== false) { + if ( ($position2 = $this->searchIfInR2(['at'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position2); - if ( ($position3 = $this->searchIfInR2(array('ic'))) !== false) { + if ( ($position3 = $this->searchIfInR2(['ic'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position3); } } @@ -234,14 +232,14 @@ private function step1() */ private function step2() { - if ( ($position = $this->searchIfInRv(array( + if ( ($position = $this->searchIfInRv([ 'assimo', 'assero', 'eranno', 'erebbero', 'erebbe', 'eremmo', 'ereste', 'eresti', 'essero', 'iranno', 'irebbero', 'irebbe', 'iremmo', 'iscano', 'ireste', 'iresti', 'iscono', 'issero', 'avamo', 'arono', 'avano', 'avate', 'eremo', 'erete', 'erono', 'evamo', 'evano', 'evate', 'ivamo', 'ivano', 'ivate', 'iremo', 'irete', 'irono', 'ammo', 'ando', 'asse', 'assi', 'emmo', 'enda', 'ende', 'endi', 'endo', 'erai', 'erei', 'Yamo', 'iamo', 'immo', 'irà', 'irai', 'irei', 'isca', 'isce', 'isci', 'isco', 'ano', 'are', 'ata', 'ate', 'ati', 'ato', 'ava', 'avi', 'avo', 'erà', 'ere', 'erò', 'ete', 'eva', - 'evi', 'evo', 'ire', 'ita', 'ite', 'iti', 'ito', 'iva', 'ivi', 'ivo', 'ono', 'uta', 'ute', 'uti', 'uto', 'irò', 'ar', 'ir'))) !== false) { + 'evi', 'evo', 'ire', 'ita', 'ite', 'iti', 'ito', 'iva', 'ivi', 'ivo', 'ono', 'uta', 'ute', 'uti', 'uto', 'irò', 'ar', 'ir'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -253,10 +251,10 @@ private function step2() */ private function step3a() { - if ($this->searchIfInRv(array('a', 'e', 'i', 'o', 'à', 'è', 'ì', 'ò')) !== false) { + if ($this->searchIfInRv(['a', 'e', 'i', 'o', 'à', 'è', 'ì', 'ò']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); - if ($this->searchIfInRv(array('i')) !== false) { + if ($this->searchIfInRv(['i']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); } return true; @@ -270,10 +268,10 @@ private function step3a() */ private function step3b() { - if ($this->searchIfInRv(array('ch')) !== false) { + if ($this->searchIfInRv(['ch']) !== false) { $this->word = preg_replace('#(ch)$#u', 'c', $this->word); - } elseif ($this->searchIfInRv(array('gh')) !== false) { + } elseif ($this->searchIfInRv(['gh']) !== false) { $this->word = preg_replace('#(gh)$#u', 'g', $this->word); } } @@ -284,6 +282,6 @@ private function step3b() */ private function finish() { - $this->word = str_replace(array('I', 'U'), array('i', 'u'), $this->word); + $this->word = str_replace(['I', 'U'], ['i', 'u'], $this->word); } } diff --git a/src/Stemmer/Norwegian.php b/src/Stemmer/Norwegian.php index b44b722..35ce94f 100644 --- a/src/Stemmer/Norwegian.php +++ b/src/Stemmer/Norwegian.php @@ -15,7 +15,7 @@ class Norwegian extends Stem /** * All norwegian vowels */ - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'y', 'æ', 'å', 'ø'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'y', 'æ', 'å', 'ø']; /** * {@inheritdoc} @@ -57,7 +57,7 @@ public function stem($word) private function hasValidSEnding($word) { $lastLetter = UTF8::substr($word, -1, 1); - if (in_array($lastLetter, array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'v', 'y', 'z'))) { + if (in_array($lastLetter, ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'v', 'y', 'z'])) { return true; } if ($lastLetter == 'k') { @@ -77,30 +77,31 @@ private function step1() { // erte ert // replace with er - if ( ($position = $this->searchIfInR1(array('erte', 'ert'))) !== false) { + if ( ($position = $this->searchIfInR1(['erte', 'ert'])) !== false) { $this->word = preg_replace('#(erte|ert)$#u', 'er', $this->word); return true; } // a e ede ande ende ane ene hetene en heten ar er heter as es edes endes enes hetenes ens hetens ers ets et het ast // delete - if ( ($position = $this->searchIfInR1(array( + if ( ($position = $this->searchIfInR1([ 'hetenes', 'hetene', 'hetens', 'heten', 'endes', 'heter', 'ande', 'ende', 'enes', 'edes', 'ede', 'ane', 'ene', 'het', 'ers', 'ets', 'ast', 'ens', 'en', 'ar', 'er', 'as', 'es', 'et', 'a', 'e' - ))) !== false) { + ])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); return true; } // s // delete if preceded by a valid s-ending - if ( ($position = $this->searchIfInR1(array('s'))) !== false) { + if ( ($position = $this->searchIfInR1(['s'])) !== false) { $word = UTF8::substr($this->word, 0, $position); if ($this->hasValidSEnding($word)) { $this->word = $word; } return true; } + return null; } /** @@ -109,7 +110,7 @@ private function step1() */ private function step2() { - if ($this->searchIfInR1(array('dt', 'vt')) !== false) { + if ($this->searchIfInR1(['dt', 'vt']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); } } @@ -121,9 +122,9 @@ private function step2() private function step3() { // leg eleg ig eig lig elig els lov elov slov hetslov - if ( ($position = $this->searchIfInR1(array( + if ( ($position = $this->searchIfInR1([ 'hetslov', 'eleg', 'elov', 'slov', 'elig', 'eig', 'lig', 'els', 'lov', 'leg', 'ig' - ))) !== false) { + ])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); } } diff --git a/src/Stemmer/Portuguese.php b/src/Stemmer/Portuguese.php index 485aba0..0a2abaf 100644 --- a/src/Stemmer/Portuguese.php +++ b/src/Stemmer/Portuguese.php @@ -15,7 +15,7 @@ class Portuguese extends Stem /** * All Portuguese vowels */ - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'á', 'é', 'í', 'ó', 'ú', 'â', 'ê', 'ô'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'á', 'é', 'í', 'ó', 'ú', 'â', 'ê', 'ô']; /** * {@inheritdoc} @@ -29,7 +29,7 @@ public function stem($word) $this->word = UTF8::strtolower($word); - $this->word = str_replace(array('ã', 'õ'), array('a~', 'o~'), $this->word); + $this->word = str_replace(['ã', 'õ'], ['a~', 'o~'], $this->word); $this->rv(); $this->r1(); @@ -60,10 +60,10 @@ public function stem($word) private function step1() { // delete if in R2 - if ( ($position = $this->search(array( + if ( ($position = $this->search([ 'amentos', 'imentos', 'adoras', 'adores', 'amento', 'imento', 'adora', 'istas', 'ismos', 'antes', 'ância', 'ezas', 'eza', 'icos', 'icas', 'ismo', 'ável', 'ível', 'ista', 'oso', - 'osos', 'osas', 'osa', 'ico', 'ica', 'ador', 'aça~o', 'aço~es' , 'ante'))) !== false) { + 'osos', 'osas', 'osa', 'ico', 'ica', 'ador', 'aça~o', 'aço~es' , 'ante'])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); @@ -73,7 +73,7 @@ private function step1() // logía logías // replace with log if in R2 - if ( ($position = $this->search(array('logías', 'logía'))) !== false) { + if ( ($position = $this->search(['logías', 'logía'])) !== false) { if ($this->inR2($position)) { $this->word = preg_replace('#(logías|logía)$#u', 'log', $this->word); } @@ -82,7 +82,7 @@ private function step1() // ución uciones // replace with u if in R2 - if ( ($position = $this->search(array('uciones', 'ución'))) !== false) { + if ( ($position = $this->search(['uciones', 'ución'])) !== false) { if ($this->inR2($position)) { $this->word = preg_replace('#(uciones|ución)$#u', 'u', $this->word); } @@ -91,7 +91,7 @@ private function step1() // ência ências // replace with ente if in R2 - if ( ($position = $this->search(array('ências', 'ência'))) !== false) { + if ( ($position = $this->search(['ências', 'ência'])) !== false) { if ($this->inR2($position)) { $this->word = preg_replace('#(ências|ência)$#u', 'ente', $this->word); } @@ -102,7 +102,7 @@ private function step1() // delete if in R1 // if preceded by iv, delete if in R2 (and if further preceded by at, delete if in R2), otherwise, // if preceded by os, ic or ad, delete if in R2 - if ( ($position = $this->search(array('amente'))) !== false) { + if ( ($position = $this->search(['amente'])) !== false) { // delete if in R1 if ($this->inR1($position)) { @@ -110,14 +110,14 @@ private function step1() } // if preceded by iv, delete if in R2 (and if further preceded by at, delete if in R2), otherwise, - if ( ($position2 = $this->searchIfInR2(array('iv'))) !== false) { + if ( ($position2 = $this->searchIfInR2(['iv'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position2); - if ( ($position3 = $this->searchIfInR2(array('at'))) !== false) { + if ( ($position3 = $this->searchIfInR2(['at'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position3); } // if preceded by os, ic or ad, delete if in R2 - } elseif ( ($position4 = $this->searchIfInR2(array('os', 'ic', 'ad'))) !== false) { + } elseif ( ($position4 = $this->searchIfInR2(['os', 'ic', 'ad'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position4); } return true; @@ -126,7 +126,7 @@ private function step1() // mente // delete if in R2 // if preceded by ante, avel or ível, delete if in R2 - if ( ($position = $this->search(array('mente'))) !== false) { + if ( ($position = $this->search(['mente'])) !== false) { // delete if in R2 if ($this->inR2($position)) { @@ -134,7 +134,7 @@ private function step1() } // if preceded by ante, avel or ível, delete if in R2 - if ( ($position2 = $this->searchIfInR2(array('ante', 'avel', 'ível'))) != false) { + if ( ($position2 = $this->searchIfInR2(['ante', 'avel', 'ível'])) != false) { $this->word = UTF8::substr($this->word, 0, $position2); } return true; @@ -143,7 +143,7 @@ private function step1() // idade idades // delete if in R2 // if preceded by abil, ic or iv, delete if in R2 - if ( ($position = $this->search(array('idades', 'idade'))) !== false) { + if ( ($position = $this->search(['idades', 'idade'])) !== false) { // delete if in R2 if ($this->inR2($position)) { @@ -151,7 +151,7 @@ private function step1() } // if preceded by abil, ic or iv, delete if in R2 - if ( ($position2 = $this->searchIfInR2(array('abil', 'ic', 'iv'))) !== false) { + if ( ($position2 = $this->searchIfInR2(['abil', 'ic', 'iv'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position2); } return true; @@ -160,7 +160,7 @@ private function step1() // iva ivo ivas ivos // delete if in R2 // if preceded by at, delete if in R2 - if ( ($position = $this->search(array('ivas', 'ivos', 'iva', 'ivo'))) !== false) { + if ( ($position = $this->search(['ivas', 'ivos', 'iva', 'ivo'])) !== false) { // delete if in R2 if ($this->inR2($position)) { @@ -168,7 +168,7 @@ private function step1() } // if preceded by at, delete if in R2 - if ( ($position2 = $this->searchIfInR2(array('at'))) !== false) { + if ( ($position2 = $this->searchIfInR2(['at'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position2); } return true; @@ -176,7 +176,7 @@ private function step1() // ira iras // replace with ir if in RV and preceded by e - if ( ($position = $this->search(array('iras', 'ira'))) !== false) { + if ( ($position = $this->search(['iras', 'ira'])) !== false) { if ($this->inRv($position)) { $before = $position -1; @@ -198,7 +198,7 @@ private function step1() */ private function step2() { - if ( ($position = $this->searchIfInRv(array( + if ( ($position = $this->searchIfInRv([ 'aríamos', 'eríamos', 'iríamos', 'ássemos', 'êssemos', 'íssemos', 'aríeis', 'eríeis', 'iríeis', 'ásseis', 'ésseis', 'ísseis', 'áramos', 'éramos', 'íramos', 'ávamos', 'aremos', 'eremos', 'iremos', @@ -211,7 +211,7 @@ private function step2() 'emos', 'imos', 'iras', 'ada', 'ida', 'ará', 'ara', 'erá', 'era', 'irá', 'ava', 'iam', 'ado', 'ido', 'ias', 'ais', 'eis', 'ira', 'ia', 'ei', 'am', 'em', 'ar', 'er', 'ir', 'as', 'es', 'is', 'eu', 'iu', 'ou', - ))) !== false) { + ])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); return true; @@ -226,7 +226,7 @@ private function step2() private function step3() { // Delete suffix i if in RV and preceded by c - if ($this->searchIfInRv(array('i')) !== false) { + if ($this->searchIfInRv(['i']) !== false) { $letter = UTF8::substr($this->word, -2, 1); if ($letter == 'c') { @@ -243,7 +243,7 @@ private function step3() private function step4() { // If the word ends with one of the suffixes "os a i o á í ó" in RV, delete it - if ( ($position = $this->searchIfInRv(array('os', 'a', 'i', 'o','á', 'í', 'ó'))) !== false) { + if ( ($position = $this->searchIfInRv(['os', 'a', 'i', 'o','á', 'í', 'ó'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); return true; } @@ -256,16 +256,13 @@ private function step4() private function step5() { // If the word ends with one of "e é ê" in RV, delete it, and if preceded by gu (or ci) with the u (or i) in RV, delete the u (or i). - if ($this->searchIfInRv(array('e', 'é', 'ê')) !== false) { + if ($this->searchIfInRv(['e', 'é', 'ê']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); - - if ( ($position2 = $this->search(array('gu', 'ci'))) !== false) { - if ($this->inRv(($position2+1))) { - $this->word = UTF8::substr($this->word, 0, -1); - } + if ( $position2 = $this->search(['gu', 'ci']) !== false && $this->inRv(($position2+1))) { + $this->word = UTF8::substr($this->word, 0, -1); } return true; - } else if ($this->search(array('ç')) !== false) { + } elseif ($this->search(['ç']) !== false) { $this->word = preg_replace('#(ç)$#u', 'c', $this->word); return true; } @@ -278,6 +275,6 @@ private function step5() private function finish() { // turn U and Y back into lower case, and remove the umlaut accent from a, o and u. - $this->word = str_replace(array('a~', 'o~'), array('ã', 'õ'), $this->word); + $this->word = str_replace(['a~', 'o~'], ['ã', 'õ'], $this->word); } } diff --git a/src/Stemmer/Romanian.php b/src/Stemmer/Romanian.php index 3e9edd1..f423ab9 100644 --- a/src/Stemmer/Romanian.php +++ b/src/Stemmer/Romanian.php @@ -15,7 +15,7 @@ class Romanian extends Stem /** * All Romanian vowels */ - protected static $vowels = array('a', 'ă', 'â', 'e', 'i', 'î', 'o', 'u'); + protected static $vowels = ['a', 'ă', 'â', 'e', 'i', 'î', 'o', 'u']; /** * {@inheritdoc} @@ -71,7 +71,7 @@ private function step0() { // ul ului // delete - if ( ($position = $this->search(array('ul', 'ului'))) !== false) { + if ( ($position = $this->search(['ul', 'ului'])) !== false) { if ($this->inR1($position)) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -80,7 +80,7 @@ private function step0() // aua // replace with a - if ( ($position = $this->search(array('aua'))) !== false) { + if ( ($position = $this->search(['aua'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(aua)$#u', 'a', $this->word); } @@ -89,7 +89,7 @@ private function step0() // ea ele elor // replace with e - if ( ($position = $this->search(array('ea', 'ele', 'elor'))) !== false) { + if ( ($position = $this->search(['ea', 'ele', 'elor'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(ea|ele|elor)$#u', 'e', $this->word); } @@ -98,7 +98,7 @@ private function step0() // ii iua iei iile iilor ilor // replace with i - if ( ($position = $this->search(array('ii', 'iua', 'iei', 'iile', 'iilor', 'ilor'))) !== false) { + if ( ($position = $this->search(['ii', 'iua', 'iei', 'iile', 'iilor', 'ilor'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(ii|iua|iei|iile|iilor|ilor)$#u', 'i', $this->word); } @@ -107,7 +107,7 @@ private function step0() // ile // replace with i if not preceded by ab - if ( ($position = $this->search(array('ile'))) !== false) { + if ( ($position = $this->search(['ile'])) !== false) { if ($this->inR1($position)) { $before = UTF8::substr($this->word, ($position-2), 2); @@ -120,7 +120,7 @@ private function step0() // atei // replace with at - if ( ($position = $this->search(array('atei'))) != false) { + if ( ($position = $this->search(['atei'])) != false) { if ($this->inR1($position)) { $this->word = preg_replace('#(atei)$#u', 'at', $this->word); } @@ -129,7 +129,7 @@ private function step0() // aţie aţia // replace with aţi - if ( ($position = $this->search(array('aţie', 'aţia'))) !== false) { + if ( ($position = $this->search(['aţie', 'aţia'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(aţie|aţia)$#u', 'aţi', $this->word); } @@ -149,7 +149,7 @@ private function step1() { // abilitate abilitati abilităi abilităţi // replace with abil - if ( ($position = $this->search(array('abilitate', 'abilitati', 'abilităi', 'abilităţi'))) !== false) { + if ( ($position = $this->search(['abilitate', 'abilitati', 'abilităi', 'abilităţi'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(abilitate|abilitati|abilităi|abilităţi)$#u', 'abil', $this->word); } @@ -158,7 +158,7 @@ private function step1() // ibilitate // replace with ibil - if ( ($position = $this->search(array('ibilitate'))) !== false) { + if ( ($position = $this->search(['ibilitate'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(ibilitate)$#u', 'ibil', $this->word); } @@ -167,7 +167,7 @@ private function step1() // ivitate ivitati ivităi ivităţi // replace with iv - if ( ($position = $this->search(array('ivitate', 'ivitati', 'ivităi', 'ivităţi'))) !== false) { + if ( ($position = $this->search(['ivitate', 'ivitati', 'ivităi', 'ivităţi'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(ivitate|ivitati|ivităi|ivităţi)$#u', 'iv', $this->word); } @@ -176,9 +176,9 @@ private function step1() // icitate icitati icităi icităţi icator icatori iciv iciva icive icivi icivă ical icala icale icali icală // replace with ic - if ( ($position = $this->search(array( + if ( ($position = $this->search([ 'icitate', 'icitati', 'icităi', 'icităţi', 'icatori', 'icator', 'iciva', - 'icive', 'icivi', 'icivă', 'icala', 'icale', 'icali', 'icală', 'iciv', 'ical'))) !== false) { + 'icive', 'icivi', 'icivă', 'icala', 'icale', 'icali', 'icală', 'iciv', 'ical'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(icitate|icitati|icităi|icităţi|cator|icatori|iciva|icive|icivi|icivă|icala|icale|icali|icală|ical|iciv)$#u', 'ic', $this->word); } @@ -187,7 +187,7 @@ private function step1() // ativ ativa ative ativi ativă aţiune atoare ator atori ătoare ător ători // replace with at - if ( ($position = $this->search(array('ativa', 'ative', 'ativi', 'ativă', 'ativ', 'aţiune', 'atoare', 'atori', 'ătoare', 'ători', 'ător', 'ator'))) !== false) { + if ( ($position = $this->search(['ativa', 'ative', 'ativi', 'ativă', 'ativ', 'aţiune', 'atoare', 'atori', 'ătoare', 'ători', 'ător', 'ator'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(ativa|ative|ativi|ativă|ativ|aţiune|atoare|atori|ătoare|ători|ător|ator)$#u', 'at', $this->word); } @@ -196,7 +196,7 @@ private function step1() // itiv itiva itive itivi itivă iţiune itoare itor itori // replace with it - if ( ($position = $this->search(array('itiva', 'itive', 'itivi', 'itivă', 'itiv', 'iţiune', 'itoare', 'itori', 'itor'))) !== false) { + if ( ($position = $this->search(['itiva', 'itive', 'itivi', 'itivă', 'itiv', 'iţiune', 'itoare', 'itori', 'itor'])) !== false) { if ($this->inR1($position)) { $this->word = preg_replace('#(itiva|itive|itivi|itivă|itiv|iţiune|itoare|itori|itor)$#u', 'it', $this->word); } @@ -218,13 +218,13 @@ private function step2() // osi oşi ant ici ică iva ive ivi ivă ata ată ati ate, ata ată ati ate uta ută uti ute, ita ită iti ite ica ice // at, os, iv, ut, it, ic // delete - if ( ($position = $this->search(array( + if ( ($position = $this->search([ 'atori', 'itate', 'itati', 'ităţi', 'abila', 'abile', 'abili', 'abilă', 'ibila', 'ibile', 'ibili', 'ibilă', 'anta', 'ante', 'anti', 'antă', 'ator', 'ibil', 'oasa', 'oasă', 'oase', 'ităi', 'abil', 'osi', 'oşi', 'ant', 'ici', 'ică', 'iva', 'ive', 'ivi', 'ivă', 'ata', 'ată', 'ati', 'ate', 'ata', 'ată', 'ati', 'ate', 'uta', 'ută', 'uti', 'ute', 'ita', 'ită', 'iti', 'ite', 'ica', 'ice', 'at', 'os', 'iv', 'ut', 'it', 'ic' - ))) !== false) { + ])) !== false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } @@ -233,7 +233,7 @@ private function step2() // iune iuni // delete if preceded by ţ, and replace the ţ by t. - if ( ($position = $this->search(array('iune', 'iuni'))) !== false) { + if ( ($position = $this->search(['iune', 'iuni'])) !== false) { if ($this->inR2($position)) { $before = $position - 1; $letter = UTF8::substr($this->word, $before, 1); @@ -247,7 +247,7 @@ private function step2() // ism isme ist ista iste isti istă işti // replace with ist - if ( ($position = $this->search(array('isme', 'ism', 'ista', 'iste', 'isti', 'istă', 'işti', 'ist'))) !== false) { + if ( ($position = $this->search(['isme', 'ism', 'ista', 'iste', 'isti', 'istă', 'işti', 'ist'])) !== false) { if ($this->inR2($position)) { $this->word = preg_replace('#(isme|ism|ista|iste|isti|istă|işti|ist)$#u', 'ist', $this->word); } @@ -270,7 +270,7 @@ private function step3() // âşi ârăm ârăţi âră asem aseşi ase aserăm aserăţi aseră isem iseşi ise // iserăm iserăţi iseră âsem âseşi âse âserăm âserăţi âseră usem useşi use userăm userăţi useră // delete if preceded in RV by a consonant or u - if ( ($position = $this->searchIfInRv(array( + if ( ($position = $this->searchIfInRv([ 'userăţi', 'iserăţi', 'âserăţi', 'aserăţi', 'userăm', 'iserăm', 'âserăm', 'aserăm', 'iseră', 'âseşi', 'useră', 'âseră', 'useşi', 'iseşi', 'aseră', 'aseşi', 'ârăţi', 'irăţi', 'urăţi', 'arăţi', 'ească', @@ -278,7 +278,7 @@ private function step3() 'âse', 'use', 'ise', 'ase', 'âră', 'iră', 'işi', 'ură', 'uşi', 'ară', 'aşi', 'âşi', 'iau', 'iai', 'iam', 'eau', 'eai', 'eam', 'ăsc', 'are', 'ere', 'ire', 'âre', 'ind', 'ând', 'eze', 'ezi', 'esc', 'âi', 'ui', 'ia', 'ea', 'au', 'ai', 'am', 'ez' - ))) !== false) { + ])) !== false) { if ($this->inRv($position)) { $before = $position - 1; if ($this->inRv($before)) { @@ -296,15 +296,16 @@ private function step3() // ăm aţi em eţi im iţi âm âţi seşi serăm serăţi seră sei se sesem seseşi sese seserăm seserăţi seseră // delete - if ( ($position = $this->searchIfInRv(array( + if ( ($position = $this->searchIfInRv([ 'seserăm', 'seserăţi', 'seseră', 'seseşi', 'sesem', 'serăţi', 'serăm', 'seşi', 'sese', 'seră', 'aţi', 'eţi', 'iţi', 'âţi', 'sei', 'se', 'ăm', 'âm', 'em', 'im' - ))) !== false) { + ])) !== false) { if ($this->inRv($position)) { $this->word = UTF8::substr($this->word, 0, $position); } return true; } + return null; } /** @@ -313,10 +314,8 @@ private function step3() private function step4() { // Search for the longest among the suffixes "a e i ie ă " and, if it is in RV, delete it. - if ( ($position = $this->search(array('a', 'ie', 'e', 'i', 'ă'))) !== false) { - if ($this->inRv($position)) { - $this->word = UTF8::substr($this->word, 0, $position); - } + if ( $position = $this->search(['a', 'ie', 'e', 'i', 'ă']) !== false && $this->inRv($position)) { + $this->word = UTF8::substr($this->word, 0, $position); } return true; @@ -329,6 +328,6 @@ private function step4() private function finish() { // Turn I, U back into i, u - $this->word = str_replace(array('I', 'U'), array('i', 'u'), $this->word); + $this->word = str_replace(['I', 'U'], ['i', 'u'], $this->word); } } diff --git a/src/Stemmer/Russian.php b/src/Stemmer/Russian.php index cd18dbf..337d2ed 100644 --- a/src/Stemmer/Russian.php +++ b/src/Stemmer/Russian.php @@ -15,41 +15,41 @@ class Russian extends Stem /** * All russian vowels */ - protected static $vowels = array('а', 'е', 'и', 'о', 'у', 'ы', 'э', 'ю', 'я'); + protected static $vowels = ['а', 'е', 'и', 'о', 'у', 'ы', 'э', 'ю', 'я']; - protected static $perfectiveGerund = array( - array('вшись', 'вши', 'в'), - array('ывшись', 'ившись', 'ывши', 'ивши', 'ив', 'ыв') - ); + protected static $perfectiveGerund = [ + ['вшись', 'вши', 'в'], + ['ывшись', 'ившись', 'ывши', 'ивши', 'ив', 'ыв'] + ]; - protected static $adjective = array( + protected static $adjective = [ 'ыми', 'ими', 'ему', 'ому', 'его', 'ого', 'ее', 'ие', 'ые', 'ое', 'ей', 'ий', 'ый', 'ой', 'ем', 'им', 'ым','ом','их', 'ых', 'ую', 'юю', 'ая', 'яя', 'ою', 'ею' - ); + ]; - protected static $participle = array( - array('ем', 'нн', 'вш', 'ющ', 'щ'), - array('ивш', 'ывш', 'ующ') - ); + protected static $participle = [ + ['ем', 'нн', 'вш', 'ющ', 'щ'], + ['ивш', 'ывш', 'ующ'] + ]; - protected static $reflexive = array('ся', 'сь'); + protected static $reflexive = ['ся', 'сь']; - protected static $verb = array( - array('ешь', 'нно', 'ете', 'йте', 'ла', 'на', 'ли', 'й', 'л', 'ем', 'н', 'ло', 'но', 'ет', 'ют', 'ны', 'ть'), - array( + protected static $verb = [ + ['ешь', 'нно', 'ете', 'йте', 'ла', 'на', 'ли', 'й', 'л', 'ем', 'н', 'ло', 'но', 'ет', 'ют', 'ны', 'ть'], + [ 'уйте', 'ило', 'ыло', 'ено','ила', 'ыла', 'ена', 'ейте', 'ены', 'ить', 'ыть', 'ишь', 'ите', 'или', 'ыли', 'ует', 'уют', 'ей', 'уй', 'ил', 'ыл', 'им', 'ым', 'ен', 'ят', 'ит', 'ыт', 'ую', 'ю' - ) - ); + ] + ]; - protected static $noun = array( + protected static $noun = [ 'иями', 'ями', 'ами', 'ией', 'иям', 'ием', 'иях', 'ев', 'ов', 'ие', 'ье', 'еи', 'ии', 'ей', 'ой', 'ий', 'ям', 'ем', 'ам', 'ом', 'ах', 'ях', 'ию', 'ью', 'ия', 'ья', 'я', 'а', 'е', 'ы', 'ь', 'и', 'о', 'у', 'й', 'ю' - ); + ]; - protected static $superlative = array('ейше', 'ейш'); + protected static $superlative = ['ейше', 'ейш']; - protected static $derivational = array('ость', 'ост'); + protected static $derivational = ['ость', 'ост']; /** * {@inheritdoc} @@ -86,71 +86,50 @@ private function step1() { // Search for a PERFECTIVE GERUND ending. // group 1 - if ( ($position = $this->searchIfInRv(self::$perfectiveGerund[0])) !== false) { - if ( ($this->inRv($position)) && ($this->checkGroup1($position)) ) { - $this->word = UTF8::substr($this->word, 0, $position); - return true; - } + if ($position = $this->searchIfInRv(self::$perfectiveGerund[0]) !== false && ($this->inRv($position) && $this->checkGroup1($position))) { + $this->word = UTF8::substr($this->word, 0, $position); + return true; } // group 2 - if ( ($position = $this->searchIfInRv(self::$perfectiveGerund[1])) !== false) { - if ($this->inRv($position)) { - $this->word = UTF8::substr($this->word, 0, $position); - return true; - } + if ($position = $this->searchIfInRv(self::$perfectiveGerund[1]) !== false && $this->inRv($position)) { + $this->word = UTF8::substr($this->word, 0, $position); + return true; } // Otherwise try and remove a REFLEXIVE ending - if ( ($position = $this->searchIfInRv(self::$reflexive)) !== false) { - if ($this->inRv($position)) { - $this->word = UTF8::substr($this->word, 0, $position); - } + if ( $position = $this->searchIfInRv(self::$reflexive) !== false && $this->inRv($position)) { + $this->word = UTF8::substr($this->word, 0, $position); } // then search in turn for (1) an ADJECTIVAL, (2) a VERB or (3) a NOUN ending. // As soon as one of the endings (1) to (3) is found remove it, and terminate step 1. - if ( ($position = $this->searchIfInRv(self::$adjective)) !== false) { - if ($this->inRv($position)) { - $this->word = UTF8::substr($this->word, 0, $position); - - if ( ($position2 = $this->search(self::$participle[0])) !== false) { - if ( ($this->inRv($position2)) && ($this->checkGroup1($position2)) ) { - $this->word = UTF8::substr($this->word, 0, $position2); - return true; - } - } - - if ( ($position2 = $this->search(self::$participle[1])) !== false) { - if ($this->inRv($position2)) { - $this->word = UTF8::substr($this->word, 0, $position2); - return true; - } - } - + if ($position = $this->searchIfInRv(self::$adjective) !== false && $this->inRv($position)) { + $this->word = UTF8::substr($this->word, 0, $position); + if ($position2 = $this->search(self::$participle[0]) !== false && ($this->inRv($position2) && $this->checkGroup1($position2))) { + $this->word = UTF8::substr($this->word, 0, $position2); return true; } - } - - if ( ($position = $this->searchIfInRv(self::$verb[0])) !== false) { - if ( ($this->inRv($position)) && ($this->checkGroup1($position)) ) { - $this->word = UTF8::substr($this->word, 0, $position); + if ($position2 = $this->search(self::$participle[1]) !== false && $this->inRv($position2)) { + $this->word = UTF8::substr($this->word, 0, $position2); return true; } + return true; } - if ( ($position = $this->searchIfInRv(self::$verb[1])) !== false) { - if ($this->inRv($position)) { - $this->word = UTF8::substr($this->word, 0, $position); - return true; - } + if ($position = $this->searchIfInRv(self::$verb[0]) !== false && ($this->inRv($position) && $this->checkGroup1($position))) { + $this->word = UTF8::substr($this->word, 0, $position); + return true; } - if ( ($position = $this->searchIfInRv(self::$noun)) !== false) { - if ($this->inRv($position)) { - $this->word = UTF8::substr($this->word, 0, $position); - return true; - } + if ($position = $this->searchIfInRv(self::$verb[1]) !== false && $this->inRv($position)) { + $this->word = UTF8::substr($this->word, 0, $position); + return true; + } + + if ($position = $this->searchIfInRv(self::$noun) !== false && $this->inRv($position)) { + $this->word = UTF8::substr($this->word, 0, $position); + return true; } return false; @@ -161,11 +140,9 @@ private function step1() */ private function step2() { - if ( ($position = $this->searchIfInRv(array('и'))) !== false) { - if ($this->inRv($position)) { - $this->word = UTF8::substr($this->word, 0, $position); - return true; - } + if ($position = $this->searchIfInRv(['и']) !== false && $this->inRv($position)) { + $this->word = UTF8::substr($this->word, 0, $position); + return true; } return false; } @@ -176,12 +153,11 @@ private function step2() */ private function step3() { - if ( ($position = $this->searchIfInRv(self::$derivational)) !== false) { - if ($this->inR2($position)) { - $this->word = UTF8::substr($this->word, 0, $position); - return true; - } + if ($position = $this->searchIfInRv(self::$derivational) !== false && $this->inR2($position)) { + $this->word = UTF8::substr($this->word, 0, $position); + return true; } + return null; } /** @@ -196,16 +172,17 @@ private function step4() } // (1) Undouble н (n) - if ( ($position = $this->searchIfInRv(array('нн'))) !== false) { + if ( ($position = $this->searchIfInRv(['нн'])) !== false) { $this->word = UTF8::substr($this->word, 0, ($position+1)); return true; } // (3) if the word ends ь (') (soft sign) remove it - if ( ($position = $this->searchIfInRv(array('ь'))) !== false) { + if ( ($position = $this->searchIfInRv(['ь'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); return true; } + return null; } /** @@ -243,10 +220,6 @@ private function checkGroup1($position) } $letter = UTF8::substr($this->word, ($position - 1), 1); - - if ($letter == 'а' || $letter == 'я') { - return true; - } - return false; + return $letter == 'а' || $letter == 'я'; } } diff --git a/src/Stemmer/Spanish.php b/src/Stemmer/Spanish.php index 190f761..461f6b1 100644 --- a/src/Stemmer/Spanish.php +++ b/src/Stemmer/Spanish.php @@ -15,7 +15,7 @@ class Spanish extends Stem /** * All spanish vowels */ - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'á', 'é', 'í', 'ó', 'ú', 'ü'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'á', 'é', 'í', 'ó', 'ú', 'ü']; /** * {@inheritdoc} @@ -39,11 +39,11 @@ public function stem($word) $this->step1(); // Do step 2a if no ending was removed by step 1. - if ($this->word == $word) { + if ($this->word === $word) { $this->step2a(); // Do Step 2b if step 2a was done, but failed to remove a suffix. - if ($this->word == $word) { + if ($this->word === $word) { $this->step2b(); } } @@ -70,11 +70,11 @@ public function stem($word) */ private function step0() { - if ( ($position = $this->searchIfInRv(array('selas', 'selos', 'las', 'los', 'les', 'nos', 'selo', 'sela', 'me', 'se', 'la', 'le', 'lo' ))) != false) { + if ( ($position = $this->searchIfInRv(['selas', 'selos', 'las', 'los', 'les', 'nos', 'selo', 'sela', 'me', 'se', 'la', 'le', 'lo' ])) != false) { $suffixe = UTF8::substr($this->word, $position); // a - $a = array('iéndo', 'ándo', 'ár', 'ér', 'ír'); + $a = ['iéndo', 'ándo', 'ár', 'ér', 'ír']; $a = array_map(function($item) use ($suffixe) { return $item . $suffixe; }, $a); @@ -89,7 +89,7 @@ private function step0() } // b - $b = array('iendo', 'ando', 'ar', 'er', 'ir'); + $b = ['iendo', 'ando', 'ar', 'er', 'ir']; $b = array_map(function($item) use ($suffixe) { return $item . $suffixe; }, $b); @@ -100,7 +100,7 @@ private function step0() } // c - if ( ($position2 = $this->searchIfInRv(array('yendo' . $suffixe))) != false) { + if ( ($position2 = $this->searchIfInRv(['yendo' . $suffixe])) != false) { $before = UTF8::substr($this->word, ($position2-1), 1); if ( (isset($before)) && ($before == 'u') ) { $this->word = UTF8::substr($this->word, 0, $position); @@ -120,9 +120,9 @@ private function step1() // anza anzas ico ica icos icas ismo ismos able ables ible ibles ista // istas oso osa osos osas amiento amientos imiento imientos // delete if in R2 - if ( ($position = $this->search(array( + if ( ($position = $this->search([ 'imientos', 'imiento', 'amientos', 'amiento', 'osas', 'osos', 'osa', 'oso', 'istas', 'ista', 'ibles', - 'ible', 'ables', 'able', 'ismos', 'ismo', 'icas', 'icos', 'ica', 'ico', 'anzas', 'anza'))) != false) { + 'ible', 'ables', 'able', 'ismos', 'ismo', 'icas', 'icos', 'ica', 'ico', 'anzas', 'anza'])) != false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); @@ -133,14 +133,14 @@ private function step1() // adora ador ación adoras adores aciones ante antes ancia ancias // delete if in R2 // if preceded by ic, delete if in R2 - if ( ($position = $this->search(array( - 'adoras', 'adora', 'aciones', 'ación', 'adores', 'ador', 'antes', 'ante', 'ancias', 'ancia'))) != false) { + if ( ($position = $this->search([ + 'adoras', 'adora', 'aciones', 'ación', 'adores', 'ador', 'antes', 'ante', 'ancias', 'ancia'])) != false) { if ($this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); } - if ( ($position2 = $this->searchIfInR2(array('ic')))) { + if ( ($position2 = $this->searchIfInR2(['ic']))) { $this->word = UTF8::substr($this->word, 0, $position2); } return true; @@ -148,7 +148,7 @@ private function step1() // logía logías // replace with log if in R2 - if ( ($position = $this->search(array('logías', 'logía'))) != false) { + if ( ($position = $this->search(['logías', 'logía'])) != false) { if ($this->inR2($position)) { $this->word = preg_replace('#(logías|logía)$#u', 'log', $this->word); } @@ -157,7 +157,7 @@ private function step1() // ución uciones // replace with u if in R2 - if ( ($position = $this->search(array('uciones', 'ución'))) != false) { + if ( ($position = $this->search(['uciones', 'ución'])) != false) { if ($this->inR2($position)) { $this->word = preg_replace('#(uciones|ución)$#u', 'u', $this->word); } @@ -166,7 +166,7 @@ private function step1() // encia encias // replace with ente if in R2 - if ( ($position = $this->search(array('encias', 'encia'))) != false) { + if ( ($position = $this->search(['encias', 'encia'])) != false) { if ($this->inR2($position)) { $this->word = preg_replace('#(encias|encia)$#u', 'ente', $this->word); } @@ -177,7 +177,7 @@ private function step1() // delete if in R1 // if preceded by iv, delete if in R2 (and if further preceded by at, delete if in R2), otherwise, // if preceded by os, ic or ad, delete if in R2 - if ( ($position = $this->search(array('amente'))) != false) { + if ( ($position = $this->search(['amente'])) != false) { // delete if in R1 if ($this->inR1($position)) { @@ -185,14 +185,14 @@ private function step1() } // if preceded by iv, delete if in R2 (and if further preceded by at, delete if in R2), otherwise, - if ( ($position2 = $this->searchIfInR2(array('iv'))) !== false) { + if ( ($position2 = $this->searchIfInR2(['iv'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position2); - if ( ($position3 = $this->searchIfInR2(array('at'))) !== false) { + if ( ($position3 = $this->searchIfInR2(['at'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position3); } // if preceded by os, ic or ad, delete if in R2 - } elseif ( ($position4 = $this->searchIfInR2(array('os', 'ic', 'ad'))) != false) { + } elseif ( ($position4 = $this->searchIfInR2(['os', 'ic', 'ad'])) != false) { $this->word = UTF8::substr($this->word, 0, $position4); } return true; @@ -201,7 +201,7 @@ private function step1() // mente // delete if in R2 // if preceded by ante, able or ible, delete if in R2 - if ( ($position = $this->search(array('mente'))) != false) { + if ( ($position = $this->search(['mente'])) != false) { // delete if in R2 if ($this->inR2($position)) { @@ -209,7 +209,7 @@ private function step1() } // if preceded by ante, able or ible, delete if in R2 - if ( ($position2 = $this->searchIfInR2(array('ante', 'able', 'ible'))) != false) { + if ( ($position2 = $this->searchIfInR2(['ante', 'able', 'ible'])) != false) { $this->word = UTF8::substr($this->word, 0, $position2); } return true; @@ -218,7 +218,7 @@ private function step1() // idad idades // delete if in R2 // if preceded by abil, ic or iv, delete if in R2 - if ( ($position = $this->search(array('idades', 'idad'))) != false) { + if ( ($position = $this->search(['idades', 'idad'])) != false) { // delete if in R2 if ($this->inR2($position)) { @@ -226,7 +226,7 @@ private function step1() } // if preceded by abil, ic or iv, delete if in R2 - if ( ($position2 = $this->searchIfInR2(array('abil', 'ic', 'iv'))) != false) { + if ( ($position2 = $this->searchIfInR2(['abil', 'ic', 'iv'])) != false) { $this->word = UTF8::substr($this->word, 0, $position2); } return true; @@ -235,7 +235,7 @@ private function step1() // iva ivo ivas ivos // delete if in R2 // if preceded by at, delete if in R2 - if ( ($position = $this->search(array('ivas', 'ivos', 'iva', 'ivo'))) != false) { + if ( ($position = $this->search(['ivas', 'ivos', 'iva', 'ivo'])) != false) { // delete if in R2 if ($this->inR2($position)) { @@ -243,7 +243,7 @@ private function step1() } // if preceded by at, delete if in R2 - if ( ($position2 = $this->searchIfInR2(array('at'))) != false) { + if ( ($position2 = $this->searchIfInR2(['at'])) != false) { $this->word = UTF8::substr($this->word, 0, $position2); } return true; @@ -259,8 +259,8 @@ private function step2a() { // if found, delete if preceded by u // (Note that the preceding u need not be in RV.) - if ( ($position = $this->searchIfInRv(array( - 'yamos', 'yendo', 'yeron', 'yan', 'yen', 'yais', 'yas', 'yes', 'yo', 'yó', 'ya', 'ye'))) != false) { + if ( ($position = $this->searchIfInRv([ + 'yamos', 'yendo', 'yeron', 'yan', 'yen', 'yais', 'yas', 'yes', 'yo', 'yó', 'ya', 'ye'])) != false) { $before = UTF8::substr($this->word, ($position-1), 1); if ( (isset($before)) && ($before == 'u') ) { @@ -279,7 +279,7 @@ private function step2a() private function step2b() { // delete - if ( ($position = $this->searchIfInRv(array( + if ( ($position = $this->searchIfInRv([ 'iésemos', 'iéramos', 'ábamos', 'iríamos', 'eríamos', 'aríamos', 'áramos', 'ásemos', 'eríais', 'aremos', 'eremos', 'iremos', 'asteis', 'ieseis', 'ierais', 'isteis', 'aríais', 'irían', 'aréis', 'erían', 'erías', 'eréis', 'iréis', 'irías', 'ieran', 'iesen', 'ieron', 'iendo', 'ieras', @@ -288,23 +288,24 @@ private function step2b() 'iera', 'iese', 'aste', 'iste', 'aban', 'aran', 'asen', 'aron', 'ando', 'abas', 'adas', 'idas', 'ases', 'aras', 'aré', 'erá', 'eré', 'áis', 'ías', 'irá', 'iré', 'aba', 'ían', 'ada', 'ara', 'ase', 'ida', 'ado', 'ido', 'ará', 'ad', 'ed', 'id', 'ís', 'ió', 'ar', 'er', 'ir', 'as', 'ía', 'an' - ))) != false) { + ])) != false) { $this->word = UTF8::substr($this->word, 0, $position); return true; } // en es éis emos // delete, and if preceded by gu delete the u (the gu need not be in RV) - if ( ($position = $this->searchIfInRv(array('éis', 'emos', 'en', 'es'))) != false) { + if ( ($position = $this->searchIfInRv(['éis', 'emos', 'en', 'es'])) != false) { $this->word = UTF8::substr($this->word, 0, $position); - if ( ($position2 = $this->search(array('gu'))) != false) { + if ( ($position2 = $this->search(['gu'])) != false) { $this->word = UTF8::substr($this->word, 0, ($position2+1)); } return true; } + return null; } /** @@ -315,17 +316,17 @@ private function step3() { // os a o á í ó // delete if in RV - if ( ($position = $this->searchIfInRv(array('os', 'a', 'o', 'á', 'í', 'ó'))) != false) { + if ( ($position = $this->searchIfInRv(['os', 'a', 'o', 'á', 'í', 'ó'])) != false) { $this->word = UTF8::substr($this->word, 0, $position); return true; } // e é // delete if in RV, and if preceded by gu with the u in RV delete the u - if ( ($position = $this->searchIfInRv(array('e', 'é'))) != false) { + if ( ($position = $this->searchIfInRv(['e', 'é'])) != false) { $this->word = UTF8::substr($this->word, 0, $position); - if ( ($position2 = $this->searchIfInRv(array('u'))) != false) { + if ( ($position2 = $this->searchIfInRv(['u'])) != false) { $before = UTF8::substr($this->word, ($position2-1), 1); if ( (isset($before)) && ($before == 'g') ) { $this->word = UTF8::substr($this->word, 0, $position2); @@ -343,6 +344,6 @@ private function step3() */ private function finish() { - $this->word = str_replace(array('á', 'í', 'ó', 'é', 'ú'), array('a', 'i', 'o', 'e', 'u'), $this->word); + $this->word = str_replace(['á', 'í', 'ó', 'é', 'ú'], ['a', 'i', 'o', 'e', 'u'], $this->word); } } diff --git a/src/Stemmer/Stem.php b/src/Stemmer/Stem.php index 0c6f148..8bf24e3 100644 --- a/src/Stemmer/Stem.php +++ b/src/Stemmer/Stem.php @@ -6,7 +6,7 @@ abstract class Stem implements Stemmer { - protected static $vowels = array('a', 'e', 'i', 'o', 'u', 'y'); + protected static $vowels = ['a', 'e', 'i', 'o', 'u', 'y']; /** * helper, contains stringified list of vowels @@ -112,7 +112,7 @@ protected function search($suffixes, $offset = 0) */ protected function r1() { - list($this->r1Index, $this->r1) = $this->rx($this->word); + [$this->r1Index, $this->r1] = $this->rx($this->word); } /** @@ -120,7 +120,7 @@ protected function r1() */ protected function r2() { - list($index, $value) = $this->rx($this->r1); + [$index, $value] = $this->rx($this->r1); $this->r2 = $value; $this->r2Index = $this->r1Index + $index; @@ -141,7 +141,7 @@ protected function rx($in) $index = $length; // we search all vowels - $vowels = array(); + $vowels = []; for ($i=0; $i<$length; $i++) { $letter = UTF8::substr($in, $i, 1); if (in_array($letter, static::$vowels)) { @@ -162,7 +162,7 @@ protected function rx($in) } } - return array($index, $value); + return [$index, $value]; } /** @@ -217,5 +217,6 @@ protected function rv() $this->rvIndex = 3; return true; } + return null; } } diff --git a/src/Stemmer/Stemmer.php b/src/Stemmer/Stemmer.php index b43b0f1..cf04660 100644 --- a/src/Stemmer/Stemmer.php +++ b/src/Stemmer/Stemmer.php @@ -1,4 +1,7 @@ searchIfInR1(array( + if ( ($position = $this->searchIfInR1([ 'heterna', 'hetens', 'ornas', 'andes', 'arnas', 'heter', 'ernas', 'anden', 'heten', 'andet', 'arens', 'orna', 'arna', 'erna', 'aren', 'ande', 'ades', 'arne', 'erns', 'aste', 'ade', 'ern', 'het', 'ast', 'are', 'ens', 'or', 'es', 'ad', 'en', 'at', 'ar', 'as', 'er', 'a', 'e' - ))) !== false) { + ])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); return true; } // s // delete if preceded by a valid s-ending - if ( ($position = $this->searchIfInR1(array('s'))) !== false) { + if ( ($position = $this->searchIfInR1(['s'])) !== false) { $word = UTF8::substr($this->word, 0, $position); if ($this->hasValidSEnding($word)) { $this->word = $word; } } + return null; } /** @@ -95,7 +96,7 @@ private function step1() private function step2() { // dd gd nn dt gt kt tt - if ($this->searchIfInR1(array('dd', 'gd', 'nn', 'dt', 'gt', 'kt', 'tt')) !== false) { + if ($this->searchIfInR1(['dd', 'gd', 'nn', 'dt', 'gt', 'kt', 'tt']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); } } @@ -108,23 +109,24 @@ private function step3() { // lig ig els // delete - if ( ($position = $this->searchIfInR1(array('lig', 'ig', 'els'))) !== false) { + if ( ($position = $this->searchIfInR1(['lig', 'ig', 'els'])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); return true; } // löst // replace with lös - if ( ($this->searchIfInR1(array('löst'))) !== false) { + if ( ($this->searchIfInR1(['löst'])) !== false) { $this->word = UTF8::substr($this->word, 0, -1); return true; } // fullt // replace with full - if ( ($this->searchIfInR1(array('fullt'))) !== false) { + if ( ($this->searchIfInR1(['fullt'])) !== false) { $this->word = UTF8::substr($this->word, 0, -1); return true; } + return null; } } diff --git a/src/StemmerManager.php b/src/StemmerManager.php index e31acc3..3deb45d 100644 --- a/src/StemmerManager.php +++ b/src/StemmerManager.php @@ -5,12 +5,7 @@ class StemmerManager { /** @var array */ - private $stemmers; - - public function __construct() - { - $this->stemmers = []; - } + private $stemmers = []; /** * @throws NotFoundException diff --git a/test/CsvFileIterator.php b/test/CsvFileIterator.php index bf1ed17..269e8df 100644 --- a/test/CsvFileIterator.php +++ b/test/CsvFileIterator.php @@ -10,7 +10,7 @@ class CsvFileIterator implements \Iterator public function __construct($file) { if (! ($this->file = fopen($file, 'r'))) { - die('Can\'t open file '.$this->file)."\n"; + die('Can\'t open file '.$this->file); } } diff --git a/test/FactoryTest.php b/test/FactoryTest.php index 73dd5f2..44e65b2 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -1,5 +1,7 @@ 'Wamania\\Snowball\\Stemmer\\Catalan', - 'cat' => 'Wamania\\Snowball\\Stemmer\\Catalan', - 'catalan' => 'Wamania\\Snowball\\Stemmer\\Catalan', - 'da' => 'Wamania\\Snowball\\Stemmer\\Danish', - 'dan' => 'Wamania\\Snowball\\Stemmer\\Danish', - 'danish' => 'Wamania\\Snowball\\Stemmer\\Danish', - 'nl' => 'Wamania\\Snowball\\Stemmer\\Dutch', - 'dut' => 'Wamania\\Snowball\\Stemmer\\Dutch', - 'nld' => 'Wamania\\Snowball\\Stemmer\\Dutch', - 'dutch' => 'Wamania\\Snowball\\Stemmer\\Dutch', - 'en' => 'Wamania\\Snowball\\Stemmer\\English', - 'eng' => 'Wamania\\Snowball\\Stemmer\\English', - 'english' => 'Wamania\\Snowball\\Stemmer\\English', - 'fr' => 'Wamania\\Snowball\\Stemmer\\French', - 'fre' => 'Wamania\\Snowball\\Stemmer\\French', - 'fra' => 'Wamania\\Snowball\\Stemmer\\French', - 'french' => 'Wamania\\Snowball\\Stemmer\\French', - 'de' => 'Wamania\\Snowball\\Stemmer\\German', - 'deu' => 'Wamania\\Snowball\\Stemmer\\German', - 'ger' => 'Wamania\\Snowball\\Stemmer\\German', - 'german' => 'Wamania\\Snowball\\Stemmer\\German', - 'it' => 'Wamania\\Snowball\\Stemmer\\Italian', - 'ita' => 'Wamania\\Snowball\\Stemmer\\Italian', - 'italian' => 'Wamania\\Snowball\\Stemmer\\Italian', - 'no' => 'Wamania\\Snowball\\Stemmer\\Norwegian', - 'nor' => 'Wamania\\Snowball\\Stemmer\\Norwegian', - 'norwegian' => 'Wamania\\Snowball\\Stemmer\\Norwegian', - 'pt' => 'Wamania\\Snowball\\Stemmer\\Portuguese', - 'por' => 'Wamania\\Snowball\\Stemmer\\Portuguese', - 'portuguese' => 'Wamania\\Snowball\\Stemmer\\Portuguese', - 'ro' => 'Wamania\\Snowball\\Stemmer\\Romanian', - 'rum' => 'Wamania\\Snowball\\Stemmer\\Romanian', - 'ron' => 'Wamania\\Snowball\\Stemmer\\Romanian', - 'romanian' => 'Wamania\\Snowball\\Stemmer\\Romanian', - 'ru' => 'Wamania\\Snowball\\Stemmer\\Russian', - 'rus' => 'Wamania\\Snowball\\Stemmer\\Russian', - 'russian' => 'Wamania\\Snowball\\Stemmer\\Russian', - 'es' => 'Wamania\\Snowball\\Stemmer\\Spanish', - 'spa' => 'Wamania\\Snowball\\Stemmer\\Spanish', - 'spanish' => 'Wamania\\Snowball\\Stemmer\\Spanish', - 'sv' => 'Wamania\\Snowball\\Stemmer\\Swedish', - 'swe' => 'Wamania\\Snowball\\Stemmer\\Swedish', - 'swedish' => 'Wamania\\Snowball\\Stemmer\\Swedish', + 'ca' => \Wamania\Snowball\Stemmer\Catalan::class, + 'cat' => \Wamania\Snowball\Stemmer\Catalan::class, + 'catalan' => \Wamania\Snowball\Stemmer\Catalan::class, + 'da' => \Wamania\Snowball\Stemmer\Danish::class, + 'dan' => \Wamania\Snowball\Stemmer\Danish::class, + 'danish' => \Wamania\Snowball\Stemmer\Danish::class, + 'nl' => \Wamania\Snowball\Stemmer\Dutch::class, + 'dut' => \Wamania\Snowball\Stemmer\Dutch::class, + 'nld' => \Wamania\Snowball\Stemmer\Dutch::class, + 'dutch' => \Wamania\Snowball\Stemmer\Dutch::class, + 'en' => \Wamania\Snowball\Stemmer\English::class, + 'eng' => \Wamania\Snowball\Stemmer\English::class, + 'english' => \Wamania\Snowball\Stemmer\English::class, + 'fr' => \Wamania\Snowball\Stemmer\French::class, + 'fre' => \Wamania\Snowball\Stemmer\French::class, + 'fra' => \Wamania\Snowball\Stemmer\French::class, + 'french' => \Wamania\Snowball\Stemmer\French::class, + 'de' => \Wamania\Snowball\Stemmer\German::class, + 'deu' => \Wamania\Snowball\Stemmer\German::class, + 'ger' => \Wamania\Snowball\Stemmer\German::class, + 'german' => \Wamania\Snowball\Stemmer\German::class, + 'it' => \Wamania\Snowball\Stemmer\Italian::class, + 'ita' => \Wamania\Snowball\Stemmer\Italian::class, + 'italian' => \Wamania\Snowball\Stemmer\Italian::class, + 'no' => \Wamania\Snowball\Stemmer\Norwegian::class, + 'nor' => \Wamania\Snowball\Stemmer\Norwegian::class, + 'norwegian' => \Wamania\Snowball\Stemmer\Norwegian::class, + 'pt' => \Wamania\Snowball\Stemmer\Portuguese::class, + 'por' => \Wamania\Snowball\Stemmer\Portuguese::class, + 'portuguese' => \Wamania\Snowball\Stemmer\Portuguese::class, + 'ro' => \Wamania\Snowball\Stemmer\Romanian::class, + 'rum' => \Wamania\Snowball\Stemmer\Romanian::class, + 'ron' => \Wamania\Snowball\Stemmer\Romanian::class, + 'romanian' => \Wamania\Snowball\Stemmer\Romanian::class, + 'ru' => \Wamania\Snowball\Stemmer\Russian::class, + 'rus' => \Wamania\Snowball\Stemmer\Russian::class, + 'russian' => \Wamania\Snowball\Stemmer\Russian::class, + 'es' => \Wamania\Snowball\Stemmer\Spanish::class, + 'spa' => \Wamania\Snowball\Stemmer\Spanish::class, + 'spanish' => \Wamania\Snowball\Stemmer\Spanish::class, + 'sv' => \Wamania\Snowball\Stemmer\Swedish::class, + 'swe' => \Wamania\Snowball\Stemmer\Swedish::class, + 'swedish' => \Wamania\Snowball\Stemmer\Swedish::class, ]; foreach ($isoCodes as $isoCode => $classname) { diff --git a/test/ManagerTest.php b/test/ManagerTest.php index cfe0e9a..0e1586f 100644 --- a/test/ManagerTest.php +++ b/test/ManagerTest.php @@ -1,5 +1,7 @@ Date: Mon, 15 Jun 2026 14:34:25 +0100 Subject: [PATCH 3/5] Typing --- rector.php | 2 +- src/Stemmer/Catalan.php | 12 ++++++------ src/Stemmer/Danish.php | 11 +++++------ src/Stemmer/Dutch.php | 19 +++++++++---------- src/Stemmer/English.php | 34 ++++++++++++++++------------------ src/Stemmer/Finnish.php | 14 +++++++------- src/Stemmer/French.php | 22 +++++++++++----------- src/Stemmer/German.php | 8 ++++---- src/Stemmer/Italian.php | 16 ++++++++-------- src/Stemmer/Norwegian.php | 11 +++++------ src/Stemmer/Portuguese.php | 12 ++++++------ src/Stemmer/Romanian.php | 17 +++++++---------- src/Stemmer/Russian.php | 12 ++++++------ src/Stemmer/Spanish.php | 18 +++++++++--------- src/Stemmer/Stem.php | 2 +- src/Stemmer/Swedish.php | 11 +++++------ test/CatalanTest.php | 4 ++-- test/CsvFileIterator.php | 4 ++-- test/DanishTest.php | 4 ++-- test/DutchTest.php | 4 ++-- test/EnglishTest.php | 4 ++-- test/FactoryTest.php | 2 +- test/FinnishTest.php | 4 ++-- test/FrenchTest.php | 4 ++-- test/GermanTest.php | 4 ++-- test/ItalianTest.php | 4 ++-- test/ManagerTest.php | 2 +- test/NorwegianTest.php | 4 ++-- test/PortugueseTest.php | 4 ++-- test/RomanianTest.php | 4 ++-- test/RussianTest.php | 4 ++-- test/SpanishTest.php | 4 ++-- test/SwedishTest.php | 4 ++-- 33 files changed, 138 insertions(+), 147 deletions(-) diff --git a/rector.php b/rector.php index 894587f..74e5e82 100644 --- a/rector.php +++ b/rector.php @@ -16,7 +16,7 @@ ->withPreparedSets( codeQuality: true, deadCode: true, - // typeDeclarations: true, + typeDeclarations: true, ) ->withComposerBased( phpunit: true, diff --git a/src/Stemmer/Catalan.php b/src/Stemmer/Catalan.php index 94a02e3..d6c341a 100644 --- a/src/Stemmer/Catalan.php +++ b/src/Stemmer/Catalan.php @@ -84,7 +84,7 @@ class Catalan extends Stem /** * {@inheritdoc} */ - public function stem($word) + public function stem($word): string { // we do ALL in UTF-8 if (!UTF8::is_utf8($word)) { @@ -123,7 +123,7 @@ public function stem($word) * and delete it in R1. */ - private function step0() + private function step0(): bool { if ($position = $this->search(static::$attached_pronoun) !== false && $this->inR1($position)) { $this->word = UTF8::substr($this->word, 0, $position); @@ -135,7 +135,7 @@ private function step0() /** * Step 1a: Standard suffix */ - private function step1a() + private function step1a(): bool { // Run step 1a.2 before 1a.1, since they overlap on `cions` (1a.1) and `acions` (1a.2) // @@ -211,7 +211,7 @@ private function step1a() * Search for the longest among the following suffixes in r1 and r2, and * perform the action indicated. */ - private function step1b() + private function step1b(): bool { // Step 1b.1 // @@ -261,7 +261,7 @@ private function step1b() * Search for the longest among the following suffixes in R1, and perform * the action indicated. */ - private function step2() + private function step2(): bool { // Step 2.1 // residual suffix @@ -290,7 +290,7 @@ private function step2() * And finally: * Remove accents and l aggeminades */ - private function finish() + private function finish(): void { $this->word = str_replace( ['á', 'é', 'í', 'ó', 'ú', 'à', 'è', 'ì', 'ò', 'ï', 'ü', '·'], diff --git a/src/Stemmer/Danish.php b/src/Stemmer/Danish.php index 335cce1..09a91b8 100644 --- a/src/Stemmer/Danish.php +++ b/src/Stemmer/Danish.php @@ -52,9 +52,8 @@ public function stem($word): string * a b c d f g h j k l m n o p r t v y z å * * @param string $ending - * @return boolean */ - private function hasValidSEnding($word) + private function hasValidSEnding(string $word): bool { $lastLetter = UTF8::substr($word, -1, 1); return in_array($lastLetter, ['a', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'v', 'y', 'z', 'å']); @@ -64,7 +63,7 @@ private function hasValidSEnding($word) * Step 1 * Search for the longest among the following suffixes in R1, and perform the action indicated. */ - private function step1() + private function step1(): ?bool { // hed ethed ered e erede ende erende ene erne ere en heden eren er heder erer // heds es endes erendes enes ernes eres ens hedens erens ers ets erets et eret @@ -95,7 +94,7 @@ private function step1() * Search for one of the following suffixes in R1, and if found delete the last letter. * gd dt gt kt */ - private function step2() + private function step2(): void { if ($this->searchIfInR1(['gd', 'dt', 'gt', 'kt']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); @@ -105,7 +104,7 @@ private function step2() /** * Step 3: */ - private function step3() + private function step3(): ?bool { // If the word ends igst, remove the final st. if ($this->search(['igst']) !== false) { @@ -133,7 +132,7 @@ private function step3() * Step 4: undouble * If the word ends with double consonant in R1, remove one of the consonants. */ - private function step4() + private function step4(): bool { $length = UTF8::strlen($this->word); if (!$this->inR1(($length-1))) { diff --git a/src/Stemmer/Dutch.php b/src/Stemmer/Dutch.php index 8e03aed..05a8e7d 100644 --- a/src/Stemmer/Dutch.php +++ b/src/Stemmer/Dutch.php @@ -67,9 +67,8 @@ public function stem($word) /** * Define a valid s-ending as a non-vowel other than j. * @param string $ending - * @return boolean */ - private function hasValidSEnding($word) + private function hasValidSEnding(string $word): bool { $lastLetter = UTF8::substr($word, -1, 1); return !in_array($lastLetter, array_merge(self::$vowels, ['j'])); @@ -80,7 +79,7 @@ private function hasValidSEnding($word) * @param string $ending * @return boolean */ - private function hasValidEnEnding($word) + private function hasValidEnEnding(string $word) { $lastLetter = UTF8::substr($word, -1, 1); if (in_array($lastLetter, self::$vowels)) { @@ -94,7 +93,7 @@ private function hasValidEnEnding($word) /** * Define undoubling the ending as removing the last letter if the word ends kk, dd or tt. */ - private function unDoubling() + private function unDoubling(): void { if ($this->search(['kk', 'dd', 'tt']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); @@ -105,7 +104,7 @@ private function unDoubling() * Step 1 * Search for the longest among the following suffixes, and perform the action indicated */ - private function step1() + private function step1(): bool { // heden // replace with heid if in R1 @@ -148,7 +147,7 @@ private function step1() * Step 2 * Delete suffix e if in R1 and preceded by a non-vowel, and then undouble the ending */ - private function step2() + private function step2(): bool { if ($position = $this->search(['e']) !== false && $this->inR1($position)) { $letter = UTF8::substr($this->word, -2, 1); @@ -167,7 +166,7 @@ private function step2() * Step 3a: heid * delete heid if in R2 and not preceded by c, and treat a preceding en as in step 1(b) */ - private function step3a() + private function step3a(): void { if ($position = $this->search(['heid']) !== false && $this->inR2($position)) { $letter = UTF8::substr($this->word, -5, 1); @@ -190,7 +189,7 @@ private function step3a() * Step 3b: d-suffixe * Search for the longest among the following suffixes, and perform the action indicated. */ - private function step3b($removedE) + private function step3b($removedE): bool { // end ing // delete if in R2 @@ -261,7 +260,7 @@ private function step3b($removedE) * If the words ends CVD, where C is a non-vowel, D is a non-vowel other than I, and V is double a, e, o or u, * remove one of the vowels from V (for example, maan -> man, brood -> brod). */ - private function step4() + private function step4(): ?bool { // D is a non-vowel other than I $d = UTF8::substr($this->word, -1, 1); @@ -291,7 +290,7 @@ private function step4() * Finally * Turn I and Y back into lower case. */ - private function finish() + private function finish(): void { $this->word = str_replace(['I', 'Y'], ['i', 'y'], $this->word); } diff --git a/src/Stemmer/English.php b/src/Stemmer/English.php index 921d90d..b7e4c40 100644 --- a/src/Stemmer/English.php +++ b/src/Stemmer/English.php @@ -85,14 +85,14 @@ public function stem($word) * Step 0 * Remove ', 's, 's' */ - private function step0() + private function step0(): void { if ( ($position = $this->search(["'s'", "'s", "'"])) !== false) { $this->word = UTF8::substr($this->word, 0, $position); } } - private function step1a() + private function step1a(): bool { // sses // replace by ss @@ -139,7 +139,7 @@ private function step1a() /** * Step 1b */ - private function step1b() + private function step1b(): bool { // eed eedly+ // replace by ee if in R1 @@ -184,7 +184,7 @@ private function step1b() /** * Step 1c: * */ - private function step1c() + private function step1c(): bool { // replace suffix y or Y by i if preceded by a non-vowel // which is not the first letter of the word (so cry -> cri, by -> by, say -> say) @@ -212,7 +212,7 @@ private function step1c() * Step 2 * Search for the longest among the following suffixes, and, if found and in R1, perform the action indicated. */ - private function step2() + private function step2(): bool { // iveness iviti: replace by ive if ( ($position = $this->search(['iveness', 'iviti'])) !== false) { @@ -355,7 +355,7 @@ private function step2() * Step 3: * Search for the longest among the following suffixes, and, if found and in R1, perform the action indicated. */ - private function step3() + private function step3(): bool { // ational+: replace by ate if ($this->searchIfInR1(['ational']) !== false) { @@ -400,7 +400,7 @@ private function step3() * Step 4 * Search for the longest among the following suffixes, and, if found and in R2, perform the action indicated. */ - private function step4() + private function step4(): bool { // ement ance ence able ible ant ment ent ism ate iti ous ive ize al er ic // delete @@ -434,7 +434,7 @@ private function step4() * Step 5: * * Search for the the following suffixes, and, if found, perform the action indicated. */ - private function step5() + private function step5(): bool { // e // delete if in R2, or in R1 and not preceded by a short syllable @@ -467,12 +467,12 @@ private function step5() return false; } - private function finish() + private function finish(): void { $this->word = str_replace('Y', 'y', $this->word); } - private function exceptionR1() + private function exceptionR1(): void { if (Utf8::strpos($this->word, 'gener') === 0) { $this->r1 = UTF8::substr($this->word, 5); @@ -492,7 +492,7 @@ private function exceptionR1() * 1/ Stem certain special words as follows, * 2/ If one of the following is found, leave it invariant, */ - private function exception1() + private function exception1(): ?string { $exceptions = [ 'skis' => 'ski', @@ -522,7 +522,7 @@ private function exception1() /** * Following step 1a, leave the following invariant, */ - private function exception2() + private function exception2(): ?string { $exceptions = [ 'inning' => 'inning', @@ -541,10 +541,8 @@ private function exception2() /** * A word is called short if it ends in a short syllable, and if R1 is null. * Note : R1 not really null, but the word at this state must be smaller than r1 index - * - * @return boolean */ - private function isShort() + private function isShort(): bool { $length = UTF8::strlen($this->word); return ( ($this->searchShortSyllabe(-3, 3) || $this->searchShortSyllabe(-2, 2)) && ($length == $this->r1Index) ); @@ -557,7 +555,7 @@ private function isShort() * So rap, trap, entrap end with a short syllable, and ow, on, at are classed as short syllables. * But uproot, bestow, disturb do not end with a short syllable. */ - private function searchShortSyllabe($from, $nbLetters) + private function searchShortSyllabe(int $from, int $nbLetters) { $length = UTF8::strlen($this->word); @@ -569,14 +567,14 @@ private function searchShortSyllabe($from, $nbLetters) } // (a) is just for beginning of the word - if ( ($nbLetters == 2) && ($from != 0) ) { + if ( ($nbLetters === 2) && ($from != 0) ) { return false; } $first = UTF8::substr($this->word, $from, 1); $second = UTF8::substr($this->word, ($from+1), 1); - if ($nbLetters == 2 && (in_array($first, self::$vowels) && !in_array($second, self::$vowels))) { + if ($nbLetters === 2 && (in_array($first, self::$vowels) && !in_array($second, self::$vowels))) { return true; } diff --git a/src/Stemmer/Finnish.php b/src/Stemmer/Finnish.php index 136bc7b..6a8f749 100644 --- a/src/Stemmer/Finnish.php +++ b/src/Stemmer/Finnish.php @@ -36,7 +36,7 @@ class Finnish extends Stem /** * {@inheritdoc} */ - public function stem($word) + public function stem($word): string { // we do ALL in UTF-8 if (! UTF8::is_utf8($word)) { @@ -69,7 +69,7 @@ public function stem($word) * * @return boolean True when something is done. */ - private function step1() + private function step1(): ?bool { // (a) kin kaan kään ko kö han hän pa pä // delete if preceded by n, t or a vowel @@ -107,7 +107,7 @@ private function step1() * * @return boolean True when something is done. */ - private function step2() + private function step2(): ?bool { // si // delete if not preceded by k @@ -197,7 +197,7 @@ private function step2() * * @return boolean True when something is done. */ - private function step3() + private function step3(): ?bool { // hXn // delete if preceded by X, where X is a V other than u (a/han, e/hen etc) @@ -312,7 +312,7 @@ private function step3() * * @return boolean True when something is done. */ - private function step4() + private function step4(): ?bool { // mpi mpa mpä mmi mma mmä // delete if not preceded by po @@ -347,7 +347,7 @@ private function step4() * * @return boolean True when something is done. */ - private function step5() + private function step5(): ?bool { if ($this->_removedInStep3) { if (($position = $this->searchIfInR1(['i', 'j'])) !== false) { @@ -388,7 +388,7 @@ private function step5() * Do in turn steps (a), (b), (c), (d), restricting all tests to the * region R1. */ - private function step6() + private function step6(): void { // a) If R1 ends LV // delete the last letter diff --git a/src/Stemmer/French.php b/src/Stemmer/French.php index ed33897..f32fafa 100644 --- a/src/Stemmer/French.php +++ b/src/Stemmer/French.php @@ -20,7 +20,7 @@ class French extends Stem /** * {@inheritdoc} */ - public function stem($word) + public function stem($word): string { // we do ALL in UTF-8 if (!UTF8::is_utf8($word)) { @@ -75,7 +75,7 @@ public function stem($word) * yeux -> Yeux * quand -> qUand */ - private function step0() + private function step0(): void { $this->word = preg_replace('#([q])u#u', '$1U', $this->word); $this->word = preg_replace('#(['.$this->plainVowels.'])y#u', '$1Y', $this->word); @@ -90,7 +90,7 @@ private function step0() * * @return integer Next step number */ - private function step1() + private function step1(): int { // ance iqUe isme able iste eux ances iqUes ismes ables istes // delete if in R2 @@ -329,7 +329,7 @@ private function step1() * issent isses issez issiez issions issons it * (Note that the non-vowel itself must also be in RV.) */ - private function step2a() + private function step2a(): bool { if ( ($position = $this->searchIfInRv([ 'îmes', 'îtes', 'ît', 'ies', 'ie', 'iraIent', 'irais', 'irait', 'irai', 'iras', 'ira', 'irent', 'irez', 'iriez', @@ -352,7 +352,7 @@ private function step2a() * Do step 2b if step 2a was done, but failed to remove a suffix. * Step 2b: Other verb suffixes */ - private function step2b() + private function step2b(): bool { // é ée ées és èrent er era erai eraIent erais erait eras erez eriez erions erons eront ez iez // delete @@ -400,7 +400,7 @@ private function step2b() /** * Step 3: Replace final Y with i or final ç with c */ - private function step3() + private function step3(): void { $this->word = preg_replace('#(Y)$#u', 'i', $this->word); $this->word = preg_replace('#(ç)$#u', 'c', $this->word); @@ -409,7 +409,7 @@ private function step3() /** * Step 4: Residual suffix */ - private function step4() + private function step4(): bool { //If the word ends s, not preceded by a, i, o, u, è or s, delete it. if (preg_match('#[^aiouès]s$#', $this->word)) { @@ -456,7 +456,7 @@ private function step4() * Step 5: Undouble * If the word ends enn, onn, ett, ell or eill, delete the last letter */ - private function step5() + private function step5(): void { if ($this->search(['enn', 'onn', 'ett', 'ell', 'eill']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); @@ -467,7 +467,7 @@ private function step5() * Step 6: Un-accent * If the words ends é or è followed by at least one non-vowel, remove the accent from the e. */ - private function step6() + private function step6(): void { $this->word = preg_replace('#(é|è)([^'.$this->plainVowels.']+)$#u', 'e$2', $this->word); } @@ -476,7 +476,7 @@ private function step6() * And finally: * Turn any remaining I, U and Y letters in the word back into lower case. */ - private function finish() + private function finish(): void { $this->word = str_replace(['I','U','Y'], ['i', 'u', 'y'], $this->word); } @@ -487,7 +487,7 @@ private function finish() * or the end of the word if these positions cannot be found. * (Exceptionally, par, col or tap, at the begining of a word is also taken to define RV as the region to their right.) */ - protected function rv() + protected function rv(): bool { $length = UTF8::strlen($this->word); diff --git a/src/Stemmer/German.php b/src/Stemmer/German.php index 764adc1..37ce3d8 100644 --- a/src/Stemmer/German.php +++ b/src/Stemmer/German.php @@ -63,7 +63,7 @@ public function stem($word) /** * Step 1 */ - private function step1() + private function step1(): bool { // delete if in R1 if ( ($position = $this->search(['em', 'ern', 'er'])) !== false) { @@ -105,7 +105,7 @@ private function step1() /** * Step 2 */ - private function step2() + private function step2(): bool { // en er est // delete if in R1 @@ -137,7 +137,7 @@ private function step2() /** * Step 3: d-suffixes */ - private function step3() + private function step3(): bool { // end ung // delete if in R2 @@ -204,7 +204,7 @@ private function step3() /** * Finally */ - private function finish() + private function finish(): void { // turn U and Y back into lower case, and remove the umlaut accent from a, o and u. $this->word = str_replace(['U', 'Y', 'ä', 'ü', 'ö'], ['u', 'y', 'a', 'u', 'o'], $this->word); diff --git a/src/Stemmer/Italian.php b/src/Stemmer/Italian.php index 9749137..3956f97 100644 --- a/src/Stemmer/Italian.php +++ b/src/Stemmer/Italian.php @@ -63,7 +63,7 @@ public function stem($word) /** * Step 0: Attached pronoun */ - private function step0() + private function step0(): bool { // Search for the longest among the following suffixes if ( ($position = $this->search([ @@ -77,7 +77,7 @@ private function step0() // following one of (in RV) // a $a = ['ando', 'endo']; - $a = array_map(function($item) use ($suffixe) { + $a = array_map(function(string $item) use ($suffixe): string { return $item . $suffixe; }, $a); // In case of (a) the suffix is deleted @@ -87,7 +87,7 @@ private function step0() //b $b = ['ar', 'er', 'ir']; - $b = array_map(function($item) use ($suffixe) { + $b = array_map(function(string $item) use ($suffixe): string { return $item . $suffixe; }, $b); // in case (b) it is replace by e @@ -104,7 +104,7 @@ private function step0() /** * Step 1: Standard suffix removal */ - private function step1() + private function step1(): bool { // amente // delete if in R1 @@ -230,7 +230,7 @@ private function step1() * Step 2: Verb suffixes * Search for the longest among the following suffixes in RV, and if found, delete. */ - private function step2() + private function step2(): void { if ( ($position = $this->searchIfInRv([ 'assimo', 'assero', 'eranno', 'erebbero', 'erebbe', 'eremmo', 'ereste', 'eresti', 'essero', 'iranno', 'irebbero', 'irebbe', 'iremmo', @@ -249,7 +249,7 @@ private function step2() * Step 3a * Delete a final a, e, i, o, à, è, ì or ò if it is in RV, and a preceding i if it is in RV */ - private function step3a() + private function step3a(): bool { if ($this->searchIfInRv(['a', 'e', 'i', 'o', 'à', 'è', 'ì', 'ò']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); @@ -266,7 +266,7 @@ private function step3a() * Step 3b * Replace final ch (or gh) with c (or g) if in RV (crocch -> crocc) */ - private function step3b() + private function step3b(): void { if ($this->searchIfInRv(['ch']) !== false) { $this->word = preg_replace('#(ch)$#u', 'c', $this->word); @@ -280,7 +280,7 @@ private function step3b() * Finally * turn I and U back into lower case */ - private function finish() + private function finish(): void { $this->word = str_replace(['I', 'U'], ['i', 'u'], $this->word); } diff --git a/src/Stemmer/Norwegian.php b/src/Stemmer/Norwegian.php index 35ce94f..19f1da8 100644 --- a/src/Stemmer/Norwegian.php +++ b/src/Stemmer/Norwegian.php @@ -20,7 +20,7 @@ class Norwegian extends Stem /** * {@inheritdoc} */ - public function stem($word) + public function stem($word): string { // we do ALL in UTF-8 if (!UTF8::is_utf8($word)) { @@ -52,9 +52,8 @@ public function stem($word) * or k not preceded by a vowel * * @param string $ending - * @return boolean */ - private function hasValidSEnding($word) + private function hasValidSEnding(string $word): bool { $lastLetter = UTF8::substr($word, -1, 1); if (in_array($lastLetter, ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'v', 'y', 'z'])) { @@ -73,7 +72,7 @@ private function hasValidSEnding($word) * Step 1 * Search for the longest among the following suffixes in R1, and perform the action indicated. */ - private function step1() + private function step1(): ?bool { // erte ert // replace with er @@ -108,7 +107,7 @@ private function step1() * Step 2 * If the word ends dt or vt in R1, delete the t. */ - private function step2() + private function step2(): void { if ($this->searchIfInR1(['dt', 'vt']) !== false) { $this->word = UTF8::substr($this->word, 0, -1); @@ -119,7 +118,7 @@ private function step2() * Step 3: * Search for the longest among the following suffixes in R1, and if found, delete. */ - private function step3() + private function step3(): void { // leg eleg ig eig lig elig els lov elov slov hetslov if ( ($position = $this->searchIfInR1([ diff --git a/src/Stemmer/Portuguese.php b/src/Stemmer/Portuguese.php index 0a2abaf..b335d93 100644 --- a/src/Stemmer/Portuguese.php +++ b/src/Stemmer/Portuguese.php @@ -57,7 +57,7 @@ public function stem($word) /** * Step 1: Standard suffix removal */ - private function step1() + private function step1(): bool { // delete if in R2 if ( ($position = $this->search([ @@ -196,7 +196,7 @@ private function step1() * Step 2: Verb suffixes * Search for the longest among the following suffixes in RV, and if found, delete. */ - private function step2() + private function step2(): bool { if ( ($position = $this->searchIfInRv([ 'aríamos', 'eríamos', 'iríamos', 'ássemos', 'êssemos', 'íssemos', @@ -223,7 +223,7 @@ private function step2() * Step 3: d-suffixes * */ - private function step3() + private function step3(): bool { // Delete suffix i if in RV and preceded by c if ($this->searchIfInRv(['i']) !== false) { @@ -240,7 +240,7 @@ private function step3() /** * Step 4 */ - private function step4() + private function step4(): bool { // If the word ends with one of the suffixes "os a i o á í ó" in RV, delete it if ( ($position = $this->searchIfInRv(['os', 'a', 'i', 'o','á', 'í', 'ó'])) !== false) { @@ -253,7 +253,7 @@ private function step4() /** * Step 5 */ - private function step5() + private function step5(): bool { // If the word ends with one of "e é ê" in RV, delete it, and if preceded by gu (or ci) with the u (or i) in RV, delete the u (or i). if ($this->searchIfInRv(['e', 'é', 'ê']) !== false) { @@ -272,7 +272,7 @@ private function step5() /** * Finally */ - private function finish() + private function finish(): void { // turn U and Y back into lower case, and remove the umlaut accent from a, o and u. $this->word = str_replace(['a~', 'o~'], ['ã', 'õ'], $this->word); diff --git a/src/Stemmer/Romanian.php b/src/Stemmer/Romanian.php index f423ab9..5c9d757 100644 --- a/src/Stemmer/Romanian.php +++ b/src/Stemmer/Romanian.php @@ -20,7 +20,7 @@ class Romanian extends Stem /** * {@inheritdoc} */ - public function stem($word) + public function stem($word): ?string { // we do ALL in UTF-8 if (!UTF8::is_utf8($word)) { @@ -65,9 +65,8 @@ public function stem($word) /** * Step 0: Removal of plurals (and other simplifications) * Search for the longest among the following suffixes, and, if it is in R1, perform the action indicated. - * @return boolean */ - private function step0() + private function step0(): bool { // ul ului // delete @@ -143,9 +142,8 @@ private function step0() * Step 1: Reduction of combining suffixes * Search for the longest among the following suffixes, and, if it is in R1, preform the replacement action indicated. * Then repeat this step until no replacement occurs. - * @return boolean */ - private function step1() + private function step1(): bool { // abilitate abilitati abilităi abilităţi // replace with abil @@ -209,9 +207,8 @@ private function step1() /** * Step 2: Removal of 'standard' suffixes * Search for the longest among the following suffixes, and, if it is in R2, perform the action indicated. - * @return boolean */ - private function step2() + private function step2(): bool { // atori itate itati, ităţi, abila abile abili abilă, ibila ibile ibili ibilă // anta, ante, anti, antă, ator, ibil, oasa oasă oase, ităi, abil @@ -262,7 +259,7 @@ private function step2() * Do step 3 if no suffix was removed either by step 1 or step 2. * @return boolean */ - private function step3() + private function step3(): ?bool { // are ere ire âre ind ând indu ându eze ească ez ezi ează esc eşti // eşte ăsc ăşti ăşte am ai au eam eai ea eaţi eau iam iai ia iaţi @@ -311,7 +308,7 @@ private function step3() /** * Step 4: Removal of final vowel */ - private function step4() + private function step4(): bool { // Search for the longest among the suffixes "a e i ie ă " and, if it is in RV, delete it. if ( $position = $this->search(['a', 'ie', 'e', 'i', 'ă']) !== false && $this->inRv($position)) { @@ -325,7 +322,7 @@ private function step4() * Finally * Turn I, U back into i, u */ - private function finish() + private function finish(): void { // Turn I, U back into i, u $this->word = str_replace(['I', 'U'], ['i', 'u'], $this->word); diff --git a/src/Stemmer/Russian.php b/src/Stemmer/Russian.php index 337d2ed..6d12cac 100644 --- a/src/Stemmer/Russian.php +++ b/src/Stemmer/Russian.php @@ -54,7 +54,7 @@ class Russian extends Stem /** * {@inheritdoc} */ - public function stem($word) + public function stem($word): string { // we do ALL in UTF-8 if (!UTF8::is_utf8($word)) { @@ -82,7 +82,7 @@ public function stem($word) * Otherwise try and remove a REFLEXIVE ending, and then search in turn for (1) an ADJECTIVAL, (2) a VERB or (3) a NOUN ending. * As soon as one of the endings (1) to (3) is found remove it, and terminate step 1. */ - private function step1() + private function step1(): bool { // Search for a PERFECTIVE GERUND ending. // group 1 @@ -138,7 +138,7 @@ private function step1() /** * Step 2: If the word ends with и (i), remove it. */ - private function step2() + private function step2(): bool { if ($position = $this->searchIfInRv(['и']) !== false && $this->inRv($position)) { $this->word = UTF8::substr($this->word, 0, $position); @@ -151,7 +151,7 @@ private function step2() * Step 3: Search for a DERIVATIONAL ending in R2 (i.e. the entire ending must lie in R2), * and if one is found, remove it. */ - private function step3() + private function step3(): ?bool { if ($position = $this->searchIfInRv(self::$derivational) !== false && $this->inR2($position)) { $this->word = UTF8::substr($this->word, 0, $position); @@ -164,7 +164,7 @@ private function step3() * Step 4: (1) Undouble н (n), or, (2) if the word ends with a SUPERLATIVE ending, remove it * and undouble н (n), or (3) if the word ends ь (') (soft sign) remove it. */ - private function step4() + private function step4(): ?bool { // (2) if the word ends with a SUPERLATIVE ending, remove it if ( ($position = $this->searchIfInRv(self::$superlative)) !== false) { @@ -188,7 +188,7 @@ private function step4() /** * In any word, RV is the region after the first vowel, or the end of the word if it contains no vowel. */ - protected function rv() + protected function rv(): bool { $length = UTF8::strlen($this->word); diff --git a/src/Stemmer/Spanish.php b/src/Stemmer/Spanish.php index 461f6b1..acd8084 100644 --- a/src/Stemmer/Spanish.php +++ b/src/Stemmer/Spanish.php @@ -20,7 +20,7 @@ class Spanish extends Stem /** * {@inheritdoc} */ - public function stem($word) + public function stem($word): string { // we do ALL in UTF-8 if (!UTF8::is_utf8($word)) { @@ -68,14 +68,14 @@ public function stem($word) * in RV. In the case of (c), yendo must lie in RV, but the preceding u can be outside it. * In the case of (a), deletion is followed by removing the acute accent (for example, haciéndola -> haciendo). */ - private function step0() + private function step0(): bool { if ( ($position = $this->searchIfInRv(['selas', 'selos', 'las', 'los', 'les', 'nos', 'selo', 'sela', 'me', 'se', 'la', 'le', 'lo' ])) != false) { $suffixe = UTF8::substr($this->word, $position); // a $a = ['iéndo', 'ándo', 'ár', 'ér', 'ír']; - $a = array_map(function($item) use ($suffixe) { + $a = array_map(function(string $item) use ($suffixe): string { return $item . $suffixe; }, $a); @@ -90,7 +90,7 @@ private function step0() // b $b = ['iendo', 'ando', 'ar', 'er', 'ir']; - $b = array_map(function($item) use ($suffixe) { + $b = array_map(function(string $item) use ($suffixe): string { return $item . $suffixe; }, $b); @@ -115,7 +115,7 @@ private function step0() /** * Step 1 */ - private function step1() + private function step1(): bool { // anza anzas ico ica icos icas ismo ismos able ables ible ibles ista // istas oso osa osos osas amiento amientos imiento imientos @@ -255,7 +255,7 @@ private function step1() /** * Step 2a: Verb suffixes beginning y */ - private function step2a() + private function step2a(): bool { // if found, delete if preceded by u // (Note that the preceding u need not be in RV.) @@ -276,7 +276,7 @@ private function step2a() * Step 2b: Other verb suffixes * Search for the longest among the following suffixes in RV, and perform the action indicated. */ - private function step2b() + private function step2b(): ?bool { // delete if ( ($position = $this->searchIfInRv([ @@ -312,7 +312,7 @@ private function step2b() * Step 3: residual suffix * Search for the longest among the following suffixes in RV, and perform the action indicated. */ - private function step3() + private function step3(): bool { // os a o á í ó // delete if in RV @@ -342,7 +342,7 @@ private function step3() * And finally: * Remove acute accents */ - private function finish() + private function finish(): void { $this->word = str_replace(['á', 'í', 'ó', 'é', 'ú'], ['a', 'i', 'o', 'e', 'u'], $this->word); } diff --git a/src/Stemmer/Stem.php b/src/Stemmer/Stem.php index 8bf24e3..11f4e29 100644 --- a/src/Stemmer/Stem.php +++ b/src/Stemmer/Stem.php @@ -132,7 +132,7 @@ protected function r2() * R1 : $in = $this->word * R2 : $in = R1 */ - protected function rx($in) + protected function rx(string $in) { $length = UTF8::strlen($in); diff --git a/src/Stemmer/Swedish.php b/src/Stemmer/Swedish.php index fd80204..a409699 100644 --- a/src/Stemmer/Swedish.php +++ b/src/Stemmer/Swedish.php @@ -20,7 +20,7 @@ class Swedish extends Stem /** * {@inheritdoc} */ - public function stem($word) + public function stem($word): string { // we do ALL in UTF-8 if (!UTF8::is_utf8($word)) { @@ -51,9 +51,8 @@ public function stem($word) * b c d f g h j k l m n o p r t v y * * @param string $ending - * @return boolean */ - private function hasValidSEnding($word) + private function hasValidSEnding(string $word): bool { $lastLetter = UTF8::substr($word, -1, 1); return in_array($lastLetter, ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 't', 'v', 'y']); @@ -63,7 +62,7 @@ private function hasValidSEnding($word) * Step 1 * Search for the longest among the following suffixes in R1, and perform the action indicated. */ - private function step1() + private function step1(): ?bool { // a arna erna heterna orna ad e ade ande arne are aste en anden aren heten // ern ar er heter or as arnas ernas ornas es ades andes ens arens hetens @@ -93,7 +92,7 @@ private function step1() * Step 2 * Search for one of the following suffixes in R1, and if found delete the last letter. */ - private function step2() + private function step2(): void { // dd gd nn dt gt kt tt if ($this->searchIfInR1(['dd', 'gd', 'nn', 'dt', 'gt', 'kt', 'tt']) !== false) { @@ -105,7 +104,7 @@ private function step2() * Step 3: * Search for the longest among the following suffixes in R1, and perform the action indicated. */ - private function step3() + private function step3(): ?bool { // lig ig els // delete diff --git a/test/CatalanTest.php b/test/CatalanTest.php index b410590..4821c2a 100644 --- a/test/CatalanTest.php +++ b/test/CatalanTest.php @@ -9,7 +9,7 @@ class CatalanTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Catalan(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/ca.txt'); } diff --git a/test/CsvFileIterator.php b/test/CsvFileIterator.php index 269e8df..241217c 100644 --- a/test/CsvFileIterator.php +++ b/test/CsvFileIterator.php @@ -20,7 +20,7 @@ public function __destruct() } #[\ReturnTypeWillChange] - public function rewind() + public function rewind(): void { rewind($this->file); //$this->current = fgetcsv($this->file, null, "\t"); @@ -52,7 +52,7 @@ public function current() } #[\ReturnTypeWillChange] - public function next() + public function next(): void { $line = fgets($this->file); $current = explode(' ', $line); diff --git a/test/DanishTest.php b/test/DanishTest.php index b846d72..4f08849 100644 --- a/test/DanishTest.php +++ b/test/DanishTest.php @@ -9,7 +9,7 @@ class DanishTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Danish(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/dk.txt'); } diff --git a/test/DutchTest.php b/test/DutchTest.php index 6e21f8c..ea51931 100644 --- a/test/DutchTest.php +++ b/test/DutchTest.php @@ -9,7 +9,7 @@ class DutchTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Dutch(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/nl.txt'); } diff --git a/test/EnglishTest.php b/test/EnglishTest.php index a38fb0f..85b617e 100644 --- a/test/EnglishTest.php +++ b/test/EnglishTest.php @@ -9,7 +9,7 @@ class EnglishTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new English(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/en.txt'); } diff --git a/test/FactoryTest.php b/test/FactoryTest.php index 44e65b2..ced8ae9 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -9,7 +9,7 @@ class FactoryTest extends TestCase { - public function testFactory() + public function testFactory(): void { $isoCodes = [ 'ca' => \Wamania\Snowball\Stemmer\Catalan::class, diff --git a/test/FinnishTest.php b/test/FinnishTest.php index 17a6c33..385d581 100644 --- a/test/FinnishTest.php +++ b/test/FinnishTest.php @@ -9,7 +9,7 @@ class FinnishTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Finnish(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/fi.txt'); } diff --git a/test/FrenchTest.php b/test/FrenchTest.php index a985d2a..69d04ad 100644 --- a/test/FrenchTest.php +++ b/test/FrenchTest.php @@ -9,7 +9,7 @@ class FrenchTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new French(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/fr.txt'); } diff --git a/test/GermanTest.php b/test/GermanTest.php index 3bec53d..9e50aba 100644 --- a/test/GermanTest.php +++ b/test/GermanTest.php @@ -9,7 +9,7 @@ class GermanTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new German(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/de.txt'); } diff --git a/test/ItalianTest.php b/test/ItalianTest.php index c77d8ac..a80d763 100644 --- a/test/ItalianTest.php +++ b/test/ItalianTest.php @@ -9,7 +9,7 @@ class ItalianTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Italian(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/it.txt'); } diff --git a/test/ManagerTest.php b/test/ManagerTest.php index 0e1586f..46a28ab 100644 --- a/test/ManagerTest.php +++ b/test/ManagerTest.php @@ -9,7 +9,7 @@ class ManagerTest extends TestCase { - public function testManager() + public function testManager(): void { $stemmerManager = new StemmerManager(); diff --git a/test/NorwegianTest.php b/test/NorwegianTest.php index 6265d58..8e33fd0 100644 --- a/test/NorwegianTest.php +++ b/test/NorwegianTest.php @@ -9,7 +9,7 @@ class NorwegianTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Norwegian(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/no.txt'); } diff --git a/test/PortugueseTest.php b/test/PortugueseTest.php index 6cf8851..6606cc1 100644 --- a/test/PortugueseTest.php +++ b/test/PortugueseTest.php @@ -9,7 +9,7 @@ class PortugueseTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Portuguese(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/pt.txt'); } diff --git a/test/RomanianTest.php b/test/RomanianTest.php index 150510b..4f86be0 100644 --- a/test/RomanianTest.php +++ b/test/RomanianTest.php @@ -9,7 +9,7 @@ class RomanianTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Romanian(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/ro.txt'); } diff --git a/test/RussianTest.php b/test/RussianTest.php index e95a6c9..eb6d58c 100644 --- a/test/RussianTest.php +++ b/test/RussianTest.php @@ -9,7 +9,7 @@ class RussianTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Russian(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/ru.txt'); } diff --git a/test/SpanishTest.php b/test/SpanishTest.php index 7b3cf40..f28d334 100644 --- a/test/SpanishTest.php +++ b/test/SpanishTest.php @@ -9,7 +9,7 @@ class SpanishTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Spanish(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/es.txt'); } diff --git a/test/SwedishTest.php b/test/SwedishTest.php index f3d1f71..98a535b 100644 --- a/test/SwedishTest.php +++ b/test/SwedishTest.php @@ -9,7 +9,7 @@ class SwedishTest extends TestCase /** * @dataProvider load */ - public function testStem($word, $stem) + public function testStem($word, $stem): void { $o = new Swedish(); @@ -18,7 +18,7 @@ public function testStem($word, $stem) $this->assertEquals($stem, $snowballStem); } - public function load() + public function load(): \Wamania\Snowball\Tests\CsvFileIterator { return new CsvFileIterator('test/files/sw.txt'); } From c0aa9fd118d463fc5bc7456abc04a21d3e84d65d Mon Sep 17 00:00:00 2001 From: Dom Morgan Date: Mon, 15 Jun 2026 14:35:40 +0100 Subject: [PATCH 4/5] Unnecessary config --- rector.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/rector.php b/rector.php index 74e5e82..ed98e17 100644 --- a/rector.php +++ b/rector.php @@ -21,6 +21,4 @@ ->withComposerBased( phpunit: true, ) - // ->withTypeCoverageLevel(100) - // ->withDeadCodeLevel(100) ; From d27fe67120e2a0d71dc267d4cb8f73890492b595 Mon Sep 17 00:00:00 2001 From: Dom Morgan Date: Mon, 15 Jun 2026 14:41:23 +0100 Subject: [PATCH 5/5] Migrate phpunit xm;l --- phpunit.xml.dist | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5c62690..1ae984c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ - + - + + + src + + test - - - - src - -