訂明本例驗收任務
假設雙欄單張提供文字框編號、已確認欄別及安全整數垂直位置。先沿所列欄次序,再由上而下讀;同高度按編號升序。欄別不在清單或編號重複便拒絕,不能自行估欄。
- 核對每框所屬欄
- 在各欄內排序
- 按欄次序接成全文
欄別未訂明,交版面覆核。
使用已填個案
| 個案 | 已提供輸入 | 預期結構化結果 | 判斷及原因 |
|---|---|---|---|
| 左右欄高度交錯 | {"columns":["left","right"],"boxes":[{"id":"R1","column":"right","y":10},{"id":"L2","column":"left","y":30},{"id":"L1","column":"left","y":5},{"id":"R2","column":"right","y":20}]} | {"order":["L1","L2","R1","R2"]} | 先按欄分組,不能把全部文字按高度混排。 |
| 兩框同高度 | {"columns":["left"],"boxes":[{"id":"B","column":"left","y":10},{"id":"A","column":"left","y":10}]} | {"order":["A","B"]} | 按本例同高規則,A 先於 B。 |
| 文字框位置有小數 | {"columns":["left"],"boxes":[{"id":"A","column":"left","y":1.5}]} | {"error":"box-position"} | 已訂整數座標不接1.5,不把它當有效高度來排。 |
| 欄別未列明 | {"columns":["left","right"],"boxes":[{"id":"X","column":"middle","y":1}]} | {"error":"box-association"} | middle 沒有已訂閱讀位置。 |
逐步處理 unknown-column 個案,須得到甚麼結果?原因是甚麼?
查看參考答案
{"error":"box-association"}。middle 沒有已訂閱讀位置。
執行完整本機驗算
import assert from 'node:assert/strict';
function evaluate(x){
if(x.boxes.some(b=>!Number.isSafeInteger(b.y)))return {error:'box-position'};
if(new Set(x.boxes.map(b=>b.id)).size!==x.boxes.length||x.boxes.some(b=>!x.columns.includes(b.column)))return {error:'box-association'};
return {order:x.columns.flatMap(column=>x.boxes.filter(b=>b.column===column).sort((a,b)=>a.y-b.y||(a.id<b.id?-1:a.id>b.id?1:0)).map(b=>b.id))};
}
const cases = [
{
"id": "staggered-columns",
"input": {
"columns": [
"left",
"right"
],
"boxes": [
{
"id": "R1",
"column": "right",
"y": 10
},
{
"id": "L2",
"column": "left",
"y": 30
},
{
"id": "L1",
"column": "left",
"y": 5
},
{
"id": "R2",
"column": "right",
"y": 20
}
]
},
"expected": {
"order": [
"L1",
"L2",
"R1",
"R2"
]
}
},
{
"id": "height-tie",
"input": {
"columns": [
"left"
],
"boxes": [
{
"id": "B",
"column": "left",
"y": 10
},
{
"id": "A",
"column": "left",
"y": 10
}
]
},
"expected": {
"order": [
"A",
"B"
]
}
},
{
"id": "fractional-position",
"input": {
"columns": [
"left"
],
"boxes": [
{
"id": "A",
"column": "left",
"y": 1.5
}
]
},
"expected": {
"error": "box-position"
}
},
{
"id": "unknown-column",
"input": {
"columns": [
"left",
"right"
],
"boxes": [
{
"id": "X",
"column": "middle",
"y": 1
}
]
},
"expected": {
"error": "box-association"
}
}
];
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)}));
排查指示被交錯時,連同文字保留小型文字框圖。本例座標已提供;驗算只排序,沒有從圖片偵測文字框。