maxodrom/yii2-phpmorphy
Composer 安装命令:
composer create-project maxodrom/yii2-phpmorphy
包简介
Yii2 PHPMorphy component
README 文档
README
Wrapper for package maxakawizard/phpmorphy and ported to Yii2 component base.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require maxodrom/yii2-phpmorphy:~1.0
or add
"maxodrom/yii2-phpmorphy": "~1.0"
to the require section of your composer.json.
Usage
Define new component in your Yii2 application config (@app/config/web.php)
$config = [ 'id' => 'app-frontend', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'language' => 'ru-RU', 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'components' => [ 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => '', ], 'cache' => [ 'class' => 'yii\caching\FileCache', ], 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true, ], 'db' => $db, /** * Set component here! */ 'yiimorphy' => [ 'class' => 'maxodrom\phpmorphy\components\YiiMorphy', // 'language' => 'ru', // or 'uk', or 'de' // 'options' => [], // your options which will be passed to \phpMorphy's constructor ], ], 'modules' => [], 'params' => $params, ];
In your code you can use component via standard way:
/** @var \phpMorphy $morphy */ $morphy = Yii::$app->yiimorphy->morphy; $word_one = 'КОТ'; $word_two = 'СОБАКА'; try { // word by word processing // each function return array with result or FALSE when no form(s) for given word found(or predicted) $base_form = $morphy->getBaseForm($word_one); $all_forms = $morphy->getAllForms($word_one); $pseudo_root = $morphy->getPseudoRoot($word_one); if(false === $base_form || false === $all_forms || false === $pseudo_root) { die("Can`t find or predict $word_one word"); } echo 'base form = ' . implode(', ', $base_form) . "\n"; echo 'all forms = ' . implode(', ', $all_forms) . "\n"; echo "Testing bulk mode...\n"; // bulk mode speed-ups processing up to 50-100%(mainly for getBaseForm method) // in bulk mode all function always return array $bulk_words = array($word_one, $word_two); $base_form = $morphy->getBaseForm($bulk_words); $all_forms = $morphy->getAllForms($bulk_words); $pseudo_root = $morphy->getPseudoRoot($bulk_words); // Bulk result format: // array( // INPUT_WORD1 => array(OUTWORD1, OUTWORD2, ... etc) // INPUT_WORD2 => FALSE <-- when no form for word found(or predicted) // ) echo 'bulk mode base form = ' . implode(', ', $base_form[$word_one]) . ' ' . implode(', ', $base_form[$word_two]) . "\n"; echo 'bulk mode all forms = ' . implode(', ', $all_forms[$word_one]) . ' ' . implode(', ', $all_forms[$word_two]) . "\n"; // You can also retrieve all word forms with graminfo via getAllFormsWithGramInfo method call // $all_forms_with_gram = $morphy->getAllFormsWithGramInfo($word_one); exit; } catch(\phpMorphy_Exception $e) { die('Error occured while text processing: ' . $e->getMessage()); }
maxodrom/yii2-phpmorphy 适用场景与选型建议
maxodrom/yii2-phpmorphy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.77k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 06 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「seo」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maxodrom/yii2-phpmorphy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maxodrom/yii2-phpmorphy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maxodrom/yii2-phpmorphy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
Help to manage meta data on Laravel Eloquent model
Statamic Fine Seo addon
SCEditor, a lightweight WYSIWYG BBCode & HTML editor extension for Yii 2.0 Framework
Redirect all not authenticated web user to login page.
Magento - Force store code extension
统计信息
- 总下载量: 3.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-07