PaliWordFormController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Controllers\V3;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Resources\V3\PaliWordFormResource;
  5. use App\Services\V3\PaliWordFormService;
  6. /**
  7. * 巴利词形展开(只读、公开)。
  8. *
  9. * 取代 `GET /v2/case/{word}`(`CaseController@show`)。v2 那份在 dashboard-v4 下线前原样保留,不要改动。
  10. */
  11. class PaliWordFormController extends Controller
  12. {
  13. public function __construct(private readonly PaliWordFormService $forms) {}
  14. /**
  15. * 词形展开
  16. *
  17. * 把一个巴利词还原成可能的词根,列出每个词根在三藏里实际出现过的词形(含 iti / api / ca / hi 连音),
  18. * 带出现次数与黑体次数。第一组是输入的词本身,其后是推导出的词根;没有任何词形出现过的词根不列。
  19. * 每组内按出现次数降序。词不区分大小写。
  20. *
  21. * @unauthenticated
  22. *
  23. * @urlParam word string required 巴利词,如 vitakka
  24. *
  25. * @meta total integer 组数
  26. */
  27. public function __invoke(string $word)
  28. {
  29. $groups = $this->forms->groups($word);
  30. return PaliWordFormResource::collection($groups)->additional(['meta' => ['total' => count($groups)]]);
  31. }
  32. }