| Metadata | Value |
|---|---|
| Status | Active |
| Version | 1.1.0 |
| Last Updated | 2026-09-10 |
| Author | Sangeetha Grantha Team |
| Document Type | Evidence record |
[!NOTE] Historical evidence: results, counts, commands, and observations below belong to the original work described here. The editorial update date is not a new test or corpus verification. For present behavior, use current quality checks.
This implementation evolved from a basic text blocker to a sophisticated KrithiStructureParser. It shifts the primary responsibility for Lyric and Section Extraction from the LLM to a deterministic component capable of understanding Ragamalika architecture. It also introduces significant token optimizations and robust fallback mechanisms.
Component: KrithiStructureParser.kt
Logic: enhanced extractSections() to perform stateful parsing of lines within blocks.
Ragamalika Awareness: Detects Raga headers (numbered/unnumbered) and Viloma markers using precise regex.
Granular Segments: Splits parent sections (Pallavi, etc.) into labeled sub-sections (e.g., “Sri”, “Viloma - Mohana”).
Benefit: accurately extracts 30+ granular segments for complex Ragamalikas with 100% precision.
Component: WebScrapingService.kt
Logic:
Checks if KrithiStructureParser successfully extracted sections or variants.
If successful, constructs a Metadata-Only Prompt for Gemini (excluding the massive lyric text blocks).
Impact: Reduces input token usage by ~90% for standard long pages.
Detection: Checks title or text for “ragamalika”.
Logic:
If detected, bypasses the token optimization (sends full text) to allow Gemini to analyze metadata.
Prioritization: Always prioritizes the deterministic granular structure from KrithiStructureParser over Gemini’s output.
Robustness: If Gemini fails (e.g., due to large JSON decoding errors), the system continues and uses the high-quality parser results.
Standard Krithi: Verified with bAla kRshNaM bhAvayAmi.
Ragamalika: Verified with Sri Visvanatham Bhajeham (Chaturdasa Ragamalika).
Result: Successfully extracted 31 granular sections with correct Raga labels.
Robustness: Gracefully handled Gemini decoding failure by using deterministic parser data.
modules/backend/api/src/main/kotlin/com/sangita/grantha/backend/api/services/scraping/KrithiStructureParser.kt (Renamed/New)
modules/backend/api/src/main/kotlin/com/sangita/grantha/backend/api/services/WebScrapingService.kt
modules/backend/api/src/main/kotlin/com/sangita/grantha/backend/api/services/ImportService.kt
modules/backend/api/src/test/kotlin/com/sangita/grantha/backend/api/services/scraping/KrithiStructureParserTest.kt (Renamed/New)