GeezerVison is showing github.com — feat: v0.3.0 IR S3 — ListItem/Caption/Toc/Field 일괄 도입 · DanMeon/rhwp-python@130f560
File treeExpand file treeCollapse file tree Open diff view settings implementation/v0.3.0/stages
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/workflows/ci.yml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 70 | 70 | tests/test_ir_iter_blocks.py tests/test_ir_schema_export.py \ | 71 | 71 | tests/test_ir_picture.py tests/test_ir_furniture.py \ | 72 | 72 | tests/test_ir_formula.py tests/test_ir_footnote.py \ | | 73 | + tests/test_ir_list.py tests/test_ir_caption.py \ | | 74 | + tests/test_ir_toc.py tests/test_ir_field.py \ | 73 | 75 | tests/conftest.py tests/type_check_samples.py | 74 | 76 | - name: Run pyright (intentional errors — expect 4) | 75 | 77 | if: matrix.lint | |
Collapse file Copy file name to clipboardExpand all lines: docs/implementation/v0.3.0/stages/stage-3.md +138Lines changed: 138 additions & 0 deletions - Display the source diff
- Display the rich diff
Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: docs/roadmap/README.md +3-3Lines changed: 3 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -4,11 +4,11 @@ rhwp-python 의 버전별 로드맵 + **활성 spec 인덱스 SSOT**. 모든 spe | 4 | 4 |
| 5 | 5 | 본 문서는 Living — 자유 갱신. | 6 | 6 |
| 7 | | -## 현재 상태 (2026-04-26) | | 7 | +## 현재 상태 (2026-04-27) | 8 | 8 |
| 9 | 9 | - **v0.1.0 / v0.1.1** — Frozen, PyPI 배포 완료 | 10 | 10 | - **v0.2.0** — Frozen, Document IR v1 GA (2026-04-25) | 11 | | -- **v0.3.0** — Draft, Phase 2 (IR 확장 + `rhwp-py` CLI) 진행 중 | | 11 | +- **v0.3.0** — Draft, Phase 2 (IR 확장 + `rhwp-py` CLI) 진행 중. IR 확장 S1~S3 완료 (S4 Schema GA + CLI/LangChain 마무리 남음) | 12 | 12 | - **v0.4.0+** — 미착수, Phase 3 이후 | 13 | 13 |
| 14 | 14 | ## 활성 spec 인덱스 | @@ -44,7 +44,7 @@ Phase 1 (v0.1.x) 은 GA 완료로 별도 phase 문서 없음. | 44 | 44 | |---|---|---| | 45 | 45 | | v0.1.0 | [implementation/v0.1.0/migration.md](../implementation/v0.1.0/migration.md) | [verification/v0.1.0/spinoff-review.md](../verification/v0.1.0/spinoff-review.md) | | 46 | 46 | | v0.2.0 | [implementation/v0.2.0/stages/](../implementation/v0.2.0/stages/) (S1~S5) | — | | 47 | | -| v0.3.0 (in-progress) | [implementation/v0.3.0/stages/](../implementation/v0.3.0/stages/) (S1) | — | | | 47 | +| v0.3.0 (in-progress) | [implementation/v0.3.0/stages/](../implementation/v0.3.0/stages/) (S1~S3) | — | | 48 | 48 |
| 49 | 49 | ## 원칙 | 50 | 50 |
| |
Collapse file Copy file name to clipboardExpand all lines: python/rhwp/integrations/langchain.py +77-5Lines changed: 77 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 28 | 28 | import rhwp | 29 | 29 | from rhwp.ir.nodes import ( | 30 | 30 | Block, | | 31 | + CaptionBlock, | 31 | 32 | EndnoteBlock, | | 33 | + FieldBlock, | 32 | 34 | FootnoteBlock, | 33 | 35 | FormulaBlock, | | 36 | + ListItemBlock, | 34 | 37 | ParagraphBlock, | 35 | 38 | PictureBlock, | 36 | 39 | TableBlock, | | 40 | + TocBlock, | 37 | 41 | UnknownBlock, | 38 | 42 | ) | 39 | 43 |
| @@ -152,20 +156,27 @@ def _block_to_content_and_meta(block: Block) -> tuple[str, dict[str, Any]]: | 152 | 156 | "char_end": block.prov.char_end, | 153 | 157 | } | 154 | 158 | if isinstance(block, TableBlock): | 155 | | - # ^ HTML 을 page_content 로 — LLM 에 구조 정보 제공. 검색 색인용 평문은 메타로 노출 | | 159 | + # ^ HTML 을 page_content 로 — LLM 에 구조 정보 제공. 검색 색인용 평문은 메타로 노출. | | 160 | + # caption 은 v0.2.0 호환 평문 우선, 없으면 caption_block.blocks 평문 폴백 | | 161 | + # (PictureBlock 분기와 대칭 — caption 정보 손실 회피). | | 162 | + caption_text = block.caption or ( | | 163 | + _caption_plain_text(block.caption_block) if block.caption_block is not None else None | | 164 | + ) | 156 | 165 | return block.html, { | 157 | 166 | "kind": "table", | 158 | 167 | "section_idx": block.prov.section_idx, | 159 | 168 | "para_idx": block.prov.para_idx, | 160 | 169 | "rows": block.rows, | 161 | 170 | "cols": block.cols, | 162 | 171 | "text": block.text, | 163 | | - "caption": block.caption, | | 172 | + "caption": caption_text, | 164 | 173 | } | 165 | 174 | if isinstance(block, PictureBlock): | 166 | | - # ^ description (HWP alt-text) 을 page_content 로 — 빈 description 은 lazy_load | 167 | | - # 상위에서 strip 후 skip. image meta 는 RAG 가 picture 를 별도 색인할 때 활용 | 168 | | - content = block.description or "" | | 175 | + # ^ caption.blocks 평문 우선 (S3 구조화), 없으면 description (S1 호환). | | 176 | + # image meta 는 RAG 가 picture 를 별도 색인할 때 활용. 빈 content 는 | | 177 | + # lazy_load 상위에서 strip 후 skip. | | 178 | + caption_text = _caption_plain_text(block.caption) if block.caption is not None else "" | | 179 | + content = caption_text or (block.description or "") | 169 | 180 | meta: dict[str, Any] = { | 170 | 181 | "kind": "picture", | 171 | 182 | "section_idx": block.prov.section_idx, | @@ -198,6 +209,47 @@ def _block_to_content_and_meta(block: Block) -> tuple[str, dict[str, Any]]: | 198 | 209 | "marker_section_idx": block.marker_prov.section_idx, | 199 | 210 | "marker_para_idx": block.marker_prov.para_idx, | 200 | 211 | } | | 212 | + if isinstance(block, ListItemBlock): | | 213 | + # ^ marker + " " + text 로 합쳐 content — RAG 가 항목 단위로 색인 가능. | | 214 | + # level/enumerated 는 청킹 시 hierarchy 보존 단서로 사용. | | 215 | + content = f"{block.marker} {block.text}".strip() | | 216 | + return content, { | | 217 | + "kind": "list_item", | | 218 | + "section_idx": block.prov.section_idx, | | 219 | + "para_idx": block.prov.para_idx, | | 220 | + "level": block.level, | | 221 | + "enumerated": block.enumerated, | | 222 | + } | | 223 | + if isinstance(block, CaptionBlock): | | 224 | + # ^ 단독 CaptionBlock 은 거의 없음 (Picture/Table 자식). 명시적으로 body 에 | | 225 | + # 넣은 사용자 경로만 — direction 메타로 노출. | | 226 | + return _caption_plain_text(block), { | | 227 | + "kind": "caption", | | 228 | + "section_idx": block.prov.section_idx, | | 229 | + "para_idx": block.prov.para_idx, | | 230 | + "direction": block.direction, | | 231 | + } | | 232 | + if isinstance(block, TocBlock): | | 233 | + # ^ entries 의 text 들을 개행 결합. v0.3.0 entries 는 빈 리스트가 일반적 | | 234 | + # (TOC entry 추출은 v0.4.0+) — 빈 content 는 lazy_load 상위에서 skip. | | 235 | + toc_text = "\n".join(e.text for e in block.entries if e.text) | | 236 | + return toc_text, { | | 237 | + "kind": "toc", | | 238 | + "section_idx": block.prov.section_idx, | | 239 | + "para_idx": block.prov.para_idx, | | 240 | + "entry_count": len(block.entries), | | 241 | + } | | 242 | + if isinstance(block, FieldBlock): | | 243 | + # ^ cached_value 가 있으면 그것이 content (예: 자동 날짜). raw_instruction 은 | | 244 | + # round-trip 보존용으로 메타에. v0.3.0 은 cached_value 가 항상 None 이므로 | | 245 | + # 대부분 빈 content — lazy_load 상위에서 skip 됨. | | 246 | + return block.cached_value or "", { | | 247 | + "kind": "field", | | 248 | + "section_idx": block.prov.section_idx, | | 249 | + "para_idx": block.prov.para_idx, | | 250 | + "field_kind": block.field_kind, | | 251 | + "raw_instruction": block.raw_instruction, | | 252 | + } | 201 | 253 | # 새 Block variant 가 추가되면 그 variant 의 elif 를 이 assert 보다 위에 먼저 | 202 | 254 | # 추가해야 한다. 그러지 않으면 AssertionError 로 fail-fast (silent fallback 방지) | 203 | 255 | assert isinstance(block, UnknownBlock) | @@ -206,3 +258,23 @@ def _block_to_content_and_meta(block: Block) -> tuple[str, dict[str, Any]]: | 206 | 258 | "section_idx": block.prov.section_idx, | 207 | 259 | "para_idx": block.prov.para_idx, | 208 | 260 | } | | 261 | + | | 262 | + | | 263 | +def _caption_plain_text(caption: CaptionBlock) -> str: | | 264 | + """CaptionBlock.blocks 의 텍스트 표현을 개행 결합 (S3 신규 헬퍼). | | 265 | +
| | 266 | + 포함 대상: ParagraphBlock.text + FormulaBlock.text_alt|script + FieldBlock.cached_value. | | 267 | + 캡션 안의 수식·필드도 평문 흐름의 일부 (spec § 5 "캡션 안의 인라인 수식·필드도 | | 268 | + 자연스럽게 표현") — RAG 색인에 자연 포함. 표/그림 등 구조 블록은 별도 색인. | | 269 | + """ | | 270 | + parts: list[str] = [] | | 271 | + for b in caption.blocks: | | 272 | + if isinstance(b, ParagraphBlock) and b.text: | | 273 | + parts.append(b.text) | | 274 | + elif isinstance(b, FormulaBlock): | | 275 | + text = b.text_alt or b.script | | 276 | + if text: | | 277 | + parts.append(text) | | 278 | + elif isinstance(b, FieldBlock) and b.cached_value: | | 279 | + parts.append(b.cached_value) | | 280 | + return "\n".join(parts) |
Collapse file Copy file name to clipboardExpand all lines: python/rhwp/ir/__init__.pyi +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,9 @@ from rhwp.ir.nodes import ( | 6 | 6 | from rhwp.ir.nodes import ( | 7 | 7 | Block as Block, | 8 | 8 | ) | | 9 | +from rhwp.ir.nodes import ( | | 10 | + CaptionBlock as CaptionBlock, | | 11 | +) | 9 | 12 | from rhwp.ir.nodes import ( | 10 | 13 | DocumentMetadata as DocumentMetadata, | 11 | 14 | ) | @@ -15,6 +18,12 @@ from rhwp.ir.nodes import ( | 15 | 18 | from rhwp.ir.nodes import ( | 16 | 19 | EndnoteBlock as EndnoteBlock, | 17 | 20 | ) | | 21 | +from rhwp.ir.nodes import ( | | 22 | + FieldBlock as FieldBlock, | | 23 | +) | | 24 | +from rhwp.ir.nodes import ( | | 25 | + FieldKind as FieldKind, | | 26 | +) | 18 | 27 | from rhwp.ir.nodes import ( | 19 | 28 | FootnoteBlock as FootnoteBlock, | 20 | 29 | ) | @@ -33,6 +42,9 @@ from rhwp.ir.nodes import ( | 33 | 42 | from rhwp.ir.nodes import ( | 34 | 43 | InlineRun as InlineRun, | 35 | 44 | ) | | 45 | +from rhwp.ir.nodes import ( | | 46 | + ListItemBlock as ListItemBlock, | | 47 | +) | 36 | 48 | from rhwp.ir.nodes import ( | 37 | 49 | ParagraphBlock as ParagraphBlock, | 38 | 50 | ) | @@ -54,6 +66,12 @@ from rhwp.ir.nodes import ( | 54 | 66 | from rhwp.ir.nodes import ( | 55 | 67 | TableCell as TableCell, | 56 | 68 | ) | | 69 | +from rhwp.ir.nodes import ( | | 70 | + TocBlock as TocBlock, | | 71 | +) | | 72 | +from rhwp.ir.nodes import ( | | 73 | + TocEntryBlock as TocEntryBlock, | | 74 | +) | 57 | 75 | from rhwp.ir.nodes import ( | 58 | 76 | UnknownBlock as UnknownBlock, | 59 | 77 | ) | @@ -73,15 +91,19 @@ from rhwp.ir.schema import ( | 73 | 91 | __all__ = [ | 74 | 92 | "CURRENT_SCHEMA_VERSION", | 75 | 93 | "Block", | | 94 | + "CaptionBlock", | 76 | 95 | "DocumentMetadata", | 77 | 96 | "DocumentSource", | 78 | 97 | "EndnoteBlock", | | 98 | + "FieldBlock", | | 99 | + "FieldKind", | 79 | 100 | "FootnoteBlock", | 80 | 101 | "FormulaBlock", | 81 | 102 | "Furniture", | 82 | 103 | "HwpDocument", | 83 | 104 | "ImageRef", | 84 | 105 | "InlineRun", | | 106 | + "ListItemBlock", | 85 | 107 | "ParagraphBlock", | 86 | 108 | "PictureBlock", | 87 | 109 | "Provenance", | @@ -91,6 +113,8 @@ __all__ = [ | 91 | 113 | "Section", | 92 | 114 | "TableBlock", | 93 | 115 | "TableCell", | | 116 | + "TocBlock", | | 117 | + "TocEntryBlock", | 94 | 118 | "UnknownBlock", | 95 | 119 | "export_schema", | 96 | 120 | "load_schema", | |
|