訂明本例驗收任務
假設對話讀取器只接本例格式:Reporter reports [Speaker: text]。名稱只用英文字母,引述內容不可有方括號。符合時分開列轉述人及原說話者;不當作轉述人的直接要求。其他寫法保留未能解析,不猜。
- 比對已訂轉述格式
- 分開讀轉述人及原說話者
- 保留引述,不變成操作要求
格式不符,保留原文覆核。
使用已填個案
| 個案 | 已提供輸入 | 預期結構化結果 | 判斷及原因 |
|---|---|---|---|
| 轉述取消要求 | {"line":"Ada reports [Bo: cancel X]"} | {"reporter":"Ada","quotedSpeaker":"Bo","quotedText":"cancel X","reporterRequest":false} | 引述 Bo;Ada 只是轉述,不是 Ada 的要求。 |
| 兩個角色同名 | {"line":"Ada reports [Ada: inspect X]"} | {"reporter":"Ada","quotedSpeaker":"Ada","quotedText":"inspect X","reporterRequest":false} | 即使同名,按此格式仍是轉述,不改成直接操作。 |
| 超出格式的嵌套文字 | {"line":"Ada reports [Bo: Cal says [cancel X]]"} | {"error":"grammar"} | 本格式不接嵌套括號,保留原行覆核。 |
逐步處理 nested-unrecognised 個案,須得到甚麼結果?原因是甚麼?
查看參考答案
{"error":"grammar"}。本格式不接嵌套括號,保留原行覆核。
執行完整本機驗算
import assert from 'node:assert/strict';
function evaluate(x){
const m=/^([A-Za-z]+) reports \[([A-Za-z]+): ([^\[\]]+)\]$/.exec(x.line);
return m?{reporter:m[1],quotedSpeaker:m[2],quotedText:m[3],reporterRequest:false}:{error:'grammar'};
}
const cases = [
{
"id": "reported-cancellation",
"input": {
"line": "Ada reports [Bo: cancel X]"
},
"expected": {
"reporter": "Ada",
"quotedSpeaker": "Bo",
"quotedText": "cancel X",
"reporterRequest": false
}
},
{
"id": "same-person-two-roles",
"input": {
"line": "Ada reports [Ada: inspect X]"
},
"expected": {
"reporter": "Ada",
"quotedSpeaker": "Ada",
"quotedText": "inspect X",
"reporterRequest": false
}
},
{
"id": "nested-unrecognised",
"input": {
"line": "Ada reports [Bo: Cal says [cancel X]]"
},
"expected": {
"error": "grammar"
}
}
];
for (const c of cases) assert.deepEqual(evaluate(c.input), c.expected, c.id);
console.log(JSON.stringify({checked:cases.length,caseIds:cases.map(c=>c.id)}));
把兩個角色連同引述保留。此解析器只示範已訂格式的答案,不聲稱可解任意對話,也沒有批准取消。