abugida 0.3.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- abugida/SERA_table.json +368 -0
- abugida/__init__.py +5 -0
- abugida/convert_calendar.py +118 -0
- abugida/convert_numeral.py +147 -0
- abugida/convert_script.py +115 -0
- abugida-0.3.4.dist-info/LICENSE +21 -0
- abugida-0.3.4.dist-info/METADATA +101 -0
- abugida-0.3.4.dist-info/RECORD +14 -0
- abugida-0.3.4.dist-info/WHEEL +5 -0
- abugida-0.3.4.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/calendar_conversion_test.py +29 -0
- tests/numeral_conversion_test.py +30 -0
- tests/script_conversion_test.py +34 -0
abugida/SERA_table.json
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ሀ": "he",
|
|
3
|
+
"ሁ": "hu",
|
|
4
|
+
"ሂ": "hi",
|
|
5
|
+
"ሃ": "ha",
|
|
6
|
+
"ሄ": "hE",
|
|
7
|
+
"ህ": "h",
|
|
8
|
+
"ሆ": "ho",
|
|
9
|
+
"ለ": "le",
|
|
10
|
+
"ሉ": "lu",
|
|
11
|
+
"ሊ": "li",
|
|
12
|
+
"ላ": "la",
|
|
13
|
+
"ሌ": "lE",
|
|
14
|
+
"ል": "l",
|
|
15
|
+
"ሎ": "lo",
|
|
16
|
+
"ሏ": "lWa",
|
|
17
|
+
"ሐ": "He",
|
|
18
|
+
"ሑ": "Hu",
|
|
19
|
+
"ሒ": "Hi",
|
|
20
|
+
"ሓ": "Ha",
|
|
21
|
+
"ሔ": "HE",
|
|
22
|
+
"ሕ": "H",
|
|
23
|
+
"ሖ": "Ho",
|
|
24
|
+
"ሗ": "HWa",
|
|
25
|
+
"መ": "me",
|
|
26
|
+
"ሙ": "mu",
|
|
27
|
+
"ሚ": "mi",
|
|
28
|
+
"ማ": "ma",
|
|
29
|
+
"ሜ": "mE",
|
|
30
|
+
"ም": "m",
|
|
31
|
+
"ሞ": "mo",
|
|
32
|
+
"ᎀ": "mWe",
|
|
33
|
+
"ᎁ": "mWi",
|
|
34
|
+
"ሟ": "mWa",
|
|
35
|
+
"ᎂ": "mWE",
|
|
36
|
+
"ᎃ": "mW",
|
|
37
|
+
"ሠ": "'se",
|
|
38
|
+
"ሡ": "'su",
|
|
39
|
+
"ሢ": "'si",
|
|
40
|
+
"ሣ": "'sa",
|
|
41
|
+
"ሤ": "'sE",
|
|
42
|
+
"ሥ": "'s",
|
|
43
|
+
"ሦ": "'so",
|
|
44
|
+
"ሧ": "'sWa",
|
|
45
|
+
"ረ": "re",
|
|
46
|
+
"ሩ": "ru",
|
|
47
|
+
"ሪ": "ri",
|
|
48
|
+
"ራ": "ra",
|
|
49
|
+
"ሬ": "rE",
|
|
50
|
+
"ር": "r",
|
|
51
|
+
"ሮ": "ro",
|
|
52
|
+
"ሯ": "rWa",
|
|
53
|
+
"ሰ": "se",
|
|
54
|
+
"ሱ": "su",
|
|
55
|
+
"ሲ": "si",
|
|
56
|
+
"ሳ": "sa",
|
|
57
|
+
"ሴ": "sE",
|
|
58
|
+
"ስ": "s",
|
|
59
|
+
"ሶ": "so",
|
|
60
|
+
"ሷ": "sWa",
|
|
61
|
+
"ሸ": "xe",
|
|
62
|
+
"ሹ": "xu",
|
|
63
|
+
"ሺ": "xi",
|
|
64
|
+
"ሻ": "xa",
|
|
65
|
+
"ሼ": "xE",
|
|
66
|
+
"ሽ": "x",
|
|
67
|
+
"ሾ": "xo",
|
|
68
|
+
"ሿ": "xWa",
|
|
69
|
+
"ቀ": "qe",
|
|
70
|
+
"ቁ": "qu",
|
|
71
|
+
"ቂ": "qi",
|
|
72
|
+
"ቃ": "qa",
|
|
73
|
+
"ቄ": "qE",
|
|
74
|
+
"ቅ": "q",
|
|
75
|
+
"ቆ": "qo",
|
|
76
|
+
"ቈ": "qWe",
|
|
77
|
+
"ቊ": "qWi",
|
|
78
|
+
"ቇ": "qWa",
|
|
79
|
+
"ቋ": "qWa",
|
|
80
|
+
"ቌ": "qWE",
|
|
81
|
+
"ቍ": "qW",
|
|
82
|
+
"ⷀ": "'qe",
|
|
83
|
+
"ⷁ": "'qu",
|
|
84
|
+
"ⷂ": "'qi",
|
|
85
|
+
"ⷃ": "'qa",
|
|
86
|
+
"ⷄ": "'qE",
|
|
87
|
+
"ⷅ": "'q",
|
|
88
|
+
"ⷆ": "'qo",
|
|
89
|
+
"ቐ": "Qe",
|
|
90
|
+
"ቑ": "Qu",
|
|
91
|
+
"ቒ": "Qi",
|
|
92
|
+
"ቓ": "Qa",
|
|
93
|
+
"ቔ": "QE",
|
|
94
|
+
"ቕ": "Q",
|
|
95
|
+
"ቖ": "Qo",
|
|
96
|
+
"ቘ": "QWe",
|
|
97
|
+
"ቚ": "QWi",
|
|
98
|
+
"ቛ": "QWa",
|
|
99
|
+
"ቜ": "QWE",
|
|
100
|
+
"ቝ": "QW",
|
|
101
|
+
"በ": "be",
|
|
102
|
+
"ቡ": "bu",
|
|
103
|
+
"ቢ": "bi",
|
|
104
|
+
"ባ": "ba",
|
|
105
|
+
"ቤ": "bE",
|
|
106
|
+
"ብ": "b",
|
|
107
|
+
"ቦ": "bo",
|
|
108
|
+
"ᎄ": "bWe",
|
|
109
|
+
"ᎅ": "bWi",
|
|
110
|
+
"ቧ": "bWa",
|
|
111
|
+
"ᎆ": "bWE",
|
|
112
|
+
"ᎇ": "bW",
|
|
113
|
+
"ቨ": "ve",
|
|
114
|
+
"ቩ": "vu",
|
|
115
|
+
"ቪ": "vi",
|
|
116
|
+
"ቫ": "va",
|
|
117
|
+
"ቬ": "vE",
|
|
118
|
+
"ቭ": "v",
|
|
119
|
+
"ቮ": "vo",
|
|
120
|
+
"ቯ": "vWa",
|
|
121
|
+
"ተ": "te",
|
|
122
|
+
"ቱ": "tu",
|
|
123
|
+
"ቲ": "ti",
|
|
124
|
+
"ታ": "ta",
|
|
125
|
+
"ቴ": "tE",
|
|
126
|
+
"ት": "t",
|
|
127
|
+
"ቶ": "to",
|
|
128
|
+
"ቷ": "tWa",
|
|
129
|
+
"ቸ": "ce",
|
|
130
|
+
"ቹ": "cu",
|
|
131
|
+
"ቺ": "ci",
|
|
132
|
+
"ቻ": "ca",
|
|
133
|
+
"ቼ": "cE",
|
|
134
|
+
"ች": "c",
|
|
135
|
+
"ቾ": "co",
|
|
136
|
+
"ቿ": "cWa",
|
|
137
|
+
"ኀ": "'he",
|
|
138
|
+
"ኁ": "'hu",
|
|
139
|
+
"ኂ": "'hi",
|
|
140
|
+
"ኃ": "'ha",
|
|
141
|
+
"ኄ": "'hE",
|
|
142
|
+
"ኅ": "'h",
|
|
143
|
+
"ኆ": "'ho",
|
|
144
|
+
"ኈ": "hWe",
|
|
145
|
+
"ኊ": "hWi",
|
|
146
|
+
"ኋ": "hWa",
|
|
147
|
+
"ኌ": "hWE",
|
|
148
|
+
"ኍ": "hW",
|
|
149
|
+
"ነ": "ne",
|
|
150
|
+
"ኑ": "nu",
|
|
151
|
+
"ኒ": "ni",
|
|
152
|
+
"ና": "na",
|
|
153
|
+
"ኔ": "nE",
|
|
154
|
+
"ን": "n",
|
|
155
|
+
"ኖ": "no",
|
|
156
|
+
"ኗ": "nWa",
|
|
157
|
+
"ኘ": "Ne",
|
|
158
|
+
"ኙ": "Nu",
|
|
159
|
+
"ኚ": "Ni",
|
|
160
|
+
"ኛ": "Na",
|
|
161
|
+
"ኜ": "NE",
|
|
162
|
+
"ኝ": "N",
|
|
163
|
+
"ኞ": "No",
|
|
164
|
+
"ኟ": "NWa",
|
|
165
|
+
"አ": "e",
|
|
166
|
+
"ኡ": "u",
|
|
167
|
+
"ኢ": "i",
|
|
168
|
+
"ኣ": "a",
|
|
169
|
+
"ኤ": "E",
|
|
170
|
+
"እ": "I",
|
|
171
|
+
"ኦ": "o",
|
|
172
|
+
"ኧ": "ea",
|
|
173
|
+
"ከ": "ke",
|
|
174
|
+
"ኩ": "ku",
|
|
175
|
+
"ኪ": "ki",
|
|
176
|
+
"ካ": "ka",
|
|
177
|
+
"ኬ": "kE",
|
|
178
|
+
"ክ": "k",
|
|
179
|
+
"ኮ": "ko",
|
|
180
|
+
"ኰ": "kWe",
|
|
181
|
+
"ኲ": "kWi",
|
|
182
|
+
"ኳ": "kWa",
|
|
183
|
+
"ኴ": "kWE",
|
|
184
|
+
"ኵ": "kW",
|
|
185
|
+
"ⷈ": "'ke",
|
|
186
|
+
"ⷉ": "'ku",
|
|
187
|
+
"ⷊ": "'ki",
|
|
188
|
+
"ⷋ": "'ka",
|
|
189
|
+
"ⷌ": "'kE",
|
|
190
|
+
"ⷍ": "'k",
|
|
191
|
+
"ⷎ": "'ko",
|
|
192
|
+
"ኸ": "Ke",
|
|
193
|
+
"ኹ": "Ku",
|
|
194
|
+
"ኺ": "Ki",
|
|
195
|
+
"ኻ": "Ka",
|
|
196
|
+
"ኼ": "KE",
|
|
197
|
+
"ኽ": "K",
|
|
198
|
+
"ኾ": "Ko",
|
|
199
|
+
"ዀ": "KWe",
|
|
200
|
+
"ዂ": "KWi",
|
|
201
|
+
"ዃ": "KWa",
|
|
202
|
+
"ዄ": "KWE",
|
|
203
|
+
"ዅ": "KW",
|
|
204
|
+
"ⷐ": "Xe",
|
|
205
|
+
"ⷑ": "Xu",
|
|
206
|
+
"ⷒ": "Xi",
|
|
207
|
+
"ⷓ": "Xa",
|
|
208
|
+
"ⷔ": "XE",
|
|
209
|
+
"ⷕ": "X",
|
|
210
|
+
"ⷖ": "Xo",
|
|
211
|
+
"ወ": "we",
|
|
212
|
+
"ዉ": "wu",
|
|
213
|
+
"ዊ": "wi",
|
|
214
|
+
"ዋ": "wa",
|
|
215
|
+
"ዌ": "wE",
|
|
216
|
+
"ው": "w",
|
|
217
|
+
"ዎ": "wo",
|
|
218
|
+
"ዐ": "'e",
|
|
219
|
+
"ዑ": "'u",
|
|
220
|
+
"ዒ": "'i",
|
|
221
|
+
"ዓ": "'a",
|
|
222
|
+
"ዔ": "'E",
|
|
223
|
+
"ዕ": "'I",
|
|
224
|
+
"ዖ": "'o",
|
|
225
|
+
"ዘ": "ze",
|
|
226
|
+
"ዙ": "zu",
|
|
227
|
+
"ዚ": "zi",
|
|
228
|
+
"ዛ": "za",
|
|
229
|
+
"ዜ": "zE",
|
|
230
|
+
"ዝ": "z",
|
|
231
|
+
"ዞ": "zo",
|
|
232
|
+
"ዟ": "zWa",
|
|
233
|
+
"ዠ": "Ze",
|
|
234
|
+
"ዡ": "Zu",
|
|
235
|
+
"ዢ": "Zi",
|
|
236
|
+
"ዣ": "Za",
|
|
237
|
+
"ዤ": "ZE",
|
|
238
|
+
"ዥ": "Z",
|
|
239
|
+
"ዦ": "Zo",
|
|
240
|
+
"ዧ": "ZWa",
|
|
241
|
+
"የ": "ye",
|
|
242
|
+
"ዩ": "yu",
|
|
243
|
+
"ዪ": "yi",
|
|
244
|
+
"ያ": "ya",
|
|
245
|
+
"ዬ": "yE",
|
|
246
|
+
"ይ": "y",
|
|
247
|
+
"ዮ": "yo",
|
|
248
|
+
"ዯ": "yWa",
|
|
249
|
+
"ደ": "de",
|
|
250
|
+
"ዱ": "du",
|
|
251
|
+
"ዲ": "di",
|
|
252
|
+
"ዳ": "da",
|
|
253
|
+
"ዴ": "dE",
|
|
254
|
+
"ድ": "d",
|
|
255
|
+
"ዶ": "do",
|
|
256
|
+
"ዷ": "dWa",
|
|
257
|
+
"ዸ": "De",
|
|
258
|
+
"ዹ": "Du",
|
|
259
|
+
"ዺ": "Di",
|
|
260
|
+
"ዻ": "Da",
|
|
261
|
+
"ዼ": "DE",
|
|
262
|
+
"ዽ": "D",
|
|
263
|
+
"ዾ": "Do",
|
|
264
|
+
"ዿ": "DWa",
|
|
265
|
+
"ጀ": "je",
|
|
266
|
+
"ጁ": "ju",
|
|
267
|
+
"ጂ": "ji",
|
|
268
|
+
"ጃ": "ja",
|
|
269
|
+
"ጄ": "jE",
|
|
270
|
+
"ጅ": "j",
|
|
271
|
+
"ጆ": "jo",
|
|
272
|
+
"ጇ": "jWa",
|
|
273
|
+
"ገ": "ge",
|
|
274
|
+
"ጉ": "gu",
|
|
275
|
+
"ጊ": "gi",
|
|
276
|
+
"ጋ": "ga",
|
|
277
|
+
"ጌ": "gE",
|
|
278
|
+
"ግ": "g",
|
|
279
|
+
"ጎ": "go",
|
|
280
|
+
"ጐ": "gWe",
|
|
281
|
+
"ጒ": "gWi",
|
|
282
|
+
"ጏ": "gWa",
|
|
283
|
+
"ጓ": "gWa",
|
|
284
|
+
"ጔ": "gWE",
|
|
285
|
+
"ጕ": "gW",
|
|
286
|
+
"ⷘ": "'ge",
|
|
287
|
+
"ⷙ": "'gu",
|
|
288
|
+
"ⷚ": "'gi",
|
|
289
|
+
"ⷛ": "'ga",
|
|
290
|
+
"ⷜ": "'gE",
|
|
291
|
+
"ⷝ": "'g",
|
|
292
|
+
"ⷞ": "'go",
|
|
293
|
+
"ጘ": "Ge",
|
|
294
|
+
"ጙ": "Gu",
|
|
295
|
+
"ጚ": "Gi",
|
|
296
|
+
"ጛ": "Ga",
|
|
297
|
+
"ጜ": "GE",
|
|
298
|
+
"ጝ": "G",
|
|
299
|
+
"ጞ": "Go",
|
|
300
|
+
"ⶓ": "GWe",
|
|
301
|
+
"ⶔ": "GWi",
|
|
302
|
+
"ጟ": "GWa",
|
|
303
|
+
"ⶕ": "GWE",
|
|
304
|
+
"ⶖ": "GW",
|
|
305
|
+
"ጠ": "Te",
|
|
306
|
+
"ጡ": "Tu",
|
|
307
|
+
"ጢ": "Ti",
|
|
308
|
+
"ጣ": "Ta",
|
|
309
|
+
"ጤ": "TE",
|
|
310
|
+
"ጥ": "T",
|
|
311
|
+
"ጦ": "To",
|
|
312
|
+
"ጧ": "TWa",
|
|
313
|
+
"ጨ": "Ce",
|
|
314
|
+
"ጩ": "Cu",
|
|
315
|
+
"ጪ": "Ci",
|
|
316
|
+
"ጫ": "Ca",
|
|
317
|
+
"ጬ": "CE",
|
|
318
|
+
"ጭ": "C",
|
|
319
|
+
"ጮ": "Co",
|
|
320
|
+
"ጯ": "CWa",
|
|
321
|
+
"ጰ": "Pe",
|
|
322
|
+
"ጱ": "Pu",
|
|
323
|
+
"ጲ": "Pi",
|
|
324
|
+
"ጳ": "Pa",
|
|
325
|
+
"ጴ": "PE",
|
|
326
|
+
"ጵ": "P",
|
|
327
|
+
"ጶ": "Po",
|
|
328
|
+
"ጷ": "PWa",
|
|
329
|
+
"ጸ": "Se",
|
|
330
|
+
"ጹ": "Su",
|
|
331
|
+
"ጺ": "Si",
|
|
332
|
+
"ጻ": "Sa",
|
|
333
|
+
"ጼ": "SE",
|
|
334
|
+
"ጽ": "S",
|
|
335
|
+
"ጾ": "So",
|
|
336
|
+
"ጿ": "SWa",
|
|
337
|
+
"ፀ": "'Se",
|
|
338
|
+
"ፁ": "'Su",
|
|
339
|
+
"ፂ": "'Si",
|
|
340
|
+
"ፃ": "'Sa",
|
|
341
|
+
"ፄ": "'SE",
|
|
342
|
+
"ፅ": "'S",
|
|
343
|
+
"ፆ": "'So",
|
|
344
|
+
"ፈ": "fe",
|
|
345
|
+
"ፉ": "fu",
|
|
346
|
+
"ፊ": "fi",
|
|
347
|
+
"ፋ": "fa",
|
|
348
|
+
"ፌ": "fE",
|
|
349
|
+
"ፍ": "f",
|
|
350
|
+
"ፎ": "fo",
|
|
351
|
+
"ᎈ": "fWe",
|
|
352
|
+
"ᎉ": "fWi",
|
|
353
|
+
"ፏ": "fWa",
|
|
354
|
+
"ᎊ": "fWE",
|
|
355
|
+
"ᎋ": "fW",
|
|
356
|
+
"ፐ": "pe",
|
|
357
|
+
"ፑ": "pu",
|
|
358
|
+
"ፒ": "pi",
|
|
359
|
+
"ፓ": "pa",
|
|
360
|
+
"ፔ": "pE",
|
|
361
|
+
"ፕ": "p",
|
|
362
|
+
"ፖ": "po",
|
|
363
|
+
"ᎌ": "pWe",
|
|
364
|
+
"ᎍ": "pWi",
|
|
365
|
+
"ፗ": "pWa",
|
|
366
|
+
"ᎎ": "pWE",
|
|
367
|
+
"ᎏ": "pW"
|
|
368
|
+
}
|
abugida/__init__.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from datetime import date, datetime
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class CalendarConverter:
|
|
5
|
+
"""
|
|
6
|
+
A class to handle calendar conversion between Ethiopian Calendar (EC) and Gregorian Calendar (GC).
|
|
7
|
+
|
|
8
|
+
Attributes:
|
|
9
|
+
EC_GC_DAY_DIFFERENCE (int): The constant difference in days between the Ethiopian Calendar
|
|
10
|
+
and the Gregorian Calendar. Specifically, the Ethiopian calendar lags 2430 days behind
|
|
11
|
+
the Gregorian calendar.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
EC_GC_DAY_DIFFERENCE = 2430
|
|
15
|
+
|
|
16
|
+
def convert(self, date_str: str, from_calendar: str, to_calendar: str) -> str:
|
|
17
|
+
"""
|
|
18
|
+
Convert a date from one calendar system to another.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
date_str (str): The date to be converted, formatted as "YYYY-MM-DD".
|
|
22
|
+
from_calendar (str): The source calendar system, either "EC" (Ethiopian) or "GC" (Gregorian).
|
|
23
|
+
to_calendar (str): The target calendar system, either "EC" (Ethiopian) or "GC" (Gregorian).
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
str: The converted date in the format "YYYY-MM-DD" for the target calendar system.
|
|
27
|
+
|
|
28
|
+
Raises:
|
|
29
|
+
ValueError: If the `date_str` is invalid for the source calendar system.
|
|
30
|
+
ValueError: If the `from_calendar` or `to_calendar` arguments are not "EC" or "GC".
|
|
31
|
+
ValueError: If the calendar conversion between the specified systems is unsupported.
|
|
32
|
+
ValueError: If the calculated date for the target calendar system is invalid (e.g., negative or zero days).
|
|
33
|
+
"""
|
|
34
|
+
if not self._is_date_valid(date_str, from_calendar):
|
|
35
|
+
raise ValueError(
|
|
36
|
+
"Invalid date format or value for the source calendar system"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
if [from_calendar, to_calendar] not in [["EC", "GC"], ["GC", "EC"]]:
|
|
40
|
+
raise ValueError("Unsupported calendar conversion")
|
|
41
|
+
|
|
42
|
+
day_count = self._get_absolute_day_count(date_str, from_calendar)
|
|
43
|
+
|
|
44
|
+
if from_calendar == "EC":
|
|
45
|
+
day_count += self.EC_GC_DAY_DIFFERENCE
|
|
46
|
+
else:
|
|
47
|
+
day_count -= self.EC_GC_DAY_DIFFERENCE
|
|
48
|
+
|
|
49
|
+
if day_count < 1:
|
|
50
|
+
raise ValueError("Invalid date for the target calendar system")
|
|
51
|
+
|
|
52
|
+
return self._absolute_day_count_to_date(day_count, to_calendar)
|
|
53
|
+
|
|
54
|
+
def _is_date_valid(self, date_str: str, calendar_system: str) -> bool:
|
|
55
|
+
if calendar_system == "EC":
|
|
56
|
+
year, month, day = map(int, date_str.split("-"))
|
|
57
|
+
pagume_day_count = 6 if self._is_leap_year(year, calendar_system) else 5
|
|
58
|
+
return (
|
|
59
|
+
year > 0
|
|
60
|
+
and 1 <= month <= 13
|
|
61
|
+
and 1 <= day <= (30 if month != 13 else pagume_day_count)
|
|
62
|
+
)
|
|
63
|
+
elif calendar_system == "GC":
|
|
64
|
+
try:
|
|
65
|
+
datetime.strptime(date_str, "%Y-%m-%d")
|
|
66
|
+
return True
|
|
67
|
+
except ValueError:
|
|
68
|
+
return False
|
|
69
|
+
else:
|
|
70
|
+
raise ValueError("Invalid calendar system")
|
|
71
|
+
|
|
72
|
+
def _get_absolute_day_count(self, date_str: str, calendar_system: str) -> int:
|
|
73
|
+
if calendar_system == "EC":
|
|
74
|
+
year, month, day = map(int, date_str.split("-"))
|
|
75
|
+
if self._is_date_valid(date_str, calendar_system):
|
|
76
|
+
return (
|
|
77
|
+
(year * 365 + self._count_leap_years(year, calendar_system))
|
|
78
|
+
+ ((month - 1) * 30)
|
|
79
|
+
+ day
|
|
80
|
+
)
|
|
81
|
+
raise ValueError("Invalid date in the Ethiopian Calendar")
|
|
82
|
+
elif calendar_system == "GC":
|
|
83
|
+
return date.fromisoformat(date_str).toordinal()
|
|
84
|
+
else:
|
|
85
|
+
raise ValueError("Invalid calendar system")
|
|
86
|
+
|
|
87
|
+
def _absolute_day_count_to_date(self, day_count: int, calendar_system: str) -> str:
|
|
88
|
+
if calendar_system == "EC":
|
|
89
|
+
day_count -= day_count // 1460
|
|
90
|
+
|
|
91
|
+
year = day_count // 365
|
|
92
|
+
day_count -= year * 365
|
|
93
|
+
month = day_count // 30
|
|
94
|
+
day_count -= month * 30
|
|
95
|
+
day = day_count
|
|
96
|
+
|
|
97
|
+
month += 1
|
|
98
|
+
return f"{year:04d}-{month:02d}-{day:02d}"
|
|
99
|
+
elif calendar_system == "GC":
|
|
100
|
+
return date.fromordinal(day_count).isoformat()
|
|
101
|
+
else:
|
|
102
|
+
raise ValueError("Invalid calendar system")
|
|
103
|
+
|
|
104
|
+
def _count_leap_years(self, year: int, calendar_system: str) -> int:
|
|
105
|
+
if calendar_system == "EC":
|
|
106
|
+
return year // 4
|
|
107
|
+
elif calendar_system == "GC":
|
|
108
|
+
return (year // 4) - (year // 100) + (year // 400)
|
|
109
|
+
else:
|
|
110
|
+
raise ValueError("Invalid calendar system")
|
|
111
|
+
|
|
112
|
+
def _is_leap_year(self, year: int, calendar_system: str) -> bool:
|
|
113
|
+
if calendar_system == "EC":
|
|
114
|
+
return year % 4 == 0
|
|
115
|
+
elif calendar_system == "GC":
|
|
116
|
+
return (year % 4 == 0 and year % 100 != 0) or year % 400 == 0
|
|
117
|
+
else:
|
|
118
|
+
raise ValueError("Invalid calendar system")
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
class NumeralConverter:
|
|
2
|
+
"""
|
|
3
|
+
A class to convert numerals between Ge'ez and Hindu-Arabic systems.
|
|
4
|
+
|
|
5
|
+
Attributes:
|
|
6
|
+
geez_arabic_map (Dict[str, int]): Mapping from Ge'ez to Arabic numerals.
|
|
7
|
+
arabic_geez_map (Dict[int, str]): Mapping from Arabic to Ge'ez numerals.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
def __init__(self):
|
|
11
|
+
# Mapping between Ge'ez numerals and their Arabic equivalents
|
|
12
|
+
self.geez_arabic_map = {
|
|
13
|
+
"፩": 1,
|
|
14
|
+
"፪": 2,
|
|
15
|
+
"፫": 3,
|
|
16
|
+
"፬": 4,
|
|
17
|
+
"፭": 5,
|
|
18
|
+
"፮": 6,
|
|
19
|
+
"፯": 7,
|
|
20
|
+
"፰": 8,
|
|
21
|
+
"፱": 9,
|
|
22
|
+
"፲": 10,
|
|
23
|
+
"፳": 20,
|
|
24
|
+
"፴": 30,
|
|
25
|
+
"፵": 40,
|
|
26
|
+
"፶": 50,
|
|
27
|
+
"፷": 60,
|
|
28
|
+
"፸": 70,
|
|
29
|
+
"፹": 80,
|
|
30
|
+
"፺": 90,
|
|
31
|
+
"፻": 100,
|
|
32
|
+
"፼": 10000,
|
|
33
|
+
}
|
|
34
|
+
self.arabic_geez_map = {
|
|
35
|
+
value: key for key, value in self.geez_arabic_map.items()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
def convert(self, num: int | str, from_numeral: str, to_numeral: str):
|
|
39
|
+
"""
|
|
40
|
+
Convert a numeral between Ge'ez and Hindu-Arabic systems.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
num (int|str): The numeral to be converted.
|
|
44
|
+
from_numeral (str): Source numeral system ('gz' for Ge'ez, 'ha' for Hindu-Arabic).
|
|
45
|
+
to_numeral (str): Target numeral system ('gz' for Ge'ez, 'ha' for Hindu-Arabic).
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
str|int: The converted numeral.
|
|
49
|
+
|
|
50
|
+
Raises:
|
|
51
|
+
ValueError: If invalid numeral systems are provided or input format is incorrect.
|
|
52
|
+
"""
|
|
53
|
+
if [from_numeral, to_numeral] not in [["gz", "ha"], ["ha", "gz"]]:
|
|
54
|
+
raise ValueError(f"Unsupported conversion: {from_numeral} to {to_numeral}")
|
|
55
|
+
|
|
56
|
+
if from_numeral == "gz":
|
|
57
|
+
return self._convert_geez_to_arabic(num)
|
|
58
|
+
if from_numeral == "ha":
|
|
59
|
+
return self._convert_arabic_to_geez(num)
|
|
60
|
+
|
|
61
|
+
def _convert_arabic_to_geez(self, arabic_num: int):
|
|
62
|
+
if not isinstance(arabic_num, int):
|
|
63
|
+
raise ValueError("Input must be an integer.")
|
|
64
|
+
if arabic_num <= 0:
|
|
65
|
+
raise ValueError("Ge'ez numerals do not support non-positive numbers.")
|
|
66
|
+
|
|
67
|
+
arabic_segments = self._split_arabic_num(arabic_num)
|
|
68
|
+
geez_num = ""
|
|
69
|
+
for i in range(len(arabic_segments)):
|
|
70
|
+
geez_num += self._arabic_to_geez_segment(
|
|
71
|
+
arabic_segments[i], len(arabic_segments) - 1 - i
|
|
72
|
+
)
|
|
73
|
+
return geez_num
|
|
74
|
+
|
|
75
|
+
def _convert_geez_to_arabic(self, geez_num: str):
|
|
76
|
+
if not isinstance(geez_num, str):
|
|
77
|
+
raise ValueError("Input must be a string representing a Ge'ez numeral.")
|
|
78
|
+
if not geez_num:
|
|
79
|
+
raise ValueError("Input must not be empty.")
|
|
80
|
+
if not all(char in self.geez_arabic_map for char in geez_num):
|
|
81
|
+
raise ValueError("Input contains invalid Ge'ez numeral characters.")
|
|
82
|
+
|
|
83
|
+
arabic_segments = self._split_geez_num(geez_num)
|
|
84
|
+
arabic_num = 0
|
|
85
|
+
for i in range(len(arabic_segments)):
|
|
86
|
+
arabic_num += arabic_segments[-i - 1] * pow(10, i * 2)
|
|
87
|
+
return arabic_num
|
|
88
|
+
|
|
89
|
+
def _split_arabic_num(self, arabic_num: int):
|
|
90
|
+
arabic_num = str(arabic_num)
|
|
91
|
+
segment_length = 2
|
|
92
|
+
if len(arabic_num) % 2 == 1:
|
|
93
|
+
arabic_num = "0" + arabic_num
|
|
94
|
+
return [
|
|
95
|
+
arabic_num[i : i + segment_length]
|
|
96
|
+
for i in range(0, len(arabic_num), segment_length)
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
def _arabic_to_geez_segment(self, arabic_segment: str, segment_index: int):
|
|
100
|
+
if int(arabic_segment) == 0:
|
|
101
|
+
return ""
|
|
102
|
+
geez_segment = self.arabic_geez_map.get(int(arabic_segment))
|
|
103
|
+
if not geez_segment:
|
|
104
|
+
geez_segment = (
|
|
105
|
+
self.arabic_geez_map[int(arabic_segment[0]) * 10]
|
|
106
|
+
+ self.arabic_geez_map[int(arabic_segment[1])]
|
|
107
|
+
)
|
|
108
|
+
if segment_index % 2 == 1:
|
|
109
|
+
geez_segment = "፻" if geez_segment == "፩" else geez_segment + "፻"
|
|
110
|
+
elif segment_index != 0:
|
|
111
|
+
geez_segment = "፼" if geez_segment == "፩" else geez_segment + "፼"
|
|
112
|
+
return geez_segment
|
|
113
|
+
|
|
114
|
+
def _split_geez_num(self, geez_num: str):
|
|
115
|
+
arabic_segments = []
|
|
116
|
+
geez_num_len = len(geez_num)
|
|
117
|
+
slice_end_index = geez_num_len
|
|
118
|
+
for i in range(geez_num_len):
|
|
119
|
+
if geez_num[-i - 1] == "፻":
|
|
120
|
+
arabic_segments.insert(
|
|
121
|
+
0, self._geez_to_arabic_segment(geez_num[-i:slice_end_index])
|
|
122
|
+
)
|
|
123
|
+
slice_end_index = -i - 1
|
|
124
|
+
if len(arabic_segments) % 2 == 0:
|
|
125
|
+
arabic_segments.insert(0, 0)
|
|
126
|
+
elif geez_num[-i - 1] == "፼":
|
|
127
|
+
arabic_segments.insert(
|
|
128
|
+
0, self._geez_to_arabic_segment(geez_num[-i:slice_end_index])
|
|
129
|
+
)
|
|
130
|
+
slice_end_index = -i - 1
|
|
131
|
+
if len(arabic_segments) % 2 == 1:
|
|
132
|
+
arabic_segments.insert(0, 0)
|
|
133
|
+
slice_end_index = geez_num.index("፻" if len(arabic_segments) % 2 == 1 else "፼")
|
|
134
|
+
arabic_segments.insert(
|
|
135
|
+
0, self._geez_to_arabic_segment(geez_num[0:slice_end_index])
|
|
136
|
+
)
|
|
137
|
+
return arabic_segments
|
|
138
|
+
|
|
139
|
+
def _geez_to_arabic_segment(self, geez_num: str):
|
|
140
|
+
if len(geez_num) == 0:
|
|
141
|
+
return 1
|
|
142
|
+
arabic_num = self.geez_arabic_map.get(geez_num)
|
|
143
|
+
if not arabic_num:
|
|
144
|
+
arabic_num = (
|
|
145
|
+
self.geez_arabic_map[geez_num[0]] + self.geez_arabic_map[geez_num[1]]
|
|
146
|
+
)
|
|
147
|
+
return arabic_num
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import importlib.resources as pkg_resources
|
|
4
|
+
from typing import Dict
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ScriptConverter:
|
|
8
|
+
"""
|
|
9
|
+
A class for transliteration between Ethiopic and Latin scripts.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
ethiopic_latin_map (Dict[str, str]): Mapping from Ethiopic to Latin.
|
|
13
|
+
latin_ethiopic_map (Dict[str, str]): Mapping from Latin to Ethiopic.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
def __init__(self, mapping_file: str = "SERA_table.json"):
|
|
17
|
+
"""
|
|
18
|
+
Initialize the ScriptConverter with mappings from a JSON file.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
mapping_file (str): Path to the JSON file containing transliteration mappings.
|
|
22
|
+
If not provided, defaults to 'SERA_table.json' bundled with the package.
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
FileNotFoundError: If the specified file (custom or default) is not found.
|
|
26
|
+
ValueError: If the JSON file is invalid or cannot be parsed.
|
|
27
|
+
"""
|
|
28
|
+
self.ethiopic_latin_map = self._load_mappings(mapping_file)
|
|
29
|
+
self.latin_ethiopic_map = {v: k for k, v in self.ethiopic_latin_map.items()}
|
|
30
|
+
|
|
31
|
+
@staticmethod
|
|
32
|
+
def _load_mappings(file_path: str) -> Dict[str, str]:
|
|
33
|
+
if os.path.isfile(file_path): # Custom file path
|
|
34
|
+
try:
|
|
35
|
+
with open(file_path, "r", encoding="utf-8") as file:
|
|
36
|
+
return json.load(file)
|
|
37
|
+
except json.JSONDecodeError:
|
|
38
|
+
raise ValueError(
|
|
39
|
+
f"Failed to parse the custom mapping file '{file_path}'. Ensure it contains valid JSON."
|
|
40
|
+
)
|
|
41
|
+
else: # Fallback to default file in the package
|
|
42
|
+
try:
|
|
43
|
+
with pkg_resources.open_text("abugida", file_path) as file:
|
|
44
|
+
return json.load(file)
|
|
45
|
+
except FileNotFoundError:
|
|
46
|
+
raise FileNotFoundError(
|
|
47
|
+
f"Mapping file '{file_path}' not found. If using a default file, ensure it is bundled with the package."
|
|
48
|
+
)
|
|
49
|
+
except json.JSONDecodeError:
|
|
50
|
+
raise ValueError(
|
|
51
|
+
f"Failed to parse the default mapping file '{file_path}'. Ensure it contains valid JSON."
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
def transliterate(self, word: str, direction: str) -> str:
|
|
55
|
+
"""
|
|
56
|
+
Transliterate a word between Ethiopic and Latin scripts.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
word (str): The word to be transliterated.
|
|
60
|
+
direction (str): The direction of transliteration.
|
|
61
|
+
'fwd' - Transliterate from Ethiopic to Latin.
|
|
62
|
+
'bwd' - Transliterate from Latin to Ethiopic.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
str: The transliterated word.
|
|
66
|
+
|
|
67
|
+
Raises:
|
|
68
|
+
ValueError: If an invalid direction is provided or if the word contains invalid characters.
|
|
69
|
+
"""
|
|
70
|
+
if not word:
|
|
71
|
+
raise ValueError("Word must not be empty.")
|
|
72
|
+
|
|
73
|
+
if not isinstance(word, str):
|
|
74
|
+
raise ValueError("Word must be a string.")
|
|
75
|
+
|
|
76
|
+
if not isinstance(direction, str):
|
|
77
|
+
raise ValueError("Direction must be a string.")
|
|
78
|
+
|
|
79
|
+
if direction not in ["fwd", "bwd"]:
|
|
80
|
+
raise ValueError(
|
|
81
|
+
"Invalid direction. Use 'fwd' for Ethiopic to Latin or 'bwd' for Latin to Ethiopic."
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
if direction == "fwd":
|
|
85
|
+
return self._ethiopic_to_latin(word)
|
|
86
|
+
elif direction == "bwd":
|
|
87
|
+
return self._latin_to_ethiopic(word)
|
|
88
|
+
|
|
89
|
+
def _is_valid_latin_transliteration(self, word: str) -> bool:
|
|
90
|
+
word = word.replace("'", "")
|
|
91
|
+
return word.isascii() and word.isalpha()
|
|
92
|
+
|
|
93
|
+
def _ethiopic_to_latin(self, word: str) -> str:
|
|
94
|
+
if not all(char in self.ethiopic_latin_map for char in word):
|
|
95
|
+
raise ValueError("The word contains non-Ethiopic letters.")
|
|
96
|
+
|
|
97
|
+
return "".join(self.ethiopic_latin_map[char] for char in word)
|
|
98
|
+
|
|
99
|
+
def _latin_to_ethiopic(self, word: str) -> str:
|
|
100
|
+
if not self._is_valid_latin_transliteration(word):
|
|
101
|
+
raise ValueError("The Latin transliteration contains invalid characters.")
|
|
102
|
+
|
|
103
|
+
ethiopic_word = ""
|
|
104
|
+
i = min(4, len(word))
|
|
105
|
+
while i > 0:
|
|
106
|
+
if fidel := self.latin_ethiopic_map.get(word[:i]):
|
|
107
|
+
ethiopic_word += fidel
|
|
108
|
+
word = word[i:]
|
|
109
|
+
i = min(4, len(word))
|
|
110
|
+
else:
|
|
111
|
+
i -= 1
|
|
112
|
+
if i == 0:
|
|
113
|
+
raise ValueError(f"Invalid Latin sequence: '{word}'")
|
|
114
|
+
|
|
115
|
+
return ethiopic_word
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Eyob Hagos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: abugida
|
|
3
|
+
Version: 0.3.4
|
|
4
|
+
Summary: NLP tools and resources for Ethiopian languages
|
|
5
|
+
Project-URL: Source, https://github.com/hadamard-2/abugidanlp
|
|
6
|
+
Keywords: nlp,ethiopian languages,ethiopic,abugida,ge'ez
|
|
7
|
+
Classifier: Intended Audience :: Developers
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
|
|
14
|
+
# AbugidaNLP
|
|
15
|
+
Natural Language Processing tools and resources for Ethiopian languages.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Introduction
|
|
20
|
+
AbugidaNLP is an open-source library focused on developing NLP tools tailored to Ethiopian languages. The library aims to support tasks like calendar system conversion, numeral conversion, and transliteration between Ethiopic and Latin scripts. As one of the first steps towards bridging the gap in NLP tools for underrepresented languages, AbugidaNLP aspires to grow into a comprehensive toolkit for linguists, researchers, and developers.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Key Features
|
|
25
|
+
AbugidaNLP is currently in its infancy, offering:
|
|
26
|
+
- **Transliteration**: Convert text between Ethiopic and Latin scripts.
|
|
27
|
+
- **Calendar System Conversion**: Seamlessly convert dates between Ethiopic and Gregorian calendars.
|
|
28
|
+
- **Numeral System Conversion**: Translate numbers between Ge'ez and Hindu-Arabic numeral systems.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
### Prerequisites
|
|
35
|
+
- Python 3.8 or higher
|
|
36
|
+
- pip
|
|
37
|
+
|
|
38
|
+
### Installation
|
|
39
|
+
Install AbugidaNLP using pip:
|
|
40
|
+
```bash
|
|
41
|
+
pip install abugida
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
Here’s how to get started with AbugidaNLP:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from abugida import ScriptConverter # Import the ScriptConverter class from AbugidaNLP
|
|
52
|
+
|
|
53
|
+
# Initialize the ScriptConverter
|
|
54
|
+
converter = ScriptConverter()
|
|
55
|
+
|
|
56
|
+
# Forward transliteration: Convert Ethiopic script to Latin script
|
|
57
|
+
result_fwd = converter.transliterate("በመተባበራችን", "fwd")
|
|
58
|
+
print(result_fwd) # Output: bemetebaberacn
|
|
59
|
+
|
|
60
|
+
# Backward transliteration: Convert Latin script to Ethiopic script
|
|
61
|
+
result_bwd = converter.transliterate("merejawoc", "bwd")
|
|
62
|
+
print(result_bwd) # Output: መረጃዎች
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Explanation:
|
|
66
|
+
1. **Import the library**: The `ScriptConverter` class handles script conversions.
|
|
67
|
+
2. **Initialize**: Create an instance of the `ScriptConverter` to use its methods.
|
|
68
|
+
3. **Transliteration**:
|
|
69
|
+
- Use the `"fwd"` mode for Ethiopic to Latin conversion.
|
|
70
|
+
- Use the `"bwd"` mode for Latin to Ethiopic conversion.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Documentation
|
|
75
|
+
Documentation for AbugidaNLP is under construction. Stay tuned for detailed usage examples and API references.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
We welcome contributions to AbugidaNLP! Whether it's improving documentation, adding new features, or fixing bugs, your help is valuable.
|
|
81
|
+
|
|
82
|
+
### Steps to Contribute:
|
|
83
|
+
1. Fork the repository.
|
|
84
|
+
2. Create a new branch for your feature/bugfix.
|
|
85
|
+
3. Submit a pull request.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Acknowledgments
|
|
95
|
+
Special thanks to the following resources for their inspiration and insights:
|
|
96
|
+
- [A Look at Ethiopic Numerals](https://www.geez.org/Numerals/)
|
|
97
|
+
- [The System for Ethiopic Representation in ASCII](https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=96a6d78a3fced66214611339a0f95441ab4dc992)
|
|
98
|
+
|
|
99
|
+
## Contact
|
|
100
|
+
For questions or support, please open an issue.
|
|
101
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
abugida/SERA_table.json,sha256=l_-6PlPsg37-lsXhxvdQmIQGwcPFWwa4zXGBUY3tf-Q,5923
|
|
2
|
+
abugida/__init__.py,sha256=TL3h2AkI460H8Y-S_lGvck2DNPsVDLF8VkIcTWfCxC8,215
|
|
3
|
+
abugida/convert_calendar.py,sha256=BkjDJEZ-MTGFD-Nqxw5GJcOiq752AavDFgG_p8RcL30,4909
|
|
4
|
+
abugida/convert_numeral.py,sha256=MsQSwyEkUdvoNTndFin-UlEZ0kwORN2uDtZGPk18uTQ,5694
|
|
5
|
+
abugida/convert_script.py,sha256=xerEacK_YhhvodraYi5kI58-jF5YsFWg6Sk_-4k5TUA,4556
|
|
6
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
tests/calendar_conversion_test.py,sha256=-PSEgYFDfelGj49XFLL8lbILI9l6E-p8kIKi3Wp9wBU,930
|
|
8
|
+
tests/numeral_conversion_test.py,sha256=aJRoigCIoaeOOfMmQ_JS5lACA5WIDmKU-1RIk7n2V5I,948
|
|
9
|
+
tests/script_conversion_test.py,sha256=MY-gH4iOPLzKHel9TfsZSqBqtFfRqr6TtPCC5kyfTlg,1199
|
|
10
|
+
abugida-0.3.4.dist-info/LICENSE,sha256=OpNYJtMf4FO2L7OcNiG8C6A7WzV347vO39Vc0uED68s,1087
|
|
11
|
+
abugida-0.3.4.dist-info/METADATA,sha256=Dw8-Dnw3Lz7X6up4AVv668x0WtzuWixkhbWMNtMtizk,3455
|
|
12
|
+
abugida-0.3.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
13
|
+
abugida-0.3.4.dist-info/top_level.txt,sha256=SckwQfZfqolN50K72Yudohf1bFxBz_R48aUCVV1QaiQ,14
|
|
14
|
+
abugida-0.3.4.dist-info/RECORD,,
|
tests/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from abugida import CalendarConverter
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestConvertCalendar(unittest.TestCase):
|
|
6
|
+
def setUp(self):
|
|
7
|
+
self.convert = CalendarConverter().convert
|
|
8
|
+
self.test_cases = [
|
|
9
|
+
("2017-03-11", "2024-11-20"),
|
|
10
|
+
("1993-10-13", "2001-06-20"),
|
|
11
|
+
("1860-08-06", "1868-04-13"),
|
|
12
|
+
("2012-09-11", "2020-05-19"),
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
def test_ec_to_gc(self):
|
|
16
|
+
for ec_date, gc_date in self.test_cases:
|
|
17
|
+
with self.subTest(ec_date=ec_date):
|
|
18
|
+
result = self.convert(ec_date, "EC", "GC")
|
|
19
|
+
self.assertEqual(result, gc_date)
|
|
20
|
+
|
|
21
|
+
def test_gc_to_ec(self):
|
|
22
|
+
for ec_date, gc_date in self.test_cases:
|
|
23
|
+
with self.subTest(gc_date=gc_date):
|
|
24
|
+
result = self.convert(gc_date, "GC", "EC")
|
|
25
|
+
self.assertEqual(result, ec_date)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
unittest.main()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from abugida import NumeralConverter
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestConvertNumeral(unittest.TestCase):
|
|
6
|
+
def setUp(self):
|
|
7
|
+
self.convert = NumeralConverter().convert
|
|
8
|
+
|
|
9
|
+
self.test_cases = [
|
|
10
|
+
(7654321, "፯፻፷፭፼፵፫፻፳፩"),
|
|
11
|
+
(7650021, "፯፻፷፭፼፳፩"),
|
|
12
|
+
(7650121, "፯፻፷፭፼፻፳፩"),
|
|
13
|
+
(20242, "፪፼፪፻፵፪"),
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
def test_gz_to_ha(self):
|
|
17
|
+
for ha_num, gz_num in self.test_cases:
|
|
18
|
+
with self.subTest(gz_num=gz_num):
|
|
19
|
+
result = self.convert(gz_num, "gz", "ha")
|
|
20
|
+
self.assertEqual(result, ha_num)
|
|
21
|
+
|
|
22
|
+
def test_ha_to_gz(self):
|
|
23
|
+
for ha_num, gz_num in self.test_cases:
|
|
24
|
+
with self.subTest(ha_num=ha_num):
|
|
25
|
+
result = self.convert(ha_num, "ha", "gz")
|
|
26
|
+
self.assertEqual(result, gz_num)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if __name__ == "__main__":
|
|
30
|
+
unittest.main()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from abugida import ScriptConverter
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestTransliteration(unittest.TestCase):
|
|
6
|
+
def setUp(self):
|
|
7
|
+
self.transliterate = ScriptConverter().transliterate
|
|
8
|
+
|
|
9
|
+
self.test_cases = [
|
|
10
|
+
("ኢትዮጵያ", "ityoPya"),
|
|
11
|
+
("ሰባበረው", "sebaberew"),
|
|
12
|
+
("ልጆቻችን", "ljocacn"),
|
|
13
|
+
("ውሃ", "wha"),
|
|
14
|
+
("አገልግሎት", "egelglot"),
|
|
15
|
+
("መረጃዎች", "merejawoc"),
|
|
16
|
+
("ቁርጥራጭ", "qurTraC"),
|
|
17
|
+
("ማህበረሰብ", "mahbereseb"),
|
|
18
|
+
("ትርዒት", "tr'it"),
|
|
19
|
+
("ትዕይንት", "t'Iynt"),
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
def test_transliterate_fwd(self):
|
|
23
|
+
for ethiopic, latin in self.test_cases:
|
|
24
|
+
with self.subTest(original=ethiopic, expected=latin):
|
|
25
|
+
self.assertEqual(self.transliterate(ethiopic, "fwd"), latin)
|
|
26
|
+
|
|
27
|
+
def test_transliterate_bwd(self):
|
|
28
|
+
for ethiopic, latin in self.test_cases:
|
|
29
|
+
with self.subTest(original=latin, expected=ethiopic):
|
|
30
|
+
self.assertEqual(self.transliterate(latin, "bwd"), ethiopic)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
unittest.main()
|