$value) { $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){ $this->info($count); } $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{ $parentWord = $parent->parent; } fwrite($fp, $word->word.' '.$parentWord.PHP_EOL); }else{ $this->error('word no parent word='.$word->word); } } } fclose($fp); return 0; } }