Просмотр исходного кода

Merge branch 'staging' of https://github.com/iapt-platform/mint into laravel

bhikkhu-kosalla-china 4 лет назад
Родитель
Сommit
1a812edccc

+ 146 - 0
app/Console/Commands/UpgradeWbwAnalyses.php

@@ -0,0 +1,146 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Models\Wbw;
+use App\Models\WbwAnalysis;
+
+
+class UpgradeWbwAnalyses extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'upgrade:wbwanalyses {id?}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '用户逐词解析数据填充wbw analyses表';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        $bar = $this->output->createProgressBar(Wbw::count());
+        $counter =0;
+        if(empty($this->argument('id'))){
+            $it = Wbw::orderby('id')->cursor();
+        }else{
+            $it = Wbw::where('id',$this->argument('id'))->orderby('id')->cursor();
+        }
+        
+        foreach ($it as $wbwrow) {
+            $counter++;
+            WbwAnalysis::where('wbw_id',$wbwrow->id)->delete();
+            # code...
+            $data = str_replace("&nbsp;",' ',$wbwrow->data);
+            $data = str_replace("<br>",' ',$data);
+
+            $xmlString = "<root>" . $data . "</root>";
+            try{
+                $xmlWord = simplexml_load_string($xmlString);
+            }catch(Exception $e){
+                continue;
+            }
+            
+            $wordsList = $xmlWord->xpath('//word');
+            foreach ($wordsList as $word) {
+                $pali = $word->real->__toString();
+                foreach ($word as $key => $value) {
+                    $strValue = $value->__toString();
+                    if ($strValue !== "?" && $strValue !== "" && $strValue !== ".ctl." && $strValue !== ".a." && $strValue !== " " && mb_substr($strValue, 0, 3, "UTF-8") !== "[a]" && $strValue !== "_un_auto_factormean_" && $strValue !== "_un_auto_mean_") {
+                        $iType = 0;
+                        $lang = 'pali';
+                        $newData = [
+							'wbw_id'=>$wbwrow->id,
+							'wbw_word'=>$wbwrow->word,
+							'book_id'=>$wbwrow->book_id,
+							'paragraph'=>$wbwrow->paragraph,
+							'wid'=>$wbwrow->wid,
+                            'type'=>0,
+                            'data'=>$strValue,
+                            'confidence'=>100,
+                            'lang'=>'en',
+                            'editor_id'=>$wbwrow->editor_id,
+                            'created_at'=>$wbwrow->created_at,
+                            'updated_at'=>$wbwrow->updated_at
+						];
+                        #TODO 加虚词
+                        switch ($key) {
+                            case 'type':
+                                $newData['type']=1;
+                                WbwAnalysis::insert($newData);
+                                break;
+                            case 'gramma':
+                                $newData['type']=2;
+                                WbwAnalysis::insert($newData);
+                                break;
+                            case 'mean':
+                                $newData['type']=3;
+                                WbwAnalysis::insert($newData);
+                                break;
+                            case 'org':
+                                $newData['type']=4;
+                                WbwAnalysis::insert($newData);
+                                break;
+                            case 'om':
+                                $newData['type']=5;
+                                WbwAnalysis::insert($newData);
+                                break;
+                            case 'parent':
+                                $newData['type']=6;
+                                WbwAnalysis::insert($newData);
+                                break;
+                            case 'rela':
+                            /*
+                            <rela>[{"sour_id":"p199-764-6","sour_spell":"dhammacakkappavattanatthaṃ","dest_id":"p199-764-8","dest_spell":"āmantanā","relation":"ADV","note":""}]</rela>
+                            */
+                                $newData['type']=7;
+                                $rlt = json_decode($strValue);
+                                foreach ($rlt as $rltValue) {
+                                    # code...
+                                    if(!empty($rltValue->relation)){
+                                        $newData['data'] = $rltValue->relation;
+                                        if(isset($word->gramma) && !empty($word->gramma)){
+                                            $grm = explode('$',$word->gramma);
+                                            if(count($grm)>0){
+                                                $newData['d1'] = $grm[count($grm)-1];
+                                            }else{
+                                                $newData['d1'] = $word->type;
+                                            }
+                                        }
+                                        $newData['d2'] = (int)(explode('-',$rltValue->dest_id)[2]) - (int)(explode('-',$rltValue->sour_id)[2]) ;
+                                        WbwAnalysis::insert($newData);
+                                    }
+                                }
+                                break;
+                        }
+                    }
+                }
+            }
+            $bar->advance();
+        }
+        $bar->finish();
+        $this->info("wbw analyses finished");
+        return 0;
+    }
+}

+ 92 - 0
app/Http/Controllers/AnalysisController.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\WbwAnalysis;
+use Illuminate\Http\Request;
+
+class AnalysisController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+        $result = WbwAnalysis::selectRaw('d1, data ,count(*) as ct')
+                             ->where('type',7)
+                             ->groupby('d1')
+                             ->groupby('data')
+                             ->orderbyRaw('d1,ct desc')
+                             ->get();
+        return view('wbwanalyses',['data'=>$result]);
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\WbwAnalysis  $wbwAnalysis
+     * @return \Illuminate\Http\Response
+     */
+    public function show(WbwAnalysis $wbwAnalysis)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Models\WbwAnalysis  $wbwAnalysis
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(WbwAnalysis $wbwAnalysis)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Models\WbwAnalysis  $wbwAnalysis
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, WbwAnalysis $wbwAnalysis)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\WbwAnalysis  $wbwAnalysis
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(WbwAnalysis $wbwAnalysis)
+    {
+        //
+    }
+}

+ 71 - 0
app/Http/Controllers/WbwAnalysisController.php

@@ -0,0 +1,71 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\WbwAnalysis;
+use Illuminate\Http\Request;
+
+class WbwAnalysisController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *select d1, data ,count(*) as ct from wbw_analyses where type = 7  group by d1,data order by d1,ct desc 
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+        $result = WbwAnalysis::selectRaw('d1, data ,count(*) as ct')
+                             ->where('type',7)
+                             ->groupby('d1')
+                             ->groupby('data')
+                             ->orderbyRaw('d1,ct desc')
+                             ->get();
+        return view('wbwanalyses',['data'=>$result]);
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\WbwAnalysis  $wbwAnalysis
+     * @return \Illuminate\Http\Response
+     */
+    public function show(WbwAnalysis $wbwAnalysis)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Models\WbwAnalysis  $wbwAnalysis
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, WbwAnalysis $wbwAnalysis)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\WbwAnalysis  $wbwAnalysis
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(WbwAnalysis $wbwAnalysis)
+    {
+        //
+    }
+}

+ 11 - 0
app/Models/WbwAnalysis.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class WbwAnalysis extends Model
+{
+    use HasFactory;
+}

+ 59 - 0
database/migrations/2022_02_07_012707_create_wbw_analyses_table.php

@@ -0,0 +1,59 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateWbwAnalysesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     
+     * @return void
+     */
+     /*
+     'userid',
+                            'pali',
+                            'book',
+                            'paragraph',
+                            'wid',
+                            'type',
+                            'data',
+                            'confidence',
+                            'lang',
+                            'modify_time')
+     */
+    public function up()
+    {
+        Schema::create('wbw_analyses', function (Blueprint $table) {
+            $table->id();
+            $table->bigInteger('wbw_id')->index();
+            $table->string('wbw_word',1024);
+            $table->integer('book_id');
+            $table->integer('paragraph');
+            $table->integer('wid');
+            $table->integer('type');
+            $table->text('data')->index();
+            $table->integer('confidence');
+            $table->string('lang',16);
+            $table->text('d1')->nullable()->index();//备用数据
+            $table->text('d2')->nullable()->index();//备用数据
+            $table->text('d3')->nullable()->index();//备用数据
+            $table->bigInteger('editor_id');
+            $table->timestamps();
+
+            $table->index(['type','data']);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('wbw_analyses');
+    }
+}

+ 19 - 0
resources/views/wbwanalyses.blade.php

@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+    <body>
+        <h1>逐词解析数据分析</h1>
+        <table>
+        @foreach($data as $row)
+        <tr>
+        <td>{{ $row->d1 }}</td>
+        <td>{{ $row->data }}</td>
+        <td style='width:500px;'><span style='display:inline-block;width:{{ $row->ct }}px;background-color:green;'>{{ $row->ct }}</span></td>
+        </tr>
+        @endforeach
+        </table>
+
+        <script>
+        var app = @json($data);
+        </script>
+    </body>
+</html>

+ 4 - 2
routes/web.php

@@ -1,7 +1,7 @@
 <?php
 
 use Illuminate\Support\Facades\Route;
-
+use App\Http\Controllers\WbwAnalysisController;
 /*
 |--------------------------------------------------------------------------
 | Web Routes
@@ -23,4 +23,6 @@ Route::get('/user/{id}', function ($id) {
 
 Route::get('/home/{name}', function ($name) {
     return view('home', ['name' => $name]);
-});
+});
+
+Route::get('/wbwanalyses', [WbwAnalysisController::class,'index']);