Skip to content

Instantly share code, notes, and snippets.

@shantanuo
Created May 18, 2024 04:00
Show Gist options
  • Save shantanuo/19087db135474c2e59ca7f57e0ee9f36 to your computer and use it in GitHub Desktop.
Save shantanuo/19087db135474c2e59ca7f57e0ee9f36 to your computer and use it in GitHub Desktop.
python implementation of vruddhi
import re
vruddhi = {'अ': 'आ', 'इ': 'ऐ', 'ई': 'ऐ', 'उ': 'औ', 'ऊ': 'औ', 'ए': 'ऐ', 'ओ': 'औ',
'ि': 'ै', 'ी': 'ै', 'ु': 'ौ', 'ू': 'ौ', 'े': 'ै', 'ो': 'ौ',
'क': 'का', 'ख': 'खा', 'ग': 'गा', 'घ': 'घा', 'ङ': 'ङा',
'च': 'चा', 'छ': 'छा', 'ज': 'जा', 'झ': 'झा', 'ञ': 'ञा',
'ट': 'टा', 'ठ': 'ठा', 'ड': 'डा', 'ढ': 'ढा', 'ण': 'णा',
'त': 'ता', 'थ': 'था', 'द': 'दा', 'ध': 'धा', 'न': 'ना',
'प': 'पा', 'फ': 'फा', 'ब': 'बा', 'भ': 'भा', 'म': 'मा',
'य': 'या', 'र': 'रा', 'ल': 'ला', 'व': 'वा', 'श': 'शा',
'ष': 'षा', 'स': 'सा', 'ह': 'हा', 'ळ': 'ळा'}
svar = ["ा", "ि", "ी", "ु", "ू", "े", "ै", "ो", "ौ"]
def sanskrit_expand(s):
try:
pattern = re.compile(r"(.्)?.[ािीुूृेैोौ]?")
x = pattern.match(s).group(0)
myr = x[-1]
ns = s.replace(myr, vruddhi[myr], 1)
if s[-1] in svar:
ns1 = ns[0:-1] + "िक"
ns2 = ns[0:-1] + "ी"
ns3 = ns[0:-1] + "्य"
else:
ns1 = ns + "िक"
ns2 = ns + "ी"
ns3 = ns + "्य"
except KeyError:
ns = s
if s[-1] in svar:
ns1 = ns[0:-1] + "िक"
ns2 = ns[0:-1] + "ी"
ns3 = ns[0:-1] + "्य"
else:
ns1 = ns + "िक"
ns2 = ns + "ी"
ns3 = ns + "्य"
return (ns1, ns2, ns3)
sanskrit_expand('नगर')
# returns ('नागरिक', 'नागरी', 'नागर्य')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment