跳至內容
Astera Technology

保留轉述中的原說話者

用有限轉述格式分原說話者與轉述人,不把引述變成直接要求。

下載完整個案資料及參考答案 ↓

訂明本例驗收任務

假設對話讀取器只接本例格式:Reporter reports [Speaker: text]。名稱只用英文字母,引述內容不可有方括號。符合時分開列轉述人及原說話者;不當作轉述人的直接要求。其他寫法保留未能解析,不猜。

  1. 比對已訂轉述格式
  2. 分開讀轉述人及原說話者
  3. 保留引述,不變成操作要求

格式不符,保留原文覆核。

使用已填個案

原創假設輸入及確切答案鍵
個案已提供輸入預期結構化結果判斷及原因
轉述取消要求{"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"}本格式不接嵌套括號,保留原行覆核。
下載可編輯 CSV ↓

逐步處理 nested-unrecognised 個案,須得到甚麼結果?原因是甚麼?

查看參考答案

{"error":"grammar"}。本格式不接嵌套括號,保留原行覆核。

執行完整本機驗算

另存為 .mjs,以 Node.js 執行;只驗提供的個案
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)}));
下載可執行例子 ↓

把兩個角色連同引述保留。此解析器只示範已訂格式的答案,不聲稱可解任意對話,也沒有批准取消。

相關資源