Sangeetha-Grantha

Metadata Value
Status Completed
Version 1.0.0
Last Updated 2026-03-20
Author Sangeetha Grantha Team

Track: Multi-Pass Parsing Architecture for Indic Script Extraction

ID: TRACK-100 Status: Not Started Owner: Sangita Grantha Architect Created: 2026-03-20 Updated: 2026-03-20 Parent: TRACK-093 (Trinity Krithi Import)

Goal

Redesign the StructureParser.parse() method to process content beyond the first metadata boundary, enabling extraction of Devanagari, Tamil, Telugu, Kannada, and Malayalam lyric variants. Currently only the English/IAST variant is extracted because the parser truncates all text at the first metadata boundary (Gist/Meaning/Variations), and all Indic-script lyrics appear after these boundaries on all three Trinity blogs.

Context

Analysis

Verified Code Path

  1. parse() (line 274) receives full extracted text
  2. _find_metadata_boundaries() (line 862) scans entire text for MEANING, GIST, NOTES, WORD_DIVISION, VARIATIONS patterns
  3. Lines 286-297: Early-boundary guard skips boundaries in first 200 chars (TRACK-097 fix)
  4. Line 299-300 — the critical truncation:
    lyric_window_end = effective_boundaries[0].start_pos if effective_boundaries else len(source_text)
    lyric_text = source_text[:lyric_window_end]
    
  5. _build_blocks() (line 315) only receives lyric_text — the truncated window
  6. _extract_sections() and _extract_lyric_variants() therefore only see English/IAST content

Blog Content Layout (verified against test evidence)

English/IAST sections (Pallavi, Anupallavi, Charanam)
─── metadata boundary (Gist/Variations) ─── ← parser stops here
Word-by-word Meaning
Notes/Comments
Devanagari sections
Tamil sections
Telugu sections
Kannada sections
Malayalam sections

Report Accuracy

The report’s characterization is accurate. The truncation at line 299-300 is the root cause. The _extract_language_header_variants() method (line 665) already has logic to handle language-labeled blocks, but it never sees them because _build_blocks() is fed truncated text.

Implementation Plan

Phase 1: Full-Document Language Block Detection

Phase 2: Per-Block Section Parsing

Phase 3: Integration

Phase 4: Testing & Validation

Design Considerations

Option A — Full-document language-block parsing (recommended): Scan the entire document for language headers, parse each block independently. This is cleaner because it treats each language variant as a first-class entity and naturally handles per-script metadata sections.

Option B — Two-phase approach: Extract English skeleton first, then scan remaining document for Indic blocks. This preserves more of the current code path but creates tighter coupling between the two phases.

Recommendation: Option A. The existing _extract_language_header_variants() method already implements most of the per-block logic — it just needs to operate on the full document. The change is primarily in parse() where the text window is constructed, not in the downstream extraction methods.

Risk: Language headers (e.g., “Tamil”, “Devanagari”) might appear within lyric text as words. Mitigation: language headers must be standalone lines (the existing _detect_language_header() already checks for this via lowered == key or lowered.startswith(f"{key}:") patterns).

Acceptance Criteria

Dependencies

Files to Modify