[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
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 7 additions and 1 deletions

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;
} }
} }