feat: sb verses extracted

This commit is contained in:
gosangam
2026-04-14 15:58:06 +05:30
parent 82e720b10a
commit c5d4194d00
6502 changed files with 16345 additions and 7851 deletions
+40 -9
View File
@@ -86,18 +86,49 @@ def normalize_devanagari_anusvara(text: str) -> str:
def join_virama_words(text: str) -> str:
"""Join Devanagari words where the previous word ends with virāma (्)
and the next word starts with a consonant.
"""Join Devanagari words where the previous word ends with virāma (्).
In standard Devanagari verse rendering, a word ending in a halant
(virāma) connects to the following consonant-initial word without a space.
e.g., श्रीर् विजयो → श्रीर्विजयो
Handles both virāma+consonant and virāma+vowel cases.
In Devanagari script, a halant (virāma) consonant always absorbs the
following letter — whether consonant or vowel — without a space.
But when followed by a vowel, the space is preserved:
e.g., किम् अकुर्वत → किम् अकुर्वत (stays separate)
virāma + consonant: श्रीर् विजयो → श्रीर्विजयो
virāma + vowel: किम् अकुर्वत → किमकुर्वत
तैर् अलातायुधैः → तैरलातायुधैः
माम् एकं → मामेकं
Uses [ \\t]+ instead of \\s+ to avoid joining across newlines (line breaks
separate paired pādas and must be preserved).
"""
# Devanagari consonants: क (U+0915) through ह (U+0939)
return re.sub(r"्\s+([क-ह])", r"्\1", text)
# Join virāma + space + consonant (क U+0915 through ह U+0939)
text = re.sub(r"्[ \t]+([क-ह])", r"्\1", text)
# Join virāma + space + independent vowel (अ U+0905 through औ U+0914, plus ॠ ॡ)
# Drop the virāma and replace the independent vowel with its dependent mātrā form.
_VOWEL_TO_MATRA = {
"अ": "", # inherent vowel — just drop virāma and the अ
"आ": "ा",
"इ": "ि",
"ई": "ी",
"उ": "ु",
"ऊ": "ू",
"ऋ": "ृ",
"ॠ": "ॄ",
"ऌ": "ॢ",
"ॡ": "ॣ",
"ए": "े",
"ऐ": "ै",
"ओ": "ो",
"औ": "ौ",
}
def _virama_vowel_replace(m):
vowel = m.group(1)
matra = _VOWEL_TO_MATRA.get(vowel, vowel)
return matra
text = re.sub(r"्[ \t]+([अ-औॠॡ])", _virama_vowel_replace, text)
return text
def iast_to_devanagari(iast_text: str) -> str: