[PLUGIN][StemWord] Remove the country part from the code. Ignore if no stemmer is found for the given language

This commit is contained in:
Hugo Sales 2021-12-08 21:50:26 +00:00
parent 659ea5cd1f
commit 26b95fae96
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -25,13 +25,19 @@ namespace Plugin\StemWord;
use App\Core\Event; use App\Core\Event;
use App\Core\Modules\Plugin; use App\Core\Modules\Plugin;
use Wamania\Snowball\NotFoundException;
use Wamania\Snowball\StemmerFactory; use Wamania\Snowball\StemmerFactory;
class StemWord extends Plugin class StemWord extends Plugin
{ {
public function onStemWord(string $language, string $word, ?string &$out) public function onStemWord(string $language, string $word, ?string &$out)
{ {
$out = StemmerFactory::create($language)->stem($word); $language = explode('_', $language)[0];
try {
$out = StemmerFactory::create($language)->stem($word);
} catch (NotFoundException) {
return Event::next;
}
return Event::stop; return Event::stop;
} }
} }