visuddhinanda 3 vuotta sitten
vanhempi
sitoutus
add7ba2784

+ 92 - 0
app/Console/Commands/InitSystemDict.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\DictInfo;
+use Illuminate\Console\Command;
+
+class InitSystemDict extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'init:system.dict';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'create system dict. like sys_regular  ect.';
+
+    /**
+     * name 不要修改。因为在程序其他地方,用name 查询词典id
+     */
+    protected $dictionary =[
+        [
+            "name"=>'robot_compound',
+            'shortname'=>'compound',
+            'description'=>'split compound by AI',
+            'src_lang'=>'pa',
+            'dest_lang'=>'cm',
+        ],
+        [
+            "name"=>'system_regular',
+            'shortname'=>'regular',
+            'description'=>'system regular',
+            'src_lang'=>'pa',
+            'dest_lang'=>'cm',
+        ],
+        [
+            "name"=>'community',
+            'shortname'=>'社区',
+            'description'=>'由用户贡献词条的社区字典',
+            'src_lang'=>'pa',
+            'dest_lang'=>'cm',
+        ],
+        [
+            "name"=>'community_extract',
+            'shortname'=>'社区汇总',
+            'description'=>'由用户贡献词条的社区字典汇总统计',
+            'src_lang'=>'pa',
+            'dest_lang'=>'cm',
+        ],
+    ];
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        $this->info("start");
+        foreach ($this->dictionary as $key => $value) {
+            # code...
+            $channel = DictInfo::firstOrNew([
+                'name' => $value['name'],
+                'owner_id' => config("app.admin.root_uuid"),
+            ]);
+            $channel->shortname = $value['shortname'];
+            $channel->description = $value['description'];
+            $channel->src_lang = $value['src_lang'];
+            $channel->dest_lang = $value['dest_lang'];
+            $channel->meta = json_encode($value,JSON_UNESCAPED_UNICODE);
+            $channel->save();
+            $this->info("updated {$value['name']}");
+        }
+        return 0;
+    }
+}

+ 16 - 0
app/Http/Api/DictApi.php

@@ -0,0 +1,16 @@
+<?php
+namespace App\Http\Api;
+use App\Models\DictInfo;
+
+class DictApi{
+    public static function getSysDict($name){
+        $dict_info=  DictInfo::where('name',$name)
+                    ->where('owner_id',config("app.admin.root_uuid"))
+                    ->first();
+        if(!$dict_info){
+            return false;
+        }else{
+            return $dict_info->id;
+        }
+    }
+}

+ 34 - 0
database/migrations/2023_02_17_025306_change_confidence_in_user_dicts.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeConfidenceInUserDicts extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('user_dicts', function (Blueprint $table) {
+            //
+            $table->float('confidence')->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('user_dicts', function (Blueprint $table) {
+            //
+            $table->integer('confidence')->change();
+        });
+    }
+}