Refine run-001 toward reference block layout

This commit is contained in:
2026-04-03 15:05:04 +09:00
parent 74197864ca
commit d80d62e2e7
22 changed files with 167 additions and 157 deletions

View File

@@ -504,12 +504,12 @@ def _build_stage2_retry_html(ctx: PipelineContext, retry_plan: dict) -> dict:
comparison_title = comparison_topic.title if comparison_topic and comparison_topic.title else 'Comparison'
problem_bullets = _problem_bullets_from_raw(raw)[:2]
evidence_bullets = _evidence_bullets_from_raw(raw)[:4]
evidence_bullets = _evidence_bullets_from_raw(raw)[:3]
definition_sections = _definition_sections_from_raw(raw)[:3]
relation_bullets = _relation_bullets_from_raw(raw)[:4]
comparison_rows = _parse_comparison_rows_from_raw(raw)
preferred_axes = ['\ubc94\uc704', '\ud504\ub85c\uc138\uc2a4', '\uc131\uacfc\ud488', '\ud655\uc7a5\uc131']
preferred_axes = ['범위', '프로세스', '성과품', '확장성']
picked_rows = [row for row in comparison_rows if row[0] in preferred_axes]
if len(picked_rows) < 4:
seen = {row[0] for row in picked_rows}
@@ -519,7 +519,7 @@ def _build_stage2_retry_html(ctx: PipelineContext, retry_plan: dict) -> dict:
seen.add(row[0])
if len(picked_rows) >= 4:
break
picked_rows = picked_rows[:4]
picked_rows = picked_rows[:3]
image_src = _extract_image_src_from_raw(raw)
if image_src and ctx.base_path:
@@ -531,89 +531,96 @@ def _build_stage2_retry_html(ctx: PipelineContext, retry_plan: dict) -> dict:
image_caption = _extract_caption_from_raw(raw)
conclusion_text = _conclusion_from_raw(raw)
intro_len = sum(len(x) for x in problem_bullets + evidence_bullets)
defs_len = sum(len(s['body']) for s in definition_sections)
relation_len = sum(len(x) for x in relation_bullets)
sidebar_width = '34%' if defs_len >= relation_len else '31%'
main_width = '66%' if defs_len >= relation_len else '69%'
relation_visual_height = '138px' if intro_len > 320 else '152px'
problem_items_html = ''.join(
f'<li style="margin-left:14px; margin-bottom:3px;">{_trim_visible_copy(item, floor=84, ceiling=180)}</li>'
f'<li style="margin-left:14px; margin-bottom:4px;">{_trim_visible_copy(item, floor=100, ceiling=220)}</li>'
for item in problem_bullets
)
evidence_items_html = ''.join(
f'<li style="margin-left:14px; margin-bottom:3px;">{_trim_visible_copy(item, floor=72, ceiling=150)}</li>'
f'<li style="margin-left:14px; margin-bottom:4px;">{_trim_visible_copy(item, floor=84, ceiling=180)}</li>'
for item in evidence_bullets
)
relation_items_html = ''.join(
f'<li style="margin-left:14px; margin-bottom:3px;">{_trim_visible_copy(item, floor=72, ceiling=150)}</li>'
f'<li style="margin-left:16px; margin-bottom:5px;">{_trim_visible_copy(item, floor=92, ceiling=210)}</li>'
for item in relation_bullets
)
definition_cards_html = ''
for section in definition_sections:
for idx, section in enumerate(definition_sections, start=1):
definition_cards_html += (
'<div style="background:#ffffff; border:1px solid #cbd5e1; border-radius:10px; padding:10px 12px;">'
f'<div style="font-size:11px; font-weight:800; color:#0f172a; margin-bottom:4px;">{section["title"]}</div>'
f'<div style="font-size:9px; line-height:1.55; color:#334155;">{_trim_visible_copy(section["body"], floor=120, ceiling=250)}</div>'
'<div style="background:#ffffff; border:1px solid #d7e2f0; border-radius:14px; padding:12px; display:flex; gap:10px; align-items:flex-start; min-height:96px;">'
f'<div style="width:34px; height:34px; border-radius:999px; background:#2563eb; color:#fff; font-size:15px; font-weight:800; display:flex; align-items:center; justify-content:center; flex-shrink:0;">{idx}</div>'
'<div style="flex:1;">'
f'<div style="font-size:13px; font-weight:800; color:#0f172a; margin-bottom:6px; line-height:1.35;">{section["title"]}</div>'
f'<div style="font-size:9.5px; line-height:1.55; color:#334155; word-break:keep-all;">{_trim_visible_copy(section["body"], floor=150, ceiling=330)}</div>'
'</div>'
'</div>'
)
comparison_rows_html = ''
for axis, dx, bim in picked_rows:
comparison_rows_html += (
'<div style="background:#ffffff; border:1px solid #bfdbfe; border-radius:10px; padding:8px 10px; display:flex; flex-direction:column; gap:4px; min-height:52px;">'
f'<div style="font-size:8px; font-weight:800; color:#1d4ed8;">{axis}</div>'
f'<div style="font-size:7.2px; line-height:1.32; color:#1e3a8a;"><span style="font-weight:700;">DX</span> {_trim_visible_copy(dx, floor=48, ceiling=92)}</div>'
f'<div style="font-size:7.2px; line-height:1.32; color:#334155;"><span style="font-weight:700;">BIM</span> {_trim_visible_copy(bim, floor=48, ceiling=92)}</div>'
'<div style="display:grid; grid-template-columns:1fr 86px 1fr; border-top:1px solid #dbe5f2; align-items:stretch;">'
f'<div style="padding:6px 9px; font-size:9.4px; line-height:1.35; color:#1e3a8a; font-weight:600; background:#ffffff;">{_trim_visible_copy(dx, floor=72, ceiling=145)}</div>'
f'<div style="padding:6px 6px; font-size:9.4px; line-height:1.25; color:#1d4ed8; font-weight:800; text-align:center; background:#eff6ff; border-left:1px solid #dbe5f2; border-right:1px solid #dbe5f2; display:flex; align-items:center; justify-content:center;">{axis}</div>'
f'<div style="padding:6px 9px; font-size:9.4px; line-height:1.35; color:#475569; text-align:right; background:#ffffff;">{_trim_visible_copy(bim, floor=72, ceiling=145)}</div>'
'</div>'
)
intro_html = (
'<div style="background:linear-gradient(135deg,#fff7ed 0%,#ffedd5 100%); border:1px solid #fdba74; border-radius:12px; padding:8px 10px; display:grid; grid-template-columns:1fr 1fr; gap:10px;">'
f'<div><div style="font-size:11px; font-weight:800; color:#c2410c; margin-bottom:4px;">{problem_title}</div><ul style="font-size:9px; line-height:1.45; color:#7c2d12; padding-left:0; margin:0; list-style:disc;">{problem_items_html}</ul></div>'
f'<div><div style="font-size:11px; font-weight:800; color:#9a3412; margin-bottom:4px;">{evidence_title}</div><ul style="font-size:8.5px; line-height:1.4; color:#7c2d12; padding-left:0; margin:0; list-style:disc;">{evidence_items_html}</ul></div>'
'<div style="background:linear-gradient(135deg,#fff5f5 0%,#ffe8e8 100%); border:2px solid #f8a4a4; border-radius:12px; padding:10px 14px;">'
'<div style="display:flex; gap:12px; align-items:flex-start;">'
'<div style="font-size:24px; line-height:1; color:#f59e0b; margin-top:2px;">&#9888;</div>'
'<div style="flex:1;">'
f'<div style="font-size:12px; font-weight:900; color:#b42318; margin-bottom:5px;">{problem_title}</div>'
f'<ul style="font-size:9px; line-height:1.45; color:#7a271a; padding-left:0; margin:0 0 4px 0; list-style:disc;">{problem_items_html}</ul>'
f'<div style="font-size:8.5px; line-height:1.38; color:#9a3412; margin-top:2px;"><span style="font-weight:800;">{evidence_title}</span></div>'
f'<ul style="font-size:8.5px; line-height:1.38; color:#9a3412; padding-left:0; margin:2px 0 0 0; list-style:disc;">{evidence_items_html}</ul>'
'<div style="margin-top:8px; background:#991b1b; color:#ffffff; border-radius:4px; padding:5px 10px; font-size:10px; font-weight:800; word-break:keep-all;">&#8594; 각 용어의 정의, 역할, 상호관계에 대한 체계적 정립 필요</div>'
'</div>'
'</div>'
'</div>'
)
relation_html = (
f'<div class="relation-diagram-card" style="background:#ffffff; border:1px solid #cbd5e1; border-radius:14px; padding:12px 14px; display:grid; grid-template-columns:250px 1fr; gap:10px;">'
'<div style="display:flex; flex-direction:column; gap:5px;">'
f'{_relation_visual(image_src, image_caption).replace("height:220px", f"height:{relation_visual_height}")}'
f'<div style="font-size:8px; line-height:1.3; color:#166534; background:#dcfce7; border:1px solid #86efac; border-radius:999px; padding:3px 8px; text-align:center;">{image_caption}</div>'
'<div style="background:#ffffff; border:1px solid #d6e2ef; border-radius:14px; padding:10px 12px;">'
f'<div style="font-size:14px; font-weight:900; color:#1f3b63; margin-bottom:6px;">{relation_title}</div>'
'<div style="display:grid; grid-template-columns:250px 1fr; gap:14px; align-items:start;">'
'<div>'
f'{_relation_visual(image_src, image_caption).replace("height:220px", "height:208px").replace("padding:10px", "padding:12px")}'
f'<div style="margin-top:8px; background:#dcfce7; border:1px solid #86efac; color:#166534; font-size:9px; line-height:1.3; border-radius:999px; padding:4px 10px; text-align:center;">{image_caption}</div>'
'</div>'
'<div style="display:flex; flex-direction:column; gap:8px;">'
f'<ul style="font-size:8.8px; line-height:1.42; color:#334155; padding-left:0; margin:0; list-style:disc;">{relation_items_html}</ul>'
'<div style="margin-top:4px; border:1px solid #b9d3ff; border-radius:10px; overflow:hidden;">'
'<div style="display:grid; grid-template-columns:1fr 86px 1fr; background:linear-gradient(135deg,#0d47a1,#1565c0); color:#fff; font-weight:800; font-size:12px; text-align:center;">'
'<div style="padding:7px 10px;">DX</div>'
'<div style="padding:7px 6px; background:rgba(0,0,0,0.14); font-size:11px;">\uad6c\ubd84</div>'
'<div style="padding:7px 10px;">BIM</div>'
'</div>'
f'{comparison_rows_html}'
'</div>'
'<div style="display:flex; flex-direction:column; gap:6px;">'
f'<div style="font-size:11px; font-weight:800; color:#1e40af;">{relation_title}</div>'
f'<ul style="font-size:8.5px; line-height:1.42; color:#334155; padding-left:0; margin:0; list-style:disc;">{relation_items_html}</ul>'
'</div>'
'</div>'
)
comparison_html = (
'<div class="comparison-summary-card" style="background:#eff6ff; border:1px solid #bfdbfe; border-radius:12px; padding:8px 10px;">'
f'<div style="font-size:11px; font-weight:800; color:#1d4ed8; margin-bottom:6px;">{comparison_title}</div>'
f'<div style="display:grid; grid-template-columns:1fr 1fr; gap:8px;">{comparison_rows_html}</div>'
'</div>'
)
body_html = (
'<div style="width:100%; height:100%; box-sizing:border-box; font-family:\'Segoe UI\',sans-serif; color:#0f172a; display:flex; flex-direction:column; gap:6px;">'
'<div style="width:100%; height:100%; box-sizing:border-box; font-family:Segoe UI,sans-serif; color:#0f172a; display:flex; flex-direction:column; gap:6px;">'
f'{intro_html}'
f'{relation_html}'
f'{comparison_html}'
'</div>'
)
sidebar_html = (
'<div style="width:100%; height:100%; box-sizing:border-box; font-family:\'Segoe UI\',sans-serif; display:flex; flex-direction:column; gap:8px;">'
f'<div style="background:#ffffff; border:1px solid #cbd5e1; border-radius:12px; padding:10px 12px;"><div style="font-size:12px; font-weight:800; color:#1e293b; margin-bottom:8px;">{definitions_title}</div><div style="display:flex; flex-direction:column; gap:8px;">{definition_cards_html}</div></div>'
'<div style="width:100%; height:100%; box-sizing:border-box; font-family:Segoe UI,sans-serif; display:flex; flex-direction:column; gap:10px;">'
f'<div style="font-size:12px; font-weight:800; color:#475569; padding:2px 6px;">{definitions_title}</div>'
f'{definition_cards_html}'
'</div>'
)
footer_html = (
'<div style="background:linear-gradient(135deg, #006aff 0%, #00aaff 100%); border-radius:10px; padding:10px 20px; text-align:center; color:#ffffff; width:100%; height:52px; display:flex; align-items:center; justify-content:center; box-sizing:border-box;">'
f'<div style="font-size:12px; font-weight:800; line-height:1.35;">{conclusion_text}</div>'
'<div style="background:linear-gradient(135deg, #0b6ef3 0%, #17a6f5 100%); border-radius:10px; padding:10px 20px; text-align:center; color:#ffffff; width:100%; height:58px; display:flex; align-items:center; justify-content:center; box-sizing:border-box;">'
f'<div style="font-size:13px; font-weight:900; line-height:1.35;">{conclusion_text}</div>'
'</div>'
)
@@ -621,7 +628,7 @@ def _build_stage2_retry_html(ctx: PipelineContext, retry_plan: dict) -> dict:
'body_html': body_html,
'sidebar_html': sidebar_html,
'footer_html': footer_html,
'reasoning': f"retry regrouping by content importance: intro(problem+evidence), body(relation+comparison), sidebar(definitions), widths {main_width}/{sidebar_width}",
'reasoning': 'retry regrouping by content importance: grouped problem+evidence, reference-like relation block, comparison embedded under relation, numbered definition cards',
}