|
|
@@ -5,6 +5,8 @@ namespace App\Http\Controllers;
|
|
|
use App\Models\UserDict;
|
|
|
use App\Models\DictInfo;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use App\Tools\CaseMan;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
require_once __DIR__."/../../../public/app/dict/grm_abbr.php";
|
|
|
|
|
|
@@ -24,46 +26,75 @@ class DictController extends Controller
|
|
|
$dictListOutput = [];
|
|
|
$caseListOutput = [];
|
|
|
$indexCol = ['word','note','dict_id'];
|
|
|
-
|
|
|
- $word = $request->get('word');
|
|
|
- $result = UserDict::select($indexCol)->where('word',$word)->where('source','_PAPER_')->get();
|
|
|
- $anchor = $word;
|
|
|
- $wordData=[
|
|
|
- 'word'=> $word,
|
|
|
- 'factors'=> "",
|
|
|
- 'parents'=> "",
|
|
|
- 'case'=> [],
|
|
|
- 'anchor'=> $anchor,
|
|
|
- 'dict' => [],
|
|
|
- ];
|
|
|
- $dictList=[
|
|
|
- 'href'=> '#'.$anchor,
|
|
|
- 'title'=> "{$word}",
|
|
|
- ];
|
|
|
- foreach ($result as $key => $value) {
|
|
|
+ $words = [];
|
|
|
+ $word_base = [];
|
|
|
+ $searched = [];
|
|
|
+ $words[$request->get('word')] = [];
|
|
|
+ for ($i=0; $i < 2; $i++) {
|
|
|
# code...
|
|
|
- $dictInfo= DictInfo::find($value->dict_id);
|
|
|
-
|
|
|
- $anchor = "{$word}-{$dictInfo->shortname}";
|
|
|
- $wordData['dict'][] = [
|
|
|
- 'dictname'=> $dictInfo->name,
|
|
|
- 'word'=> $word,
|
|
|
- 'note'=> $this->GrmAbbr($value->note,0),
|
|
|
- 'anchor'=> $anchor,
|
|
|
- ];
|
|
|
- $dictList['children'][] = [
|
|
|
- 'href'=> '#'.$anchor,
|
|
|
- 'title'=> "{$dictInfo->shortname}",
|
|
|
- ];
|
|
|
+ $word_base = [];
|
|
|
+ foreach ($words as $word => $case) {
|
|
|
+ # code...
|
|
|
+ $searched[] = $word;
|
|
|
+ $result = UserDict::select($indexCol)->where('word',$word)->where('source','_PAPER_')->get();
|
|
|
+ $anchor = $word;
|
|
|
+ $wordData=[
|
|
|
+ 'word'=> $word,
|
|
|
+ 'factors'=> "",
|
|
|
+ 'parents'=> "",
|
|
|
+ 'case'=> [],
|
|
|
+ 'grammar'=>$case,
|
|
|
+ 'anchor'=> $anchor,
|
|
|
+ 'dict' => [],
|
|
|
+ ];
|
|
|
+ $dictList=[
|
|
|
+ 'href'=> '#'.$anchor,
|
|
|
+ 'title'=> "{$word}",
|
|
|
+ ];
|
|
|
+ foreach ($result as $key => $value) {
|
|
|
+ # code...
|
|
|
+ $dictInfo= DictInfo::find($value->dict_id);
|
|
|
+
|
|
|
+ $anchor = "{$word}-{$dictInfo->shortname}";
|
|
|
+ $wordData['dict'][] = [
|
|
|
+ 'dictname'=> $dictInfo->name,
|
|
|
+ 'word'=> $word,
|
|
|
+ 'note'=> $this->GrmAbbr($value->note,0),
|
|
|
+ 'anchor'=> $anchor,
|
|
|
+ ];
|
|
|
+ $dictList['children'][] = [
|
|
|
+ 'href'=> '#'.$anchor,
|
|
|
+ 'title'=> "{$dictInfo->shortname}",
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $wordDataOutput[]=$wordData;
|
|
|
+ $dictListOutput[]=$dictList;
|
|
|
+
|
|
|
+ //TODO 加变格查询
|
|
|
+ $case = new CaseMan();
|
|
|
+ $parent = $case->WordToBase($word);
|
|
|
+ foreach ($parent as $base => $case) {
|
|
|
+ # code...
|
|
|
+ if(!in_array($base,$searched)){
|
|
|
+ $word_base[$base] = $case;
|
|
|
+ Log::info($case);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(count($word_base)===0){
|
|
|
+ break;
|
|
|
+ }else{
|
|
|
+ $words = $word_base;
|
|
|
+ }
|
|
|
}
|
|
|
- $wordDataOutput[]=$wordData;
|
|
|
- $dictListOutput[]=$dictList;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
$output['words'] = $wordDataOutput;
|
|
|
$output['dictlist'] = $dictListOutput;
|
|
|
$output['caselist'] = $caseListOutput;
|
|
|
- //TODO 加变格查询
|
|
|
+
|
|
|
//$result = UserDict::select('word')->where('word','like',"{$word}%")->groupBy('word')->get();
|
|
|
//$output['like'] = $result;
|
|
|
|