Explorar el Código

:art: formatting

visuddhinanda hace 1 año
padre
commit
13d454e507
Se han modificado 1 ficheros con 34 adiciones y 34 borrados
  1. 34 34
      api-v8/app/Console/Commands/ExportFtsPali.php

+ 34 - 34
api-v8/app/Console/Commands/ExportFtsPali.php

@@ -6,6 +6,7 @@ use Illuminate\Console\Command;
 use App\Http\Api\DictApi;
 use App\Models\UserDict;
 use Illuminate\Support\Facades\Redis;
+use Illuminate\Support\Facades\Log;
 
 class ExportFtsPali extends Command
 {
@@ -42,14 +43,14 @@ class ExportFtsPali extends Command
     {
         //irregular
         $dictId = ['4d3a0d92-0adc-4052-80f5-512a2603d0e8'];
-         //regular
+        //regular
         $dictId[] = DictApi::getSysDict('system_regular');
-        $long = ["ā","ī","ū"];
+        $long = ["ā", "ī", "ū"];
         $path = storage_path('app/export/fts');
-        if(!is_dir($path)){
-            $res = mkdir($path,0700,true);
-            if(!$res){
-                Log::error('mkdir fail path='.$exportDir);
+        if (!is_dir($path)) {
+            $res = mkdir($path, 0700, true);
+            if (!$res) {
+                Log::error('mkdir fail path=' . $path);
                 return 1;
             }
         }
@@ -57,47 +58,46 @@ class ExportFtsPali extends Command
         $pageSize = 10000;
         $currPage = 1;
         $filename = "/pali-{$currPage}.syn";
-        $fp = fopen($path.$filename,'w') or die("Unable to open file!");
+        $fp = fopen($path . $filename, 'w') or die("Unable to open file!");
         $count = 0;
         foreach ($dictId as $key => $value) {
-            $words = UserDict::where('dict_id',$value)
-                             ->select('word')
-                             ->groupBy('word')->cursor();
-            $this->info('word count='.count($words));
+            $words = UserDict::where('dict_id', $value)
+                ->select('word')
+                ->groupBy('word')->cursor();
+            $this->info('word count=' . count($words));
             foreach ($words as $key => $word) {
                 $count++;
-                if($count % 1000 === 0){
+                if ($count % 1000 === 0) {
                     $this->info($count);
                 }
-                if($count % 10000 === 0){
+                if ($count % 10000 === 0) {
                     fclose($fp);
-                    $redisKey = 'export/fts/pali'.$filename;
-                    $content = file_get_contents($path.$filename);
-                    Redis::set($redisKey,$content);
-                    Redis::expire($redisKey,3600*24*10);
+                    $redisKey = 'export/fts/pali' . $filename;
+                    $content = file_get_contents($path . $filename);
+                    Redis::set($redisKey, $content);
+                    Redis::expire($redisKey, 3600 * 24 * 10);
                     $currPage++;
                     $filename = "/pali-{$currPage}.syn";
-                    $this->info('new file filename='.$filename);
-                    $fp = fopen($path.$filename,'w') or die("Unable to open file!");
+                    $this->info('new file filename=' . $filename);
+                    $fp = fopen($path . $filename, 'w') or die("Unable to open file!");
                 }
-                $parent = UserDict::where('dict_id',$value)
-                             ->where('word',$word->word)
-                             ->selectRaw('parent,char_length("parent")')
-                             ->groupBy('parent')->orderBy('char_length','asc')->first();
+                $parent = UserDict::where('dict_id', $value)
+                    ->where('word', $word->word)
+                    ->selectRaw('parent,char_length("parent")')
+                    ->groupBy('parent')->orderBy('char_length', 'asc')->first();
 
-                if($parent && !empty($parent->parent)){
-                    $end = mb_substr($parent->parent,-1,null,"UTF-8");
-                    if(in_array($end,["ā","ī","ū"])){
-                        $head = mb_substr($parent->parent,0,mb_strlen($parent->parent)-1,"UTF-8");
-                        $newEnd = str_replace(["ā","ī","ū"],["a","i","u"],$end);
-                        $parentWord = $head.$newEnd;
-
-                    }else{
+                if ($parent && !empty($parent->parent)) {
+                    $end = mb_substr($parent->parent, -1, null, "UTF-8");
+                    if (in_array($end, ["ā", "ī", "ū"])) {
+                        $head = mb_substr($parent->parent, 0, mb_strlen($parent->parent) - 1, "UTF-8");
+                        $newEnd = str_replace(["ā", "ī", "ū"], ["a", "i", "u"], $end);
+                        $parentWord = $head . $newEnd;
+                    } else {
                         $parentWord = $parent->parent;
                     }
-                    fwrite($fp, $word->word.' '.$parentWord.PHP_EOL);
-                }else{
-                    $this->error('word no parent word='.$word->word);
+                    fwrite($fp, $word->word . ' ' . $parentWord . PHP_EOL);
+                } else {
+                    $this->error('word no parent word=' . $word->word);
                 }
             }
         }