/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
backend/controllers/data/user/GlossaryController.php
163 строки
4 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace backend\controllers\data\user; use backend\assets\GlossaryAsset; use common\controllers\base\ParentCrudController; use common\helpers\ArrayHelper; use common\helpers\FileHelper; use common\helpers\GlossaryHelper; use common\helpers\LanguageHelper; use common\helpers\NumHelper; use common\kdf\KSystem; use common\models\Glossary; use common\shell\Commands\Builder; use common\shell\Runners\Exec; use common\shell\Runners\ResultCode; use common\shell\Runners\ReturnValue; use common\shell\Runners\StandardError; use common\shell\Runners\StandardOut; use Yii; use yii\helpers\Json; use yii\helpers\VarDumper; use yii\web\NotFoundHttpException; /** * Контроллер для работы с глоссарием пользователя * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2025 */ class GlossaryController extends ParentCrudController { /** * @inheritdoc */ protected $modelClassPath = 'backend\components\crud\user\glossary'; /** * @inheritdoc */ protected $classPrefix = 'Glossary'; /** * @inheritdoc */ protected $parentModelName = 'common\models\User'; /** * @inheritdoc */ protected $relationKey = ['user_id' => 'id']; /** * Получить глоссарий в виде JSONL * @param $id * @return \yii\web\Response * @throws \yii\base\InvalidConfigException */ public function actionJsonl($id) { Yii::$app->request->validateSig(); /** @var Glossary $glossary */ $glossary = Glossary::find() ->andWhere([ 'id' => $id ]) ->one(); if (!$glossary) { throw new NotFoundHttpException(Yii::t('app', 'Glossary not found')); } $attachmentName = Yii::t('app', '{0} ({1} - {2}).jsonl', [ $glossary->name, LanguageHelper::getLanguageCode($glossary->source_language_id, KSystem::Code3), LanguageHelper::getLanguageCode($glossary->target_language_id, KSystem::Code3) ]); $this->response->sendContentAsFile($glossary->toJsonl(), $attachmentName); } /** * Проверка текста и глоссария * * @param $id * @return string * @throws NotFoundHttpException * @throws \yii\base\InvalidConfigException */ public function actionAnalysis($id) { /** @var Glossary $glossary */ $glossary = Glossary::find() ->andWhere([ 'id' => $id ]) ->one(); if (!$glossary) { throw new NotFoundHttpException(Yii::t('app', 'Glossary not found')); } $view = Yii::$app->view; $view->title = Yii::t('app', 'Analysis Glossary'); $breadcrumbs[] = [ 'label' => $view->title, ]; $view->params['breadcrumbs'] = $breadcrumbs; GlossaryAsset::register($view); return $this->render('@backend/views/data/user/check_text.twig', [ 'glossary' => $glossary ]); } /** * Проверка текста и глоссария * * @return \yii\web\Response * @throws NotFoundHttpException * @throws \yii\base\InvalidConfigException */ public function actionDoAnalysis($id) { $text = Yii::$app->request->post('request_text'); /** @var Glossary $glossary */ $glossary = Glossary::find() ->andWhere([ 'id' => $id ]) ->one(); if (!$glossary) { throw new NotFoundHttpException(Yii::t('app', 'Glossary not found')); } $data = GlossaryHelper::doAnalysis($text, $glossary); $is_ok = $data['is_ok']; $table = []; if ($is_ok) { $index = 1; foreach ($data['raw'] as $row) { $table[] = [ $index, $row['term'], NumHelper::toString($row['score'], 2), ]; $index++; } } return $this->asJson([ 'is_ok' => $is_ok, 'message' => $data['message'], 'table' => array_values($table) ]); } }