laravel-phpmorphy
is a Laravel wrapper for phpMorphy library with PHP7 support.
phpMorphy is a morphological analyzer library for Russian, Ukrainian, English and German languages.
Run the following command from your terminal:
composer require seoservice2020/laravel-phpmorphy
Or add this to require section in your composer.json
file:
{
"require": {
"seoservice2020/laravel-phpmorphy": "~2.2"
}
}
then run composer update
The defaults are set in config/morphy.php
. Copy this file to your own config directory to modify the values. You can publish the config using this command:
php artisan vendor:publish --provider="SEOService2020\Morphy\MorphyServiceProvider"
This is the contents of the published file:
return [
'common_options' => [
'storage' => phpMorphy::STORAGE_FILE,
'predict_by_suffix' => true,
'predict_by_db' => true,
'graminfo_as_text' => true,
],
'morphies' => [
[
// phpMorphy instance name
// specific morphy can be accessed through Morphy::morphy($name) method
'name' => SEOService2020\Morphy\Morphy::russianLang,
// phpMorphy language
// see Morphy class for available values
'language' => SEOService2020\Morphy\Morphy::russianLang,
// phpMorphy options
// if not specified or null specified, default options will be used
// to use common options from this config, specify []
'options' => [],
// dicts directory path
// if not specified or null specified, default dicts path will be used
'dicts_path' => null,
// values are 'storage', 'filesystem'
// 'storage': dicts will be taken from laravel storage (storage/app folder)
// 'filesystem': dicts will be taken by specified path as-is
// must be specified when dicts_path is not null
'dicts_storage' => 'storage',
],
],
];
Wrapper automatically prepares input word for phpMorphy: it applies trim
to word and converts it to uppercase or lowercase, depending on the dictionary options.
Using the wrapper directly:
use SEOService2020\Morphy\Morphy;
$morphy = new Morphy(Morphy::englishLang);
echo $morphy->getPseudoRoot('fighty');
Or via Laravel Facade:
use SEOService2020\Morphy\Facade\Morphy as Morphies;
// first parameter is the name of morphy in config
Morphies::getPseudoRoot('ru', 'Бойцовый');
// get morphy and call methods in regular manner
Morphies::morphy('ru')->lemmatize(' бойцовый'); // word will be trimmed
// get all morphies, returns array like ['name' => Morphy]
Morphies::morphies();
// get all morphies with specific locale, returns array like ['name' => Morphy]
Morphies::morphies(Morphy::russianLang);
// you can call phpMorphy static methods as well
Morphies::getDefaultDictsDir();
Note:
You can access morphy properties only directly from morphy object, not facade.
This package allows Laravel to support facade out of the box, but you may explicitly add facade support to config/app.php:
Section providers
SEOService2020\Morphy\MorphyServiceProvider::class,
Section aliases
'Morphy' => SEOService2020\Morphy\Facade\Morphy::class,
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email sergotail@mail.ru instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.