예제 #1
0
def shloka_filler(element, content):
    text_in_shloka = element["content"]
    if len(text_in_shloka) > 1:     # to avoid the single "["
        content["shloka"] += delimiter_for_join(content["shloka"]) +\
                             text_in_shloka
        content["devanagri"] += delimiter_for_join(content["devanagri"]) +\
                               translit.gita_to_devanagari(text_in_shloka)
    return content
예제 #2
0
def style_translits(text_to_style):
    styled = ''
    tokens_in_xlat = re.split(r'(\[[^\[]+\])', text_to_style)
    for token in tokens_in_xlat:
        if token.startswith('['):
            token = token[1:-1]
            token = span('transliteration', token) +\
                    span('sanskrit', translit.gita_to_devanagari(token))
        styled += token
    return styled
예제 #3
0
def expln_to_meanings(explnline):
  explnseq = [x.strip() for x in re.split('(\[[^\]]*\])', explnline) if x]
  meaningitems = []
  for phrase in explnseq:
    if phrase.startswith('['):
      devanagari = translit.gita_to_devanagari(no_sq_encl(phrase))
      meaningitems.append(f'`{devanagari}` `{translit.to_harward_kyoto(phrase)}`')
    else:
      meaningitems.append(phrase.strip())
  return ' '.join(meaningitems)
예제 #4
0
def tokenize_translits(text_to_style):
    translits = []
    translation = {}
    tokens_in_xlat = re.split(r'(\[[^\[]+\])', text_to_style)
    for token in filter_blanks(tokens_in_xlat):
        if token.startswith('['):
            token = token[1:-1]
            translation['english'] = token
            translation['sanskrit'] = translit.gita_to_devanagari(token)
        else:
            translation['translate'] = token
            translits.append(translation)
            translation = {}
    return translits
예제 #5
0
 def test_Gita_is_converted_to_devanagari(self):
     expected_mapping = {
         "siddhayE": "सिद्धये",
         "sanga": "सङ्ग",
         "shankha": "शङ्ख",
         "karmaNa:": "कर्मणः",
         "kr`ShNa": "कृष्ण",
         "vartana": "वर्तन",
         "sanga karmaNa: vartana": "सङ्ग कर्मणः वर्तन",
         "ichChA": "इच्छा",
         "prakr'tisthO": "प्रकृतिस्थो",
         "bhunktE": "भुङ्क्ते",
         "saMjnai": "संज्ञै",
         "sO_mr`tatvAya": "सोऽमृतत्वाय",
         "yajna": "यज्ञ",
         "swadharmE": "स्वधर्मे"
     }
     for transliterated in expected_mapping:
         self.assertEqual(expected_mapping[transliterated],
                          translit.gita_to_devanagari(transliterated))