deshanksuman commited on
Commit
64766e7
1 Parent(s): 4010517

Upload 3 files

Browse files

The files been uploaded.

Files changed (3) hide show
  1. TranslaterLogic.py +276 -0
  2. Transliterator.py +23 -0
  3. trigramTrans.pickle +3 -0
TranslaterLogic.py ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ nVowels =26
3
+ # 46
4
+ consonants = []
5
+ consonantsUni = []
6
+
7
+ # 26
8
+ vowels = []
9
+ vowelsUni = []
10
+ vowelModifiersUni = []
11
+
12
+ # 6
13
+ specialConsonants = []
14
+ specialConsonantsUni = []
15
+ # 2
16
+ specialCharUni = []
17
+ specialChar = []
18
+
19
+
20
+ def initializeVar():
21
+
22
+ vowelsUni.append("ඌ")
23
+ vowels.append("oo")
24
+ vowelModifiersUni.append("ූ")
25
+
26
+ vowelsUni.append("ඕ")
27
+ vowels.append("o\\)")
28
+ vowelModifiersUni.append("ෝ")
29
+ vowelsUni.append("ඕ")
30
+ vowels.append("oe")
31
+ vowelModifiersUni.append("ෝ")
32
+ vowelsUni.append("ආ")
33
+ vowels.append("aa")
34
+ vowelModifiersUni.append("ා")
35
+ vowelsUni.append("ආ")
36
+ vowels.append("a\\)")
37
+ vowelModifiersUni.append("ා")
38
+ vowelsUni.append("ඈ")
39
+ vowels.append("Aa")
40
+ vowelModifiersUni.append("ෑ")
41
+ vowelsUni.append("ඈ")
42
+ vowels.append("A\\)")
43
+ vowelModifiersUni.append("ෑ")
44
+ vowelsUni.append("ඈ")
45
+ vowels.append("ae")
46
+ vowelModifiersUni.append("ෑ")
47
+ vowelsUni.append("ඊ")
48
+ vowels.append("ii")
49
+ vowelModifiersUni.append("ී")
50
+ vowelsUni.append("ඊ")
51
+ vowels.append("i\\)")
52
+ vowelModifiersUni.append("ී")
53
+ vowelsUni.append("ඊ")
54
+ vowels.append("ie")
55
+ vowelModifiersUni.append("ී")
56
+ vowelsUni.append("ඊ")
57
+ vowels.append("ee")
58
+ vowelModifiersUni.append("ී")
59
+ vowelsUni.append("ඒ")
60
+ vowels.append("ea")
61
+ vowelModifiersUni.append("ේ")
62
+ vowelsUni.append("ඒ")
63
+ vowels.append("e\\)")
64
+ vowelModifiersUni.append("ේ")
65
+ vowelsUni.append("ඒ")
66
+ vowels.append("ei")
67
+ vowelModifiersUni.append("ේ")
68
+ vowelsUni.append("ඌ")
69
+ vowels.append("uu")
70
+ vowelModifiersUni.append("ූ")
71
+ vowelsUni.append("ඌ")
72
+ vowels.append("u\\)")
73
+ vowelModifiersUni.append("ූ")
74
+
75
+ vowelsUni.append("ඖ")
76
+ vowels.append("au")
77
+ vowelModifiersUni.append("ෞ")
78
+
79
+ vowelsUni.append("ඇ")
80
+ vowels.append("\\a")
81
+ vowelModifiersUni.append("ැ")
82
+
83
+ vowelsUni.append("අ")
84
+ vowels.append("a")
85
+ vowelModifiersUni.append("")
86
+
87
+ vowelsUni.append("ඇ")
88
+ vowels.append("A")
89
+ vowelModifiersUni.append("ැ")
90
+ vowelsUni.append("ඉ")
91
+ vowels.append("i")
92
+ vowelModifiersUni.append("ි")
93
+ vowelsUni.append("එ")
94
+ vowels.append("e")
95
+ vowelModifiersUni.append("ෙ")
96
+ vowelsUni.append("උ")
97
+ vowels.append("u")
98
+ vowelModifiersUni.append("ු")
99
+ vowelsUni.append("ඔ")
100
+ vowels.append("o")
101
+ vowelModifiersUni.append("ො")
102
+ vowelsUni.append("ඓ")
103
+ vowels.append("I")
104
+ vowelModifiersUni.append("ෛ")
105
+
106
+ specialConsonantsUni.append("ං")
107
+ specialConsonants.append("\\n")
108
+
109
+ specialConsonantsUni.append("ඃ")
110
+ specialConsonants.append("\\h")
111
+ specialConsonantsUni.append("ඞ")
112
+ specialConsonants.append("\\N")
113
+ specialConsonantsUni.append("ඍ")
114
+ specialConsonants.append("\\R")
115
+ # special characher Repaya
116
+ specialConsonantsUni.append("ර්"+"\u200D")
117
+ specialConsonants.append("R")
118
+ specialConsonantsUni.append("ර්"+"\u200D")
119
+ specialConsonants.append("\\r")
120
+
121
+ consonantsUni.append("ඬ")
122
+ consonants.append("nnd")
123
+
124
+ consonantsUni.append("ඳ")
125
+ consonants.append("nndh")
126
+
127
+ consonantsUni.append("ඟ")
128
+ consonants.append("nng")
129
+
130
+ consonantsUni.append("ත")
131
+ consonants.append("th")
132
+
133
+ consonantsUni.append("ධ")
134
+ consonants.append("dh")
135
+ consonantsUni.append("ඝ")
136
+ consonants.append("gh")
137
+ consonantsUni.append("ච")
138
+ consonants.append("ch")
139
+ consonantsUni.append("ඵ")
140
+ consonants.append("ph")
141
+ consonantsUni.append("භ")
142
+ consonants.append("bh")
143
+ consonantsUni.append("ඣ")
144
+ consonants.append("jh")
145
+ consonantsUni.append("ෂ")
146
+ consonants.append("sh")
147
+ consonantsUni.append("ඥ")
148
+ consonants.append("GN")
149
+ consonantsUni.append("ඤ")
150
+ consonants.append("KN")
151
+ consonantsUni.append("ළු")
152
+ consonants.append("Lu")
153
+ consonantsUni.append("ඛ")
154
+ consonants.append("kh")
155
+ consonantsUni.append("ඨ")
156
+ consonants.append("Th")
157
+ consonantsUni.append("ඪ")
158
+ consonants.append("Dh")
159
+ consonantsUni.append("ශ")
160
+ consonants.append("S")
161
+ consonantsUni.append("ද")
162
+ consonants.append("d")
163
+ consonantsUni.append("ච")
164
+ consonants.append("c")
165
+ consonantsUni.append("ත")
166
+ consonants.append("th")
167
+ consonantsUni.append("ට")
168
+ consonants.append("t")
169
+ consonantsUni.append("ක")
170
+ consonants.append("k")
171
+ consonantsUni.append("ඩ")
172
+ consonants.append("D")
173
+ consonantsUni.append("න")
174
+ consonants.append("n")
175
+ consonantsUni.append("ප")
176
+ consonants.append("p")
177
+ consonantsUni.append("බ")
178
+ consonants.append("b")
179
+ consonantsUni.append("ම")
180
+ consonants.append("m")
181
+ consonantsUni.append("‍ය")
182
+ consonants.append("\\u005C" + "y")
183
+ consonantsUni.append("‍ය")
184
+ consonants.append("Y")
185
+ consonantsUni.append("ය")
186
+ consonants.append("y")
187
+ consonantsUni.append("ජ")
188
+ consonants.append("j")
189
+ consonantsUni.append("ල")
190
+ consonants.append("l")
191
+ consonantsUni.append("ව")
192
+ consonants.append("v")
193
+ consonantsUni.append("ව")
194
+ consonants.append("w")
195
+ consonantsUni.append("ස")
196
+ consonants.append("s")
197
+ consonantsUni.append("හ")
198
+ consonants.append("h")
199
+ consonantsUni.append("ණ")
200
+ consonants.append("N")
201
+ consonantsUni.append("ළ")
202
+ consonants.append("L")
203
+ consonantsUni.append("ඛ")
204
+ consonants.append("K")
205
+ consonantsUni.append("ඝ")
206
+ consonants.append("G")
207
+ consonantsUni.append("ඵ")
208
+ consonants.append("P")
209
+ consonantsUni.append("ඹ")
210
+ consonants.append("B")
211
+ consonantsUni.append("ෆ")
212
+ consonants.append("f")
213
+ consonantsUni.append("ග")
214
+ consonants.append("g")
215
+ # last because we need to ommit this in dealing with Rakaransha
216
+ consonantsUni.append("ර")
217
+ consonants.append("r")
218
+ specialCharUni.append("ෲ")
219
+ specialChar.append("ruu")
220
+ specialCharUni.append("ෘ")
221
+ specialChar.append("ru")
222
+ # specialCharUni[2]="්‍ර" specialChar[2]="ra"
223
+
224
+ initializeVar()
225
+
226
+ def convertText(text):
227
+ s=""
228
+ r=""
229
+ v=""
230
+ # text = document.txtBox.box1.value;
231
+ # special consonents
232
+ for i in range(len(specialConsonants)):
233
+ text = text.replace(specialConsonants[i], specialConsonantsUni[i])
234
+ # consonents + special Chars
235
+ for i in range(len(specialCharUni)):
236
+ for j in range(len(consonants)):
237
+ s = consonants[j] + specialChar[i]
238
+ v = consonantsUni[j] + specialCharUni[i]
239
+ # r = new RegExp(s, "g")
240
+ r = s.replace(s+"/G", "")
241
+ text = text.replace(r, v)
242
+
243
+ # consonants + Rakaransha + vowel modifiers
244
+ for j in range(len(consonants)):
245
+ for i in range(len(vowels)):
246
+ s = consonants[j] + "r" + vowels[i]
247
+ v = consonantsUni[j] + "්‍ර" + vowelModifiersUni[i]
248
+ # r = new RegExp(s, "g")
249
+ r = s.replace(s+"/G", "")
250
+ text = text.replace(r, v)
251
+ s = consonants[j] + "r"
252
+ v = consonantsUni[j] + "්‍ර"
253
+ # r = new RegExp(s, "g")
254
+ r = s.replace(s+"/G", "")
255
+ text = text.replace(r, v)
256
+ # consonents + vowel modifiers
257
+ for i in range(len(consonants)):
258
+ for j in range(nVowels):
259
+ s = consonants[i] + vowels[j]
260
+ v = consonantsUni[i] + vowelModifiersUni[j]
261
+ # r = new RegExp(s, "g")
262
+ r = s.replace(s+"/G", "")
263
+ text = text.replace(r, v)
264
+
265
+ # consonents + HAL
266
+ for i in range(len(consonants)):
267
+ r = consonants[i].replace(consonants[i]+"/G", "")
268
+ text = text.replace(r, consonantsUni[i] + "්")
269
+ # vowels
270
+ for i in range(len(vowels)):
271
+ # r = new RegExp(vowels[i], "g")
272
+ r = vowels[i].replace(vowels[i]+"/G", "")
273
+ text = text.replace(r, vowelsUni[i])
274
+
275
+ return text
276
+
Transliterator.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ import nltk
3
+ import TranslaterLogic
4
+
5
+ translatorPic = open("trigramTrans.pickle", "rb")
6
+ translator = pickle.load(translatorPic)
7
+
8
+ def triGramTranslate(sentence):
9
+ sentence_romanized=sentence.split(" ")
10
+ translation = ""
11
+ translated = translator.tag(nltk.word_tokenize(sentence.lower()))
12
+ print(translated)
13
+ i=-1
14
+ for word, trans in translated:
15
+ i+=1
16
+ if trans in ('NNN'):
17
+ translation = translation + str(TranslaterLogic.convertText(str(sentence_romanized[i])) + " ")
18
+ else:
19
+ translation = translation + str(trans + " ")
20
+ return translation
21
+
22
+ inputStr=input("Enter the input")
23
+ print(triGramTranslate(inputStr))
trigramTrans.pickle ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ad177fa31545923ab983f2d7eae186ccb7f0eee1ac36f8fadd8f77485d01a4b
3
+ size 397988884