Browse Source

:bug: 删除旧数据没有判断字典id

visuddhinanda 3 years ago
parent
commit
4e58b99ec8
2 changed files with 25 additions and 14 deletions
  1. 19 11
      app/Console/Commands/UpgradeCompound.php
  2. 6 3
      app/Console/Commands/UpgradeRegular.php

+ 19 - 11
app/Console/Commands/UpgradeCompound.php

@@ -26,6 +26,9 @@ class UpgradeCompound extends Command
      */
     protected $description = 'Command description';
 
+	protected $dict_id = 'c42980f0-5967-4833-b695-84183344f68f';
+
+
     /**
      * Create a new command instance.
      *
@@ -43,11 +46,12 @@ class UpgradeCompound extends Command
      */
     public function handle()
     {
-		$ts = new TurboSplit();
+		
 		$start = \microtime(true);
 
 		$_word = $this->argument('word');
 		if(!empty($_word)){
+			$ts = new TurboSplit();
 			var_dump($ts->splitA($_word));
 			return 0;
 		}
@@ -69,7 +73,6 @@ class UpgradeCompound extends Command
 				foreach ($words as $word) {
 					$this->info($word->word);
 					Storage::disk('local')->append("tmp/compound.md", "## {$word->word}");
-
 					$parts = $ts->splitA($word->word);
 					foreach ($parts as $part) {
 						# code...
@@ -82,20 +85,21 @@ class UpgradeCompound extends Command
 			return 0;	
 		}
 
-		$words = WbwTemplate::select('real')->where('type','<>','.ctl.')->where('real','<>','')->groupBy('real')->cursor();
+		$words = WordIndex::where('final',0)->select('word')->orderBy('count','desc')->skip(72300)->cursor();
+		//$words = WbwTemplate::select('real')->where('type','<>','.ctl.')->where('real','<>','')->groupBy('real')->cursor();
 		$count = 0;
 		foreach ($words as $key => $word) {
 			# code...
 			$count++;
-			$this->info("{$count}:{$word->real}");
-			$parts = $ts->splitA($word->real);
+			$this->info("{$count}:{$word->word}"); 
+			$ts = new TurboSplit();
+			$parts = $ts->splitA($word->word);
 			foreach ($parts as $part) {
 				$new = UserDict::firstOrNew(
 					[
 						'word' => $part['word'],
-						'type' => ".cp.",
 						'factors' => $part['factors'],
-						'dict_id' => 'c42980f0-5967-4833-b695-84183344f68f'
+						'dict_id' => $dict_id,
 					],
 					[
 						'id' => app('snowflake')->id(),
@@ -103,17 +107,21 @@ class UpgradeCompound extends Command
 						'create_time'=>(int)(microtime(true)*1000),
 					]
 				);
-				$new->confidence = 50;
+				if(isset($part['type'])){
+					$new->type = $part['type'];
+				}else{
+					$new->type = ".cp.";
+				}
+				$new->confidence = (int)(50*$part['confidence']);
 				$new->language = 'cm';
 				$new->creator_id = 1;
 				$new->flag = 1;
 				$new->save();
-
 			}
 		}
 		//删除旧数据
-		UserDict::where('flag',0)->delete();
-		UserDict::where('flag',1)->update(['flag'=>0]);
+		UserDict::where('dict_id',$dict_id)->where('flag',0)->delete();
+		UserDict::where('dict_id',$dict_id)->where('flag',1)->update(['flag'=>0]);
 	
         return 0;
     }

+ 6 - 3
app/Console/Commands/UpgradeRegular.php

@@ -24,7 +24,7 @@ class UpgradeRegular extends Command
      * @var string
      */
     protected $description = 'Command description';
-
+	protected $dict_id = '57afac99-0887-455c-b18e-67c8682158b0';
     /**
      * Create a new command instance.
      *
@@ -167,7 +167,6 @@ class UpgradeRegular extends Command
 						return WbwTemplate::where('real',$newword)->exists();
 					});
 					if($exist){
-						//$this->info("{$newword} exists");
 						$new = UserDict::firstOrNew(
 							[
 								'word' => $newword,
@@ -175,7 +174,7 @@ class UpgradeRegular extends Command
 								'grammar' => $newGrammar,
 								'parent' => $word->word,
 								'factors' => "{$word->word}+[{$newEnding}]",
-								'dict_id' => '57afac99-0887-455c-b18e-67c8682158b0'
+								'dict_id' => $this->dict_id,
 							],
 							[
 								'id' => app('snowflake')->id(),
@@ -186,6 +185,7 @@ class UpgradeRegular extends Command
 						$new->confidence = 80;
 						$new->language = 'cm';
 						$new->creator_id = 1;
+						$new->flag = 1;
 						$new->save();
 					}
 				}
@@ -193,6 +193,9 @@ class UpgradeRegular extends Command
 			$bar->advance();
 		}
 		$bar->finish();
+				//删除旧数据
+		UserDict::where('dict_id',$this->dict_id)->where('flag',0)->delete();
+		UserDict::where('dict_id',$this->dict_id)->where('flag',1)->update(['flag'=>0]);
         return 0;
     }
 }