Spaces:
Sleeping
Auto-form: robust กำหนดส่งมอบ extraction (no wrong-section pulls)
Browse filesThe browser TOR fetch picked the FIRST detail part whose title+content merely
contained 'การส่งมอบงาน', so a passing mention in an earlier section (e.g.
'หลักฐานการส่งมอบงาน' in คุณสมบัติผู้ยื่นข้อเสนอ) or a look-alike heading
(สถานที่ส่งมอบ / การจ่ายเงิน / ค่าปรับ) could be pulled instead of the real
delivery clause. Section position is not fixed across TOR types either.
- signer_lookup.py: score every TOR section — title is a delivery heading wins,
look-alike sections are excluded, and a content-only match must carry a real
duration/งวด signal (ภายใน X วัน / งวดที่ N / งวดเดียว / นับถัดจาก). Broadened
the accepted headings (ระยะเวลาส่งมอบ / กำหนดส่งมอบ / ระยะเวลาดำเนินงาน …).
- ai_clean.py: _duration_from_tor tolerates a spelled-out คำอ่าน between the
number and วัน, e.g. 'ภายใน 160 (หนึ่งร้อยหกสิบ) วัน'.
Verified: real selection logic (extracted from the file) picks the correct
section for both sample TORs (1191001682 งวดเดียว 160 วัน, 1141000533 4 งวด)
over the trap/look-alike sections; parse_nguad + _duration_from_tor give the
right งวด and duration.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- ai_clean.py +3 -1
- signer_lookup.py +26 -4
|
@@ -135,7 +135,9 @@ def _duration_from_tor(delivery_clause, days_fallback):
|
|
| 135 |
and the start-event are lifted from the TOR delivery clause. Falls back to the SLA days +
|
| 136 |
the standard 'นับถัดจาก วันที่ ปตท. มีหนังสือแจ้งให้ปฏิบัติงาน' when the TOR has no 'ภายใน X วัน'."""
|
| 137 |
c = re.sub(r"\s+", " ", (delivery_clause or "")).strip()
|
| 138 |
-
|
|
|
|
|
|
|
| 139 |
if m:
|
| 140 |
return "โดยกำหนดให้แล้วเสร็จ" + m.group(0).strip()
|
| 141 |
days = str(days_fallback or "").strip()
|
|
|
|
| 135 |
and the start-event are lifted from the TOR delivery clause. Falls back to the SLA days +
|
| 136 |
the standard 'นับถัดจาก วันที่ ปตท. มีหนังสือแจ้งให้ปฏิบัติงาน' when the TOR has no 'ภายใน X วัน'."""
|
| 137 |
c = re.sub(r"\s+", " ", (delivery_clause or "")).strip()
|
| 138 |
+
# 'ภายใน X วัน ...' — tolerate a spelled-out คำอ่าน between the number and วัน
|
| 139 |
+
# (e.g. 'ภายใน 160 (หนึ่งร้อยหกสิบ) วัน') and an optional leading 'ส่งมอบ/แล้วเสร็จ'.
|
| 140 |
+
m = re.search(r"ภายใน\s*\d+\s*(?:\([^)]*\)\s*)?วัน.*?(?=\s*ทั้งนี้|$)", c)
|
| 141 |
if m:
|
| 142 |
return "โดยกำหนดให้แล้วเสร็จ" + m.group(0).strip()
|
| 143 |
days = str(days_fallback or "").strip()
|
|
@@ -138,16 +138,38 @@ _JS_TEMPLATE = r"""
|
|
| 138 |
out.chairmanPosition = u.PositionNameTH || c.position_name || null;
|
| 139 |
}
|
| 140 |
|
| 141 |
-
// 5) PR -> TOR delivery clause (การส่งมอบงาน
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
try {
|
| 143 |
const torId = inner && inner.torId;
|
| 144 |
if (torId) {
|
| 145 |
const tflt = encodeURIComponent(JSON.stringify({eager: {details: true, "$where": {id: torId}}}));
|
| 146 |
const tor = await jfetch(GW + "/master-service/TOROnline?filter=" + tflt, {headers:H});
|
| 147 |
const parts = (((Array.isArray(tor) && tor[0]) || {}).details) || [];
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
}
|
| 152 |
} catch (_) {}
|
| 153 |
return out;
|
|
|
|
| 138 |
out.chairmanPosition = u.PositionNameTH || c.position_name || null;
|
| 139 |
}
|
| 140 |
|
| 141 |
+
// 5) PR -> TOR delivery clause (การส่งมอบงาน / กำหนดส่งมอบ) — best effort; never blocks names.
|
| 142 |
+
// Robust selection: the section TITLE wins, look-alike sections are excluded, and a
|
| 143 |
+
// content-only match must carry a real duration/งวด signal. This avoids grabbing a passing
|
| 144 |
+
// mention (e.g. "หลักฐานการส่งมอบงาน" in the qualifications section) or a look-alike heading
|
| 145 |
+
// (สถานที่ส่งมอบ / การจ่ายเงิน / ค่าปรับ). The section position/number is NOT assumed.
|
| 146 |
try {
|
| 147 |
const torId = inner && inner.torId;
|
| 148 |
if (torId) {
|
| 149 |
const tflt = encodeURIComponent(JSON.stringify({eager: {details: true, "$where": {id: torId}}}));
|
| 150 |
const tor = await jfetch(GW + "/master-service/TOROnline?filter=" + tflt, {headers:H});
|
| 151 |
const parts = (((Array.isArray(tor) && tor[0]) || {}).details) || [];
|
| 152 |
+
|
| 153 |
+
const titleOf = (d) => stripHtml(d.title || "").replace(/\s+/g, "");
|
| 154 |
+
const bodyOf = (d) => stripHtml(d.contentPreview || d.content || "");
|
| 155 |
+
// delivery-section headings to ACCEPT, and look-alikes to REJECT
|
| 156 |
+
const DELIV = /(การส่งมอบงาน|กำหนด(การ)?ส่งมอบ|กำหนดเวลาส่งมอบ|ระยะเวลา(การ)?ส่งมอบ|ระยะเวลาดำเนิน(งาน|การ)|ระยะเวลาแล้วเสร็จ|กำหนดแล้วเสร็จ)/;
|
| 157 |
+
const LOOK = /(สถานที่ส่งมอบ|การจ่ายเงิน|ค่าปรับ|หลักประกัน|การตรวจรับ)/;
|
| 158 |
+
// a real "ส่งมอบภายใน X วัน" / "งวดที่ N" / "งวดเดียว" / "นับถัดจาก" signal
|
| 159 |
+
const hasDur = (t) => (/ภายใน\s*\d/.test(t) && /วัน/.test(t))
|
| 160 |
+
|| /งวดที่\s*\d/.test(t) || /งวดเดียว/.test(t) || /นับถัดจาก/.test(t);
|
| 161 |
+
|
| 162 |
+
let best = null, bestScore = 0;
|
| 163 |
+
for (const d of parts) {
|
| 164 |
+
const tt = titleOf(d), bt = bodyOf(d);
|
| 165 |
+
if (LOOK.test(tt)) continue; // never the place/payment/penalty section
|
| 166 |
+
const titleHit = DELIV.test(tt), bodyHit = DELIV.test(bt), durHit = hasDur(bt);
|
| 167 |
+
if (!(titleHit || (bodyHit && durHit))) continue; // must be a genuine delivery section
|
| 168 |
+
const score = (titleHit ? 100 : 0) + (bodyHit ? 8 : 0) + (durHit ? 30 : 0)
|
| 169 |
+
+ Math.min(bt.length, 1500) / 1000; // tie-break toward the richer body
|
| 170 |
+
if (score > bestScore) { best = d; bestScore = score; }
|
| 171 |
+
}
|
| 172 |
+
if (best) out.deliveryClause = bodyOf(best) || null;
|
| 173 |
}
|
| 174 |
} catch (_) {}
|
| 175 |
return out;
|