|
|
@@ -1,5 +1,9 @@
|
|
|
<?php
|
|
|
-
|
|
|
+/**
|
|
|
+ * 生成系统规则变形词典
|
|
|
+ * 算法: 扫描字典里的所有单词。根据语尾表变形。
|
|
|
+ * 并在词库中查找是否在三藏中出现。出现的保存。
|
|
|
+ */
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
use App\Models\UserDict;
|
|
|
@@ -8,6 +12,7 @@ use Illuminate\Console\Command;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
+use App\Http\Api\DictApi;
|
|
|
|
|
|
class UpgradeRegular extends Command
|
|
|
{
|
|
|
@@ -23,8 +28,7 @@ class UpgradeRegular extends Command
|
|
|
*
|
|
|
* @var string
|
|
|
*/
|
|
|
- protected $description = 'Command description';
|
|
|
- protected $dict_id = '57afac99-0887-455c-b18e-67c8682158b0';
|
|
|
+ protected $description = 'upgrade regular';
|
|
|
/**
|
|
|
* Create a new command instance.
|
|
|
*
|
|
|
@@ -42,6 +46,11 @@ class UpgradeRegular extends Command
|
|
|
*/
|
|
|
public function handle()
|
|
|
{
|
|
|
+ $dict_id = DictApi::getSysDict('system_regular');
|
|
|
+ if(!$dict_id){
|
|
|
+ $this->error('没有找到 system_regular 字典');
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
$nounEnding = array();
|
|
|
$rowCount=0;
|
|
|
if(($handle=fopen(public_path('app/public/ending/noun.csv'),'r'))!==FALSE){
|
|
|
@@ -79,7 +88,7 @@ class UpgradeRegular extends Command
|
|
|
$words = UserDict::where('type','.n:base.')
|
|
|
->orWhere('type','.v:base.')
|
|
|
->orWhere('type','.adj:base.')
|
|
|
- ->orWhere('type','.ti:base.');
|
|
|
+ ->orWhere('type','.ti:base.');
|
|
|
}else{
|
|
|
$words = UserDict::where('word',$this->argument('word'))
|
|
|
->where(function($query) {
|
|
|
@@ -87,16 +96,16 @@ class UpgradeRegular extends Command
|
|
|
->orWhere('type','.v:base.')
|
|
|
->orWhere('type','.adj:base.')
|
|
|
->orWhere('type','.ti:base.');
|
|
|
- });
|
|
|
+ });
|
|
|
}
|
|
|
$words = $words->select(['word','type','grammar'])
|
|
|
->groupBy(['word','type','grammar'])
|
|
|
->orderBy('word');
|
|
|
$query = "
|
|
|
- select count(*) from (select count(*) from user_dicts ud where
|
|
|
- \"type\" = '.v:base.' or
|
|
|
- \"type\" = '.n:base.' or
|
|
|
- \"type\" = '.ti:base.' or
|
|
|
+ select count(*) from (select count(*) from user_dicts ud where
|
|
|
+ \"type\" = '.v:base.' or
|
|
|
+ \"type\" = '.n:base.' or
|
|
|
+ \"type\" = '.ti:base.' or
|
|
|
\"type\" = '.adj:base.'
|
|
|
group by word,type,grammar) as t;
|
|
|
";
|
|
|
@@ -148,7 +157,7 @@ class UpgradeRegular extends Command
|
|
|
$head = mb_substr($word->word,0,(0-$endLen),"UTF-8");//原词剩余的部分
|
|
|
$newEnding = $thiscase[3];
|
|
|
$newGrammar = $thiscase[4];
|
|
|
- $newword=$head.$thiscase[2];
|
|
|
+ $newword=$head.$thiscase[2];
|
|
|
if($word->type==".n:base."){
|
|
|
//名词
|
|
|
if($thiscase[0]==$word->grammar && $thiscase[1]==$end){
|
|
|
@@ -156,7 +165,7 @@ class UpgradeRegular extends Command
|
|
|
$isMatch = true;
|
|
|
}else{
|
|
|
$isMatch = false;
|
|
|
- }
|
|
|
+ }
|
|
|
}else{
|
|
|
//形容词
|
|
|
if($thiscase[1]==$end){
|
|
|
@@ -164,7 +173,7 @@ class UpgradeRegular extends Command
|
|
|
$isMatch = true;
|
|
|
}else{
|
|
|
$isMatch = false;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -184,7 +193,7 @@ class UpgradeRegular extends Command
|
|
|
'grammar' => $newGrammar,
|
|
|
'parent' => $word->word,
|
|
|
'factors' => "{$word->word}+[{$newEnding}]",
|
|
|
- 'dict_id' => $this->dict_id,
|
|
|
+ 'dict_id' => $dict_id,
|
|
|
],
|
|
|
[
|
|
|
'id' => app('snowflake')->id(),
|
|
|
@@ -206,7 +215,7 @@ class UpgradeRegular extends Command
|
|
|
}
|
|
|
$bar->finish();
|
|
|
//删除旧数据
|
|
|
- $delOld = UserDict::where('dict_id',$this->dict_id);
|
|
|
+ $delOld = UserDict::where('dict_id',$dict_id);
|
|
|
if(!empty($this->argument('word'))){
|
|
|
$delOld = $delOld->where('word',$this->argument('word'));
|
|
|
}
|