| Metadata | Value |
|---|---|
| Status | Completed |
| Version | 1.0.0 |
| Last Updated | 2026-03-20 |
| Author | Sangeetha Grantha Team |
ID: TRACK-101 Status: Not Started Owner: Sangita Grantha Architect Created: 2026-03-20 Updated: 2026-03-20 Parent: TRACK-093 (Trinity Krithi Import)
Fix the StructureParser so that when numbered section headers like caraNam 1, svara sAhitya 2 are matched, the trailing number is stripped from the section body text. Currently the number bleeds into the lyric content as a leading character.
database/for_import/EXTRACTION-INVESTIGATION-REPORT.mdtools/krithi-extract-enrich-worker/src/structure_parser.py_detect_section_header() matches caraNam 1, the regex pattern.sub("", line, count=1) at line 399 removes the matched section keyword but leaves the trailing number. The remainder becomes "1 \n mANikya mayamaiyunna...".remainder should be "mANikya mayamaiyunna..." with no leading number._detect_section_header() (line 396) iterates SECTION_HEADER_PATTERNSr"^\s*[\-–—•*()=\[\]]*\s*(?:(?:ch|c)ara?n(?:\.\s*am|am)|caraṇam)(?:\b|:|\.|\-|\)|]|=|$)"This pattern matches caraNam but NOT the trailing ` 1 — the (?:\b |
… | $)` anchor group matches at the word boundary after “caraNam” |
remainder = pattern.sub("", line, count=1).strip() removes caraNam but " 1" staysremainder = re.sub(r"^[:\-)\]\.\s]+", "", remainder).strip() strips leading punctuation/whitespace but NOT digitsremainder "1" is then prepended to the section text via _HeaderMatch.remainderThe fix belongs in _detect_section_header() at line 400. After stripping punctuation/whitespace, also strip a leading number (with optional whitespace) that represents the section occurrence counter.
# Current (line 400):
remainder = re.sub(r"^[:\-)\]\.\s]+", "", remainder).strip()
# Fixed:
remainder = re.sub(r"^[:\-)\]\.\s]+", "", remainder).strip()
remainder = re.sub(r"^\d+\s*", "", remainder).strip()
Need to ensure this doesn’t strip leading digits that are actually part of lyric text. In Carnatic compositions, lyric lines don’t start with bare numbers — numbered section markers are the only source of leading digits after a header match. Safe to strip.
_detect_section_header() (line 400), add re.sub(r"^\d+\s*", "", remainder) after the existing punctuation stripr"^[:\-)\]\.\s\d]+""caraNam 1\nmANikya mayamaiyunna" → section text should be "mANikya mayamaiyunna" with no leading "1""svara sAhitya 2\nkunda radanA" → section text "kunda radanA""caraNam\nmANikya" (no number) → still works correctlySimple one-line fix. The trailing-number strip should happen after the existing punctuation strip to handle cases like caraNam - 1 or caraNam: 2.
tools/krithi-extract-enrich-worker/src/structure_parser.py — _detect_section_header() method, line ~400tools/krithi-extract-enrich-worker/tests/test_structure_parser.py — add numbered-label test cases