fix(extract): 章 marker と sub-heading の区別 + EDINET フッター除去#10
Merged
Conversation
PR #8 で導入した depth-aware section flush は physical h-level (h1〜h6 タグ) のみを見ていたが、 EDINET 提出書類によっては 章見出しと sub-heading に同じ <h3> タグを使っているため、 sub-heading で section が誤 flush される。 具体例: セコム 第64期 (S100W3TS) の risk 章: - `<h3>3【事業等のリスク】` ← 章 marker - `<h3>(1)事業環境に起因するリスク` ← sub-heading だが同じ <h3> - `<h3>(2)経営戦略に関するリスク` ← 同上 - `<h3>4【経営者による財政状態...】` ← 次の章 marker (mda) PR #8 の depth-only flush は (1)事業環境に起因するリスク で risk を flush してしまい、 risk セクションが 4,050 chars → 286 chars (intro のみ) に劇的に短縮されていた (= silent data loss)。 ## 修正 ### chapter vs sub-numbering を識別 `chapterHeadingPrefixRe` で 「N【...】」 「第N【...】」 形式の **章 marker** のみを検出。 「(1)」 「①」 「a.」 などの sub-numbering はマッチしない。 `walkForSections` の非マッチ heading の flush 判定を: 旧: `level > 0 && level <= state.depth` (depth のみ) 新: `level > 0 && level <= state.depth && isChapterHeading(headingText)` (depth + 章 marker) これで、 sub-heading は同 depth でも章を flush せず sub-section として継続。 章 marker が出てきたら flush する。 ### EDINET フッターアーティファクトを除去 各 `_honbun_*.htm` の末尾には `有価証券報告書(通常方式)_<14桁timestamp>` という EDINET メタ情報が書かれている。 walker はこれを最後の section の末尾に取り込んでしまうため、 governance / financial 等の末尾に metadata text が混入していた。 `filingFooterRe` で末尾の `有価証券報告書(通常方式)_<digits>` を section text から除去。 各 section の Text に `stripFilingFooter` を適用。 ## 検証 | docID | section | before (PR #8+#9) | after (本 PR) | |---|---|---|---| | S100W3TS (セコム) | risk | **286 (regression)** | **4,050 (restored)** | | S100XTNW (楽天) | governance | 8,813 | 38,947 (footer/章 marker 整理) | | S100XS22 (マクドナルド) | governance | 30,201 | 30,170 (footer -31 chars) | | S100VT7P (セブン&アイ) | governance | 59,998 | 59,967 (footer -31 chars) | 全 section の text 末尾 100 chars に `有価証券報告書(通常方式)_` を検出しなくなった。 ## Tests - `TestExtractSections_SubHeadingSameHTag`: セコムパターン (同 h3 タグで章 + sub) で section が正しく分割されること - `TestIsChapterHeading`: 章 marker と sub-numbering の判定が正しいこと - `TestStripFilingFooter`: footer 除去ロジック単体 - `TestExtractSections_FilingFooterStripped`: section 抽出時に footer が除去されること `go test ./...` 全件パス。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR #8 で導入した depth-aware section flush の 過剰 flush リグレッション と、 EDINET フッターアーティファクトの混入を修正します。
P1 リグレッション (セコム risk 286 chars に短縮)
セコム 第64期 (S100W3TS) の risk 章は、 章見出しと sub-heading に 同じ
<h3 class="smt_head2">タグ を使っています:```html
3【事業等のリスク】
← 章 marker (h3)intro...
(1)事業環境に起因するリスク
← sub-heading だが同じ... ①社会・経済 ...
(2)経営戦略に関するリスク
← 同上 ...4【経営者による財政状態...】
← 次の章 marker (mda) \`\`\`PR #8 の depth-only flush ロジックは `(1)事業環境に起因するリスク` で risk を flush してしまい、 4,050 chars → 286 chars (intro のみ) に短縮していました (= silent data loss)。
修正方針
章 marker と sub-numbering を識別
`chapterHeadingPrefixRe` で 「N【...】」 「第N【...】」 形式の 章 marker のみ検出:
`walkForSections` の非マッチ heading の flush 判定を:
これで sub-heading は同 depth でも章を flush せず継続。 章 marker が出てきたら flush する。
EDINET フッターアーティファクト除去 (codex P3)
各 `honbun*.htm` の末尾には `有価証券報告書(通常方式)<14桁timestamp>` という EDINET メタ情報が書かれており、 walker が最後の section に取り込んでいました。 `filingFooterRe` で末尾の `有価証券報告書(通常方式)` を section text から除去します。
検証
全 section の text 末尾 100 chars に `有価証券報告書(通常方式)_` を検出しなくなりました (P3 解消)。
Tests
`go test ./...` 全件パス。
Test plan