Skip to content

Commit 8b87361

Browse files
sudoghutclaude
andauthored
任官自動填充:修正二字地名 name 被錯誤剝離為單字的問題 (#972)
* 任官自動填充:修正二字地名 name 被錯誤剝離為單字的問題 AI 解析「黃縣」等二字地名時,可能將 name 剝離為單字(黃)而非保留完整 地名(黃縣)。同時在 prompt 與程式碼層面修正: - 擴展 prompt 中二字地名規則,涵蓋縣、郡等所有行政區劃類型 - 新增 normalizeAddrName() 在程式端防護,確保 name 為單字時自動補回 admin_type Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * style: 修正 PHP CS Fixer 格式問題 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent babdb08 commit 8b87361

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

app/Services/PostingAutofillService.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ protected function matchFields(array $aiData, int $personId): array {
352352
// 2. 地名匹配(addr_str)
353353
if (!empty($aiData['addr_str']) && is_array($aiData['addr_str'])) {
354354
$addrData = $aiData['addr_str'];
355+
$addrData = $this->normalizeAddrName($addrData);
355356
$searchName = $addrData['name'] ?? null;
356357
$parentName = $addrData['parent'] ?? null;
357358

@@ -659,6 +660,22 @@ protected function fuzzyMatchOffice(string $officeName, ?int $dynastyCode = null
659660
return null;
660661
}
661662

663+
/**
664+
* 正規化 addr_str:當 name 剝離 admin_type 後只剩一個字時,將 admin_type 補回 name。
665+
*
666+
* 例如 AI 可能回傳 name=黃, admin_type=縣,應修正為 name=黃縣, admin_type=縣。
667+
*/
668+
protected function normalizeAddrName(array $addrData): array {
669+
$name = $addrData['name'] ?? null;
670+
$adminType = $addrData['admin_type'] ?? null;
671+
672+
if ($name !== null && $adminType !== null && mb_strlen($name) === 1) {
673+
$addrData['name'] = $name.$adminType;
674+
}
675+
676+
return $addrData;
677+
}
678+
662679
/**
663680
* 模糊匹配地名
664681
*

resources/prompts/ai-posting-extraction-prompt.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ For each posting in `postings`, fill the following fields:
125125
→ Example: "永興軍" → `"name": "永興", "admin_type": "軍"`
126126
→ Example: "安豐軍" → `"name": "安豐", "admin_type": "軍"`
127127
→ Example: "西京監" → `"name": "西京", "admin_type": "監"`
128-
* For **2-character names** ending with 州/府:
129-
→ The last character is likely part of the place name itself
128+
* For **2-character names** (e.g. 黃縣、涿州、泉州):
129+
→ The last character is the admin_type, but name must **keep the full 2-character form**
130130
→ Example: "涿州" → `"name": "涿州", "admin_type": "州"`
131131
→ Example: "泉州" → `"name": "泉州", "admin_type": "州"`
132132
→ Example: "杭州" → `"name": "杭州", "admin_type": "州"`
133+
→ Example: "黃縣" → `"name": "黃縣", "admin_type": "縣"`
134+
→ Example: "吳郡" → `"name": "吳郡", "admin_type": "郡"`
133135
* If admin unit cannot be determined, set to `null`
134136

135137
**If no location is explicitly stated, return `null` for the entire addr_str.**

0 commit comments

Comments
 (0)