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
+46 -2
View File
@@ -85,8 +85,52 @@ 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."""
return re.sub(r"्\s+([क-ह])", r"्\1", text)
"""Join Devanagari words where the previous word ends with virāma.
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.
virāma + consonant: श्रीर् विजयो → श्रीर्विजयो
virāma + vowel: तैर् अलातायुधैः → तैरलातायुधैः
"""
# Join virāma + space + consonant (क U+0915 through ह U+0939)
# Use [ \t]+ instead of \s+ to avoid joining across newlines (line breaks
# separate paired pādas and must be preserved).
text = re.sub(r"्[ \t]+([क-ह])", r"्\1", text)
# Join virāma + space + independent vowel (अ U+0905 through औ U+0914, plus ॠ ॡ)
# The transliterator will have produced virāma on the consonant and a separate
# independent vowel glyph. We need to:
# 1. Drop the virāma (the consonant takes the vowel)
# 2. Replace the independent vowel with its dependent mātrā form
# However, a simpler approach: just remove the space and let the
# virāma+independent-vowel stay — this is visually wrong.
# Instead, we do the proper mapping:
_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)
# Remove the virāma (्) and replace independent vowel with mātrā
return matra
text = re.sub(r"्[ \t]+([अ-औॠॡ])", _virama_vowel_replace, text)
return text
def iast_to_devanagari(iast_text: str) -> str: