seoservice2020 / laravel-phpmorphy
laravel-phpmorphy - Laravel 的 phpMorphy 库包装器。
2.2.1
2021-01-31 05:18 UTC
Requires
- php: ^7.2
- illuminate/support: ^7.0|^8.0
- seoservice2020/phpmorphy: ^2.2.2
README
laravel-phpmorphy
是一个支持 PHP7 的 phpMorphy 库的 Laravel 包装器。
phpMorphy 是一个用于俄语、乌克兰语、英语和德语的语言形态分析库。
安装
在您的终端运行以下命令
composer require seoservice2020/laravel-phpmorphy
或者将此添加到您的 composer.json
文件的 require 部分
{ "require": { "seoservice2020/laravel-phpmorphy": "~2.2" } }
然后运行 composer update
配置
默认设置在 config/morphy.php
中。将此文件复制到您的配置目录以修改值。您可以使用以下命令发布配置
php artisan vendor:publish --provider="SEOService2020\Morphy\MorphyServiceProvider"
这是已发布文件的 内容
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', ], ], ];
使用方法
包装器会自动准备输入单词以供 phpMorphy 使用:它会对单词应用 trim
并将其转换为大写或小写,具体取决于字典选项。
直接使用包装器
use SEOService2020\Morphy\Morphy; $morphy = new Morphy(Morphy::englishLang); echo $morphy->getPseudoRoot('fighty');
或者通过 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();
注意
您只能直接从 morphy 对象访问 morphy 属性,而不能从 facade 访问。
添加 facade 支持
此包允许 Laravel 默认支持 facade,但您也可以显式地将 facade 支持添加到 config/app.php
部分 providers
SEOService2020\Morphy\MorphyServiceProvider::class,
部分 aliases
'Morphy' => SEOService2020\Morphy\Facade\Morphy::class,
变更日志
请参阅 CHANGELOG 以获取更多信息。
贡献
请参阅 CONTRIBUTING 以获取详细信息。
安全
如果您发现任何安全问题,请通过电子邮件 sergotail@mail.ru 报告,而不是使用问题跟踪器。
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。