Datasets:
Tasks:
Translation
Modalities:
Text
Formats:
parquet
Languages:
Sinhala
Size:
1M - 10M
ArXiv:
Tags:
transliteration
License:
Upload Transliterator.py
Browse files- Transliterator.py +483 -0
Transliterator.py
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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u"ආ", u"ඇ", u"ඈ", u"ඉ", u"ඊ", u"උ", u"ඌ", u"ඍ", u"ඎ", u"ඏ", u"ඐ", u"එ", u"ඒ", u"ඓ", u"ඔ", u"ඕ", u"ඖ"]
|
| 3 |
+
sripali_list = [u"ං",u"ඃ",u"්",u"ා",u"ැ",u"ෑ",u"ි",u"ී",u"ු",u"ූ",u"ෘ",u"ෙ",u"ේ",u"ෛ",u"ො",u"ෝ",u"ෞ",u"ෟ",u"ෲ",u"ෳ","\u200d"]
|
| 4 |
+
big_list = vowel_list + sripali_list
|
| 5 |
+
|
| 6 |
+
special_character_list = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ":", ";", ".", "-", ",", "/", " ", "\n"] #*** cant inseart u"\" to here ??? :o
|
| 7 |
+
|
| 8 |
+
unwanted_symbols = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
|
| 9 |
+
unwanted_symbols = unwanted_symbols + ["~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "=", "[", "]", "{", "}", "|", " ", "?", "<", ">"]
|
| 10 |
+
|
| 11 |
+
def transliterate(self):
|
| 12 |
+
sin_text = self
|
| 13 |
+
|
| 14 |
+
#remove english and unwanted symbols
|
| 15 |
+
sin_text_temp_list = list(sin_text)
|
| 16 |
+
sin_text_list = [x for x in sin_text_temp_list if x not in unwanted_symbols]
|
| 17 |
+
#print("original is: ", sin_text_temp_list)
|
| 18 |
+
#print("unwanted symbols removed list is ", sin_text_list)
|
| 19 |
+
sin_text = "".join(sin_text_list)
|
| 20 |
+
#print("unwanted symbols removed sin_text is ", sin_text)
|
| 21 |
+
#print(type(sin_text))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
#call convert_to_phoneme function and get the halfly transliterated string
|
| 25 |
+
mapped_text_list = convert_to_phoneme(sin_text)
|
| 26 |
+
#print("mapped text list: ",mapped_text_list)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
a_inserted_list = insert_a(sin_text_list, mapped_text_list)
|
| 30 |
+
#print( "a inserted phoneme string:", a_inserted_list)
|
| 31 |
+
#print("\n")
|
| 32 |
+
|
| 33 |
+
singlish_list = phoneme_to_english(a_inserted_list)
|
| 34 |
+
#print("singlish list", singlish_list)
|
| 35 |
+
singlish_word=""
|
| 36 |
+
for i in singlish_list:
|
| 37 |
+
singlish_word+=i
|
| 38 |
+
#print(singlish_word)
|
| 39 |
+
return singlish_word
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
file = open("address.txt","w")
|
| 44 |
+
file.write("".join(singlish_list))
|
| 45 |
+
|
| 46 |
+
def convert_to_phoneme(word):
|
| 47 |
+
word_in_phoneme_list = []
|
| 48 |
+
for letter in word:
|
| 49 |
+
if letter == u"ං":
|
| 50 |
+
word_in_phoneme_list.append(u'ŋ')
|
| 51 |
+
if letter == u"ඃ":
|
| 52 |
+
word_in_phoneme_list.append(u'h')
|
| 53 |
+
if letter == u"අ":
|
| 54 |
+
word_in_phoneme_list.append(u'a')
|
| 55 |
+
if letter == u"ආ":
|
| 56 |
+
word_in_phoneme_list.append(u'a:')
|
| 57 |
+
if letter == u"ඇ":
|
| 58 |
+
word_in_phoneme_list.append(u'æ')
|
| 59 |
+
if letter == u"ඈ":
|
| 60 |
+
word_in_phoneme_list.append(u'æ:')
|
| 61 |
+
if letter == u"ඉ":
|
| 62 |
+
word_in_phoneme_list.append(u'i')
|
| 63 |
+
if letter == u"ඊ":
|
| 64 |
+
word_in_phoneme_list.append(u'i:')
|
| 65 |
+
if letter == u"උ":
|
| 66 |
+
word_in_phoneme_list.append(u'u')
|
| 67 |
+
if letter == u"ඌ":
|
| 68 |
+
word_in_phoneme_list.append(u'u:')
|
| 69 |
+
if letter == u"ඍ":
|
| 70 |
+
word_in_phoneme_list.append(u'ri')
|
| 71 |
+
if letter == u"ඎ":
|
| 72 |
+
word_in_phoneme_list.append(u'ru:')
|
| 73 |
+
if letter == u"ඏ":
|
| 74 |
+
word_in_phoneme_list.append(u'ilu')
|
| 75 |
+
if letter == u"ඐ":
|
| 76 |
+
word_in_phoneme_list.append(u'ilu:')
|
| 77 |
+
if letter == u"එ":
|
| 78 |
+
word_in_phoneme_list.append(u'e')
|
| 79 |
+
if letter == u"ඒ":
|
| 80 |
+
word_in_phoneme_list.append(u'e:')
|
| 81 |
+
if letter == u"ඓ":
|
| 82 |
+
word_in_phoneme_list.append(u'ai')
|
| 83 |
+
if letter == u"ඔ":
|
| 84 |
+
word_in_phoneme_list.append(u'o')
|
| 85 |
+
if letter == u"ඕ":
|
| 86 |
+
word_in_phoneme_list.append(u'o:')
|
| 87 |
+
if letter == u"ඖ":
|
| 88 |
+
word_in_phoneme_list.append(u'ou')
|
| 89 |
+
if letter == u"ක":
|
| 90 |
+
word_in_phoneme_list.append(u'k')
|
| 91 |
+
if letter == u"ඛ":
|
| 92 |
+
word_in_phoneme_list.append(u'k')
|
| 93 |
+
if letter == u"ග":
|
| 94 |
+
word_in_phoneme_list.append(u'ɡ')
|
| 95 |
+
if letter == u"ඝ":
|
| 96 |
+
word_in_phoneme_list.append(u'ɡ_')
|
| 97 |
+
if letter == u"ඞ":
|
| 98 |
+
word_in_phoneme_list.append(u'ŋ')
|
| 99 |
+
if letter == u"ඟ":
|
| 100 |
+
word_in_phoneme_list.append(u'ɠ') # *** n දැමිය යුතු සඤ්ඥක අකුරක්
|
| 101 |
+
if letter == u"ච":
|
| 102 |
+
word_in_phoneme_list.append(u'c')
|
| 103 |
+
if letter == u"ඡ":
|
| 104 |
+
word_in_phoneme_list.append(u'c')
|
| 105 |
+
if letter == u"ජ":
|
| 106 |
+
word_in_phoneme_list.append(u'ɟ')
|
| 107 |
+
if letter == u"ඣ":
|
| 108 |
+
word_in_phoneme_list.append(u'ɟh')
|
| 109 |
+
if letter == u"ඤ":
|
| 110 |
+
word_in_phoneme_list.append(u'ɲ')
|
| 111 |
+
if letter == u"ඥ":
|
| 112 |
+
word_in_phoneme_list.append(u'jɲ')
|
| 113 |
+
if letter == u"ඦ":
|
| 114 |
+
word_in_phoneme_list.append(u'ʄ') # *** n දැමිය යුතු සඤ්ඥක අකුරක් - ඉඦු ඉඦු one an only word in sinhala that has ඦ
|
| 115 |
+
if letter == u"ට":
|
| 116 |
+
word_in_phoneme_list.append(u'ʈ')
|
| 117 |
+
if letter == u"ඨ":
|
| 118 |
+
word_in_phoneme_list.append(u'ʈ')
|
| 119 |
+
if letter == u"ඩ":
|
| 120 |
+
word_in_phoneme_list.append(u'ɖ')
|
| 121 |
+
if letter == u"ඪ":
|
| 122 |
+
word_in_phoneme_list.append(u'ɖ')
|
| 123 |
+
if letter == u"න":
|
| 124 |
+
word_in_phoneme_list.append(u'n')
|
| 125 |
+
if letter == u"ණ":
|
| 126 |
+
word_in_phoneme_list.append(u'n')
|
| 127 |
+
if letter == u"ඬ":
|
| 128 |
+
word_in_phoneme_list.append(u'ɖ_') # *** n දැමිය යුතු සඤ්ඥක අකුරක්
|
| 129 |
+
if letter == u"ත":
|
| 130 |
+
word_in_phoneme_list.append(u't')
|
| 131 |
+
if letter == u"ථ":
|
| 132 |
+
word_in_phoneme_list.append(u't')
|
| 133 |
+
if letter == u"ද":
|
| 134 |
+
word_in_phoneme_list.append(u'd')
|
| 135 |
+
if letter == u"ධ":
|
| 136 |
+
word_in_phoneme_list.append(u'd_')
|
| 137 |
+
if letter == u"ඳ":
|
| 138 |
+
word_in_phoneme_list.append(u'ɗ') # *** n දැමිය යුතු සඤ්ඥක අකුරක් - e.g සඳතැන්න
|
| 139 |
+
if letter == u"ප":
|
| 140 |
+
word_in_phoneme_list.append(u'p')
|
| 141 |
+
if letter == u"ඵ":
|
| 142 |
+
word_in_phoneme_list.append(u'p')
|
| 143 |
+
if letter == u"බ":
|
| 144 |
+
word_in_phoneme_list.append(u'b')
|
| 145 |
+
if letter == u"භ":
|
| 146 |
+
word_in_phoneme_list.append(u'b_')
|
| 147 |
+
if letter == u"ම":
|
| 148 |
+
word_in_phoneme_list.append(u'm')
|
| 149 |
+
if letter == u"ඹ":
|
| 150 |
+
word_in_phoneme_list.append(u'ɓ') # *** m දැමිය යුතු සඤ්ඥක අකුර
|
| 151 |
+
if letter == u"ය":
|
| 152 |
+
word_in_phoneme_list.append(u'j')
|
| 153 |
+
if letter == u"ර":
|
| 154 |
+
word_in_phoneme_list.append(u'r')
|
| 155 |
+
if letter == u"ල":
|
| 156 |
+
word_in_phoneme_list.append(u'l')
|
| 157 |
+
if letter == u"ව":
|
| 158 |
+
word_in_phoneme_list.append(u'w')
|
| 159 |
+
if letter == u"ශ":
|
| 160 |
+
word_in_phoneme_list.append(u'ʃ')
|
| 161 |
+
if letter == u"ෂ":
|
| 162 |
+
word_in_phoneme_list.append(u'ʃ')
|
| 163 |
+
if letter == u"ස":
|
| 164 |
+
word_in_phoneme_list.append(u's')
|
| 165 |
+
if letter == u"හ":
|
| 166 |
+
word_in_phoneme_list.append(u'h')
|
| 167 |
+
if letter == u"ළ":
|
| 168 |
+
word_in_phoneme_list.append(u'l')
|
| 169 |
+
if letter == u"ෆ":
|
| 170 |
+
word_in_phoneme_list.append(u'f')
|
| 171 |
+
if letter == u"්":
|
| 172 |
+
word_in_phoneme_list.append(u'_') # **** hal symbol
|
| 173 |
+
if letter == "\u200d":
|
| 174 |
+
word_in_phoneme_list.append(u'_') # **** for rakaransaya
|
| 175 |
+
if letter == u"ා":
|
| 176 |
+
word_in_phoneme_list.append(u'a:')
|
| 177 |
+
if letter == u"ැ":
|
| 178 |
+
word_in_phoneme_list.append(u'æ')
|
| 179 |
+
if letter == u"ෑ":
|
| 180 |
+
word_in_phoneme_list.append(u'æ:')
|
| 181 |
+
if letter == u"ි":
|
| 182 |
+
word_in_phoneme_list.append(u'i')
|
| 183 |
+
if letter == u"ී":
|
| 184 |
+
word_in_phoneme_list.append(u'i:')
|
| 185 |
+
if letter == u"ු":
|
| 186 |
+
word_in_phoneme_list.append(u'u')
|
| 187 |
+
if letter == u"ූ":
|
| 188 |
+
word_in_phoneme_list.append(u'u:')
|
| 189 |
+
if letter == u"ෘ":
|
| 190 |
+
word_in_phoneme_list.append(u'ru')
|
| 191 |
+
if letter == u"ෲ":
|
| 192 |
+
word_in_phoneme_list.append(u'ru:')
|
| 193 |
+
if letter == u"ෙ":
|
| 194 |
+
word_in_phoneme_list.append(u'e')
|
| 195 |
+
if letter == u"ේ":
|
| 196 |
+
word_in_phoneme_list.append(u'e:')
|
| 197 |
+
if letter == u"ෛ":
|
| 198 |
+
word_in_phoneme_list.append(u'ai')
|
| 199 |
+
if letter == u"ො":
|
| 200 |
+
word_in_phoneme_list.append(u'o')
|
| 201 |
+
if letter == u"ෝ":
|
| 202 |
+
word_in_phoneme_list.append(u'o:')
|
| 203 |
+
if letter == u"ෞ":
|
| 204 |
+
word_in_phoneme_list.append(u'ou')
|
| 205 |
+
if letter == u"ෟ":
|
| 206 |
+
word_in_phoneme_list.append(u'ou')
|
| 207 |
+
|
| 208 |
+
if letter == u"1":
|
| 209 |
+
word_in_phoneme_list.append(u'1')
|
| 210 |
+
if letter == u"2":
|
| 211 |
+
word_in_phoneme_list.append(u'2')
|
| 212 |
+
if letter == u"3":
|
| 213 |
+
word_in_phoneme_list.append(u'3')
|
| 214 |
+
if letter == u"4":
|
| 215 |
+
word_in_phoneme_list.append(u'4')
|
| 216 |
+
if letter == u"5":
|
| 217 |
+
word_in_phoneme_list.append(u'5')
|
| 218 |
+
if letter == u"6":
|
| 219 |
+
word_in_phoneme_list.append(u'6')
|
| 220 |
+
if letter == u"7":
|
| 221 |
+
word_in_phoneme_list.append(u'7')
|
| 222 |
+
if letter == u"8":
|
| 223 |
+
word_in_phoneme_list.append(u'8')
|
| 224 |
+
if letter == u"9":
|
| 225 |
+
word_in_phoneme_list.append(u'9')
|
| 226 |
+
if letter == u"0":
|
| 227 |
+
word_in_phoneme_list.append(u'0')
|
| 228 |
+
if letter == u".":
|
| 229 |
+
word_in_phoneme_list.append(u'.')
|
| 230 |
+
if letter == u"-":
|
| 231 |
+
word_in_phoneme_list.append(u'-')
|
| 232 |
+
if letter == u"/":
|
| 233 |
+
word_in_phoneme_list.append(u'/')
|
| 234 |
+
if letter == u" ":
|
| 235 |
+
word_in_phoneme_list.append(u' ')
|
| 236 |
+
if letter == u",":
|
| 237 |
+
word_in_phoneme_list.append(u',')
|
| 238 |
+
if letter == u"\n":
|
| 239 |
+
word_in_phoneme_list.append(u'\n')
|
| 240 |
+
if letter == u":":
|
| 241 |
+
word_in_phoneme_list.append(u':')
|
| 242 |
+
if letter == u";":
|
| 243 |
+
word_in_phoneme_list.append(u':')
|
| 244 |
+
# word_in_phoneme = "".join(word_in_phoneme) #converting to string
|
| 245 |
+
return word_in_phoneme_list
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def insert_a(sin_text_list, mapped_text_list):
|
| 249 |
+
sin_text_list.append("_") # Append a dummy non effecting symbol at end of sin_text_list to overcome error of length mis match of occuring in rule 2)
|
| 250 |
+
a_inserted_list = []
|
| 251 |
+
|
| 252 |
+
for i, letter in enumerate(mapped_text_list):
|
| 253 |
+
a_inserted_list.append(letter)
|
| 254 |
+
|
| 255 |
+
# rule 1 : dont insert /a/ after a wovel phoneme representative
|
| 256 |
+
if sin_text_list[i] in big_list:
|
| 257 |
+
continue
|
| 258 |
+
|
| 259 |
+
# rule 2 : don't insert /a/ after a phoneme symbol, if the next relevent symbol in sin_text_list is in sripali_list.
|
| 260 |
+
elif sin_text_list[i+1] in sripali_list:
|
| 261 |
+
if sin_text_list[i+1] == u"ං": #to handle special cases like පංචිකාවත්ත where ං is just after a consonent
|
| 262 |
+
a_inserted_list.append('a')
|
| 263 |
+
continue
|
| 264 |
+
|
| 265 |
+
# handdle spaces, commas and new line characters
|
| 266 |
+
elif letter in special_character_list:
|
| 267 |
+
continue
|
| 268 |
+
|
| 269 |
+
# rule 3 : if the letter is not filtered by above rules, then append /a/
|
| 270 |
+
else:
|
| 271 |
+
a_inserted_list.append('a')
|
| 272 |
+
|
| 273 |
+
return a_inserted_list
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
def phoneme_to_english(word):
|
| 277 |
+
word_in_singlish = []
|
| 278 |
+
for letter in word:
|
| 279 |
+
|
| 280 |
+
if letter == u"ɖ_":
|
| 281 |
+
word_in_singlish.append(u'nd') # *** සඤ්ඥක අකුරු, so inseart n prior
|
| 282 |
+
|
| 283 |
+
if letter == u"ɠ":
|
| 284 |
+
word_in_singlish.append(u'ng') # *** සඤ්ඥක අකුරු, so inseart n prior
|
| 285 |
+
|
| 286 |
+
if letter == u"ɗ":
|
| 287 |
+
word_in_singlish.append(u'nd') # *** සඤ්ඥක අකුරු, so inseart n prior
|
| 288 |
+
|
| 289 |
+
if letter == u"ʄ":
|
| 290 |
+
word_in_singlish.append(u'nj') # *** සඤ්ඥක අකුරු, so inseart n prior
|
| 291 |
+
|
| 292 |
+
if letter == u"ɓ":
|
| 293 |
+
word_in_singlish.append(u'mb') # *** සඤ්ඥක අකුරු, so inseart n prior
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
if letter == u"d_":
|
| 297 |
+
word_in_singlish.append(u'dh') # *** mahapprana d_ -> dh
|
| 298 |
+
|
| 299 |
+
if letter == u"b_":
|
| 300 |
+
word_in_singlish.append(u'bh') # *** mahapprana b -> bh
|
| 301 |
+
|
| 302 |
+
if letter == u"ɡ_":
|
| 303 |
+
word_in_singlish.append(u'gh') # *** mahapprana g_ -> gh
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
if letter == u"ŋ":
|
| 307 |
+
word_in_singlish.append(u'n') #some times to "ng"
|
| 308 |
+
continue;
|
| 309 |
+
if letter == u"h":
|
| 310 |
+
word_in_singlish.append(u'h')
|
| 311 |
+
continue
|
| 312 |
+
if letter == u"a":
|
| 313 |
+
word_in_singlish.append(u'a') #vowel
|
| 314 |
+
if letter == u"a:":
|
| 315 |
+
word_in_singlish.append(u'a') #vowel
|
| 316 |
+
if letter == u"æ":
|
| 317 |
+
word_in_singlish.append(u'e') #This is special case. although it should be "a", in singlish we use "e"
|
| 318 |
+
# For example ඇල්ල -> Ella
|
| 319 |
+
if letter == u"æ:":
|
| 320 |
+
word_in_singlish.append(u'e') # කුරුණෑගල -> kurunEgala
|
| 321 |
+
if letter == u"i":
|
| 322 |
+
word_in_singlish.append(u'i')
|
| 323 |
+
if letter == u"i:":
|
| 324 |
+
word_in_singlish.append(u'ee') #some times "ea"
|
| 325 |
+
if letter == u"u":
|
| 326 |
+
word_in_singlish.append(u'u')
|
| 327 |
+
|
| 328 |
+
if letter == u"u:":
|
| 329 |
+
word_in_singlish.append(u'u') # some times "ue"
|
| 330 |
+
if letter == u"ri":
|
| 331 |
+
word_in_singlish.append(u'ri')
|
| 332 |
+
if letter == u"ru:":
|
| 333 |
+
word_in_singlish.append(u'ruu')
|
| 334 |
+
if letter == u"ilu":
|
| 335 |
+
word_in_singlish.append(u'ilu')
|
| 336 |
+
if letter == u"ilu:":
|
| 337 |
+
word_in_singlish.append(u'ilue')
|
| 338 |
+
if letter == u"e":
|
| 339 |
+
word_in_singlish.append(u'e')
|
| 340 |
+
if letter == u"e:":
|
| 341 |
+
word_in_singlish.append(u'e')
|
| 342 |
+
if letter == u"ai":
|
| 343 |
+
word_in_singlish.append(u'ai')
|
| 344 |
+
if letter == u"o":
|
| 345 |
+
word_in_singlish.append(u'o')
|
| 346 |
+
if letter == u"o:":
|
| 347 |
+
word_in_singlish.append(u'o') #ex: හෝමාගම -> homagama
|
| 348 |
+
if letter == u"k":
|
| 349 |
+
word_in_singlish.append(u'k')
|
| 350 |
+
continue
|
| 351 |
+
if letter == u"k":
|
| 352 |
+
word_in_singlish.append(u'k')
|
| 353 |
+
if letter == u"ɡ":
|
| 354 |
+
word_in_singlish.append(u'g')
|
| 355 |
+
if letter == u"ŋ":
|
| 356 |
+
word_in_singlish.append(u'n')
|
| 357 |
+
if letter == u"c":
|
| 358 |
+
word_in_singlish.append(u'ch')
|
| 359 |
+
continue
|
| 360 |
+
if letter == u"c":
|
| 361 |
+
word_in_singlish.append(u'ch')
|
| 362 |
+
if letter == u"ɟ":
|
| 363 |
+
word_in_singlish.append(u'j')
|
| 364 |
+
if letter == u"ɟh":
|
| 365 |
+
word_in_singlish.append(u'jh')
|
| 366 |
+
if letter == u"ɲ":
|
| 367 |
+
word_in_singlish.append(u'kn')
|
| 368 |
+
if letter == u"jɲ":
|
| 369 |
+
word_in_singlish.append(u'gn')
|
| 370 |
+
if letter == u"ʈ":
|
| 371 |
+
word_in_singlish.append(u't')
|
| 372 |
+
continue
|
| 373 |
+
if letter == u"ʈ":
|
| 374 |
+
word_in_singlish.append(u't')
|
| 375 |
+
if letter == u"ɖ":
|
| 376 |
+
word_in_singlish.append(u'd')
|
| 377 |
+
continue
|
| 378 |
+
if letter == u"ɖ":
|
| 379 |
+
word_in_singlish.append(u'd')
|
| 380 |
+
if letter == u"n":
|
| 381 |
+
word_in_singlish.append(u'n')
|
| 382 |
+
continue
|
| 383 |
+
if letter == u"n":
|
| 384 |
+
word_in_singlish.append(u'n')
|
| 385 |
+
if letter == u"t":
|
| 386 |
+
word_in_singlish.append(u'th')
|
| 387 |
+
continue
|
| 388 |
+
if letter == u"t":
|
| 389 |
+
word_in_singlish.append(u'th')
|
| 390 |
+
if letter == u"d":
|
| 391 |
+
word_in_singlish.append(u'd')
|
| 392 |
+
|
| 393 |
+
if letter == u"p":
|
| 394 |
+
word_in_singlish.append(u'p')
|
| 395 |
+
continue
|
| 396 |
+
if letter == u"p":
|
| 397 |
+
word_in_singlish.append(u'p')
|
| 398 |
+
if letter == u"b":
|
| 399 |
+
word_in_singlish.append(u'b')
|
| 400 |
+
continue
|
| 401 |
+
if letter == u"m":
|
| 402 |
+
word_in_singlish.append(u'm')
|
| 403 |
+
if letter == u"j":
|
| 404 |
+
word_in_singlish.append(u'y')
|
| 405 |
+
if letter == u"r":
|
| 406 |
+
word_in_singlish.append(u'r')
|
| 407 |
+
if letter == u"l":
|
| 408 |
+
word_in_singlish.append(u'l')
|
| 409 |
+
continue
|
| 410 |
+
if letter == u"w":
|
| 411 |
+
word_in_singlish.append(u'w')
|
| 412 |
+
if letter == u"ʃ":
|
| 413 |
+
word_in_singlish.append(u'sh')
|
| 414 |
+
continue
|
| 415 |
+
if letter == u"ʃ":
|
| 416 |
+
word_in_singlish.append(u'sh')
|
| 417 |
+
if letter == u"s":
|
| 418 |
+
word_in_singlish.append(u's')
|
| 419 |
+
if letter == u"h":
|
| 420 |
+
word_in_singlish.append(u'h')
|
| 421 |
+
if letter == u"l":
|
| 422 |
+
word_in_singlish.append(u'l')
|
| 423 |
+
if letter == u"f":
|
| 424 |
+
word_in_singlish.append(u'f')
|
| 425 |
+
if letter == u"_ ":
|
| 426 |
+
word_in_singlish.append(u'_')
|
| 427 |
+
|
| 428 |
+
if letter == u"ou":
|
| 429 |
+
word_in_singlish.append(u'au')
|
| 430 |
+
continue
|
| 431 |
+
if letter == u"ru:":
|
| 432 |
+
word_in_singlish.append(u'ru')
|
| 433 |
+
|
| 434 |
+
if letter == u"1":
|
| 435 |
+
word_in_singlish.append(u'1')
|
| 436 |
+
if letter == u"2":
|
| 437 |
+
word_in_singlish.append(u'2')
|
| 438 |
+
if letter == u"3":
|
| 439 |
+
word_in_singlish.append(u'3')
|
| 440 |
+
if letter == u"4":
|
| 441 |
+
word_in_singlish.append(u'4')
|
| 442 |
+
if letter == u"5":
|
| 443 |
+
word_in_singlish.append(u'5')
|
| 444 |
+
if letter == u"6":
|
| 445 |
+
word_in_singlish.append(u'6')
|
| 446 |
+
if letter == u"7":
|
| 447 |
+
word_in_singlish.append(u'7')
|
| 448 |
+
if letter == u"8":
|
| 449 |
+
word_in_singlish.append(u'8')
|
| 450 |
+
if letter == u"9":
|
| 451 |
+
word_in_singlish.append(u'9')
|
| 452 |
+
if letter == u"0":
|
| 453 |
+
word_in_singlish.append(u'0')
|
| 454 |
+
if letter == u".":
|
| 455 |
+
word_in_singlish.append(u'.')
|
| 456 |
+
if letter == u"-":
|
| 457 |
+
word_in_singlish.append(u'-')
|
| 458 |
+
if letter == u"/":
|
| 459 |
+
word_in_singlish.append(u'/')
|
| 460 |
+
if letter == u" ":
|
| 461 |
+
word_in_singlish.append(u' ')
|
| 462 |
+
if letter == u",":
|
| 463 |
+
word_in_singlish.append(u',')
|
| 464 |
+
if letter == u"\n":
|
| 465 |
+
word_in_singlish.append(u'\n')
|
| 466 |
+
if letter == u":":
|
| 467 |
+
word_in_singlish.append(u':')
|
| 468 |
+
if letter == u";":
|
| 469 |
+
word_in_singlish.append(u':')
|
| 470 |
+
|
| 471 |
+
return word_in_singlish
|
| 472 |
+
|
| 473 |
+
file= open("Sinhala_tweets_non_depression.csv","r",encoding='utf-8')
|
| 474 |
+
file2= open("RomanizedSinhala_Sinhala_Non_Depression_Tweets.txt","a",encoding='utf-8')
|
| 475 |
+
|
| 476 |
+
for i in file:
|
| 477 |
+
word=transliterate(i)
|
| 478 |
+
print(word)
|
| 479 |
+
file2.write(word)
|
| 480 |
+
file.close()
|
| 481 |
+
file2.close()
|
| 482 |
+
|
| 483 |
+
|