can you keep this full script as is and just add and account for any special character…
- User
can you keep this full script as is and just add and account for any special character it might encounter in hindi ? like for words like रीब्रांड it took half b and full ra with aa ki matra which is wrong then here on words like ट्विटर only for ट् it dominates in ट्वि as you can see there are lots of special interaction or special cases in hindi and i want you to account for as much of these as you can in this script by adding something like ब्र is krutidev and also for as much as special cases as you can like for ट्व etc...
"import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties from PIL import Image, ImageDraw, ImageFont from datetime import datetime, timedelta import pandas as pd import os import re import io
class UnicodeToKrutidev: def init(self): # Unicode to Krutidev mapping self.unicode_to_krutidev = { "'": "^", "'": "*", """: "Þ", """: "ß", "(": "¼", ")": "½", "{": "¿", "}": "À", "=": "¾", "।": "A", "?": "\", "-": "&", "µ": "&", "॰": "Œ", ",": "]", ".": "-", "०": "å", "१": "ƒ", "२": "„", "३": "…", "४": "†", "५": "‡", "६": "ˆ", "७": "‰", "८": "Š", "९": "‹", "x": "Û", "फ़्": "¶", "क़": "d", "ख़": "[k", "ग़": "x", "ज़्": "T", "ज़": "t", "ड़": "M+", "ढ़": "<+", "फ़": "Q", "य़": ";", "ऱ": "j", "ऩ": "u", "त्त्": "Ù", "त्त": "Ùk", "क्त": "Dr", "दृ": "–", "कृ": "—", "ह्न": "à", "ह्य": "á", "हृ": "â", "ह्म": "ã", "ह्र": "ºz", "ह्": "º", "द्द": "í", "क्ष्": "{", "क्ष": "{k", "त्र्": "«", "त्र": "=", "ज्ञ": "K", "छ्य": "Nî", "ट्य": "Vî", "ठ्य": "Bî", "ड्य": "Mî", "ढ्य": "<î", "द्य": "|", "द्व": "}", "श्र": "J", "ट्र": "Vª", "ड्र": "Mª", "ढ्र": "<ªª", "छ्र": "Nª", "क्र": "Ø", "फ्र": "Ý", "द्र": "æ", "प्र": "ç", "ग्र": "xz", "रु": "#", "रू": ":", "्र": "z", "ओ": "vks", "औ": "vkS", "आ": "vk", "अ": "v", "ई": "bZ", "इ": "b", "उ": "m", "ऊ": "Å", "ऐ": ",s", "ए": ",", "ऋ": "_", "क्": "D", "क": "d", "क्क": "ô", "ख्": "[", "ख": "[k", "ग्": "X", "ग": "x", "घ्": "?", "घ": "?k", "ङ": "³", "चै": "pkS", "च्": "P", "च": "p", "छ": "N", "ज्": "T", "ज": "t", "झ्": "÷", "झ": ">", "ञ": "¥", "ट्ट": "ê", "ट्ठ": "ë", "ट": "V", "ठ": "B", "ड्ड": "ì", "ड्ढ": "ï", "ड": "M", "ढ": "<", "ण्": ".", "ण": ".k", "त्": "R", "त": "r", "थ्": "F", "थ": "Fk", "द्ध": ")", "द": "n", "ध्": "/", "ध": "/k", "न्": "U", "न": "u", "प्": "I", "प": "i", "फ्": "¶", "फ": "Q", "ब्": "C", "ब": "c", "भ्": "H", "भ": "Hk", "म्": "E", "म": "e", "य्": "¸", "य": ";", "र": "j", "ल्": "Y", "ल": "y", "ळ": "G", "व्": "O", "व": "o", "श्": "'", "श": "'k", "ष्": """, "ष": ""k", "स्": "L", "स": "l", "ह": "g", "ऑ": "v‚", "ॉ": "‚", "ो": "ks", "ौ": "kS", "ा": "k", "ी": "h", "ु": "q", "ू": "w", "ृ": "`", "े": "s", "ै": "S", "ं": "a", "ँ": "¡", "ः": "%", "ॅ": "W", "ऽ": "·", "\u094D": "~" }
self.matras = { "ा", "ि", "ी", "ु", "ू", "ृ", "े", "ै", "ो", "ौ", "ं", "ः", "ँ", "ॅ", "ॉ", ":", "\u0901", "\u0902", "\u093E", "\u093F", "\u0940", "\u0941", "\u0942", "\u0943", "\u0945", "\u0947", "\u0948", "\u094B", "\u094C" } def find_next_consonant_boundary(self, chars, start): i = start i += 1 while i < len(chars) and (chars[i] in self.matras or chars[i] == "\u094D"): i += 1 return i def convert(self, text): chars = list(text) i = 0 # Handle half-र (ra) repositioning i = 0 while i < len(chars): if chars[i] == "र" and i + 1 < len(chars) and chars[i + 1] == "\u094D": next_pos = i + 2 while next_pos < len(chars) and chars[next_pos] in self.matras: next_pos += 1 if next_pos < len(chars): insert_pos = self.find_next_consonant_boundary(chars, next_pos) chars.insert(insert_pos, "Z") chars.pop(i) chars.pop(i) i = insert_pos continue i += 1 # Handle ि (vowel sign I) repositioning i = 1 while i < len(chars): if chars[i] == "ि": f_position = i j = i - 1 while j >= 0 and chars[j] == "\u094D": j -= 2 chars.pop(f_position) chars.insert(j, "f") i = f_position i += 1 # Final conversion output = [] i = 0 while i < len(chars): matched = False for length in range(4, 0, -1): if i + length <= len(chars): substring = "".join(chars[i:i + length]) if substring in self.unicode_to_krutidev: output.append(self.unicode_to_krutidev[substring]) i += length matched = True break if not matched: if chars[i] in self.unicode_to_krutidev: output.append(self.unicode_to_krutidev[chars[i]]) else: output.append(chars[i]) i += 1 return "".join(output) - Assistant