File size: 16,334 Bytes
0a4e172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
from normalizer import Normalizer

def test_currency_normalization():
    n = Normalizer()

    assert n.process("من امروز ۳$ دارم") == "من امروز سه دلار دارم"
    assert n.process("من امروز 3$ دارم") == "من امروز سه دلار دارم"
    assert n.process("من امروز 1 $ دارم") == "من امروز یک دلار دارم"
    assert n.process("من امروز 12.4$ دارم") == "من امروز دوازده دلار و چهل سنت دارم"
    assert n.process("من امروز 12.۴$ دارم") == "من امروز دوازده دلار و چهل سنت دارم"
    assert n.process("من امروز 125.۴3$ دارم") == "من امروز یکصد و بیست و پنج دلار و چهل و سه سنت دارم"
    assert n.process("من امروز 12.۴€ دارم") == "من امروز دوازده یورو و چهل سنت دارم"
    assert n.process("من امروز 1001.۴€ و 5۲.4$ دارم") == "من امروز یک هزار و یک یورو و چهل سنت و پنجاه و دو دلار و چهل سنت دارم"

    assert n.process("I have 3$") == "I have three dollars"
    assert n.process("I have ۳$.") == "I have three dollars."
    assert n.process("I have 1$") == "I have one dollar"
    assert n.process("I have 1 $") == "I have one dollar"
    assert n.process("I have 2.5$") == "I have two dollars and fifty cents"
    assert n.process("I have ۲.۵$") == "I have two dollars and fifty cents"
    assert n.process("I have 2.۵$") == "I have two dollars and fifty cents"
    assert n.process("I have ۱.1$.") == "I have one dollar and ten cents."
    assert n.process("I have 3$ and 1 €") == "I have three dollars and one euro"
    assert n.process("I have 3.9$ and 1.3€ and 12.۳3 £.") == (
        "I have three dollars and ninety cents and one euro and thirty cents "
        "and twelve pounds and thirty-three pence."
    )
    assert n.process("1000$") == "one thousand dollars"
    assert n.process("1,000$") == "one thousand dollars"
    assert n.process("1000  $") == "one thousand dollars"
    assert n.process("1,000,001 €") == "one million and one euros"
    assert n.process("۱۰۰۰$") == "یک هزار دلار"
    assert n.process("۱۰۰۱  $") == "یک هزار و یک دلار"

    print("✅ All currency normalization tests passed successfully!")
#----------------------------------------------------------------------------------------------------------------------------
def test_unit_normalization():
    n = Normalizer()

    assert n.process("وزن او ۷۵kg است") == "وزن او هفتاد و پنج کیلوگرم است"
    assert n.process("وزن او 75kg است") == "وزن او هفتاد و پنج کیلوگرم است"
    assert n.process("دمای هوا ۷۷°F است") == "دمای هوا هفتاد و هفت درجه فارنهایت است"
    assert n.process("از اینجا تا آنجا ۱۰۰۰.۵m فاصله است") == "از اینجا تا آنجا یک هزار متر و پنجاه سانتیمتر فاصله است"
    assert n.process("I ran 5km today") == "I ran five kilometres today"
    assert n.process("It is 2۵°C outside") == "It is twenty-five degrees Celsius outside"
    assert n.process("The car goes 60 km/h") == "The car goes sixty kilometres per hour"
    assert n.process("1000m") == "one thousand metres"
    assert n.process("۲۳۰۰m") == "دو هزار و سیصد متر"
    assert n.process("۱.۲۳۴ m") == "یک متر و بیست و سه سانتیمتر و چهار میلیمتر"
    assert n.process("26°C") == "twenty-six degrees Celsius"
    assert n.process("۲۶ °C") == "بیست و شش درجه سانتیگراد"
    assert n.process("۲۴ °F") == "بیست و چهار درجه فارنهایت"
    assert n.process("۷۰ km/h") == "هفتاد کیلومتر بر ساعت"
    assert n.process("۳.۵ L") == "سه لیتر و پانصد میلی‌لیتر"
    assert n.process("۸ oz") == "هشت اونس"
    assert n.process("۳.۵ sec") == "سه ثانیه و پانصد میلی‌ثانیه"
    assert n.process("۳.۵ min") == "سه دقیقه و سی ثانیه"
    assert n.process("3.5hour") == "three hours and thirty minutes"
    assert n.process("3.51 hour") == "three hours, thirty minutes and thirty-six seconds"
    assert n.process("3.512 hour") == "three hours, thirty minutes, forty-three seconds and two hundred milliseconds"
    assert n.process("۳.۵۱۲ hour") == "سه ساعت و سی دقیقه و چهل و سه ثانیه و دویست میلی‌ثانیه"
    assert n.process("10.5 days") == "ten days and twelve hours"
    assert n.process("۱,۰۰۰,۰۰۰ hour") == "یک میلیون ساعت"
    assert n.process("5 %") == "five percent"
    assert n.process("%5") == "five percent"
    assert n.process("٪۲۰") == "بیست درصد"
    assert n.process("20 % cm") == "twenty percent centimetre"
    assert n.process("۲۰% cm") == "بیست درصد سانتیمتر"
    assert n.process("۲۰٪ cm") == "بیست درصد سانتیمتر"
    assert n.process("٪۲۰ cm") == "بیست درصد سانتیمتر"
    assert n.process("٪ ۲۰ cm.") == "بیست درصد سانتیمتر."
    assert n.process("% ۲۰ cm.") == "بیست درصد سانتیمتر."
    

    print("✅ All unit normalization tests passed successfully!")
#----------------------------------------------------------------------------------------------------------------------------
def test_fraction_normalization():
    n = Normalizer()

    assert n.process("1/3") == "one third"
    assert n.process("1000000/3") == "one million thirds"
    assert n.process("۱/۳") == "یک سوم"
    assert n.process("۱ ۱/۳") == "یک و یک سوم"
    assert n.process("1/2 kg") == "one half kilogram"
    assert n.process("1000/2 kg") == "one thousand halves kilograms"
    assert n.process("1,000,000/2 sec") == "one million halves seconds"
    assert n.process("1,000,000/3 sec") == "one million thirds seconds"
    assert n.process("۱,۵۰۰,۰۰۰/۳ hour") == "یک میلیون و پانصد هزار سوم ساعت"
    assert n.process("۶/۵ sec") == "شش پنجم ثانیه"
    assert n.process("۷/۹۰ km/h") == "هفت نودم کیلومتر بر ساعت"
    assert n.process("۷.۹۰ km/h") == "هفت و نه دهم کیلومتر بر ساعت"
    assert n.process("۱۵ ۱۲/۲۳ min") == "پانزده و دوازده بیست و سوم دقیقه"
    assert n.process("1 100/2 %") == "one and one hundred halves percent"
    assert n.process("۱/۲ ٪") == "یک دوم درصد"
    assert n.process("1 5,000/2000% cm") == "one and five thousand two thousandths percent centimetre"
    assert n.process("۲/۱۰٪ cm") == "دو دهم درصد سانتیمتر"
    assert n.process("3/4 km/h") == "three quarters kilometre per hour"
    assert n.process("1½ kg") == "one and one half kilograms"
    assert n.process("۵½ kg") == "پنج و یک دوم کیلوگرم"

    print("✅ All fraction normalization tests passed successfully!")
#----------------------------------------------------------------------------------------------------------------------------
def test_symbol_normalization():
    n = Normalizer()

    assert n.process("علی & محسن") == "علی و محسن"
    assert n.process("Ali & Mohsen") == "Ali and Mohsen"
    assert n.process("R&D") == "R and D"
    assert n.process("Tom &Jerry") == "Tom and Jerry"
    assert n.process("4 & 5") == "four and five"
    assert n.process("۴ & ۵") == "چهار و پنج"
    assert n.process("3/4 & 7/3") == "three quarters and seven thirds"
    assert n.process("۱/۲ & ۳/۲") == "یک دوم و سه دوم"
    assert n.process("Farzin & 2 friends") == "Farzin and two friends"
    assert n.process("Chapter V.") == "Chapter five."
    assert n.process("Mohsen V.") == "Mohsen V."
    assert n.process("II & IV") == "two and four"
    assert n.process("3$ & 4€") == "three dollars and four euros"
    assert n.process("بخش V  را بخوان") == "بخش پنج را بخوان"

    assert n.process("- 2 kg") == "negative two kilograms"
    assert n.process("3+4") == "three plus four"
    assert n.process("3×4") == "three times four"
    assert n.process("3 × 4=12.") == "three times four equals twelve."
    assert n.process("8 ÷ 2") == "eight divided by two"
    assert n.process("۸ ÷ ۲") == "هشت تقسیم بر دو"
    assert n.process("۸ × ۲ = 16") == "هشت ضربدر دو مساوی است با شانزده"
    assert n.process("۸ * ۲ = 16") == "هشت ضربدر دو مساوی است با شانزده"
    assert n.process("5 - 3 = 2") == "five minus three equals two"
    assert n.process("5,000 - 3000 = 2000") == "five thousand minus three thousand equals two thousand"
    assert n.process("۵ - ۳ = ۲") == "پنج منهای سه مساوی است با دو"
    assert n.process("5kg + 3kg = 8kg") == "five kilograms plus three kilograms equals eight kilograms"
    assert n.process("Tom + Jerry") == "Tom plus Jerry"
    
    assert n.process("5 - 10") == "five to ten"
    assert n.process("1/2 - 3/4") == "one half to three quarters"
    assert n.process("5kg - 10kg") == "five kilograms to ten kilograms"
    assert n.process("5% - 10%") == "five percent to ten percent"
    assert n.process("1990 - 2000") == "one thousand, nine hundred and ninety to two thousand"

    assert n.process('3 "m"') == 'three "metres"'
    assert n.process('3 (kg)') == 'three (kilograms)'
    assert n.process('3 {kg}') == 'three {kilograms}'
    assert n.process('3 [kg]') == 'three [kilograms]'
    assert n.process('(3) + (4)') == '(three) plus (four)'
    assert n.process('3 $ + [4 oz]') == 'three dollars plus [four ounces]'
    assert n.process('[3]-[5]') == '[three] to [five]'
    assert n.process('[۳] - ۵') == '[سه] تا پنج'

    print("✅ All symbol normalization tests passed successfully!")
#----------------------------------------------------------------------------------------------------------------------------
def test_phone_normalization():
    n = Normalizer()

    assert n.process("۰۹۱۵۶۴۸۶۳۲۰") == "صفر نهصد و پانزده، ششصد و چهل و هشت، شصت و سه، بیست"
    assert n.process("۰۹۱۵-۶۴۸۶۳۲۰") == "صفر نهصد و پانزده، ششصد و چهل و هشت، شصت و سه، بیست"
    assert n.process("+۹۸۹۱۵۶۴۸۶۳۲۰") == "مثبت نود و هشت، نهصد و پانزده، ششصد و چهل و هشت، شصت و سه، بیست"
    assert n.process("(+۹۸۹۱۵) ۶۴۸۶۳۲۰") == "(مثبت نود و هشت، نهصد و پانزده)، ششصد و چهل و هشت، شصت و سه، بیست"
    assert n.process("۰۲۱-۸۸۵۲۳۰۰۶") == "صفر بیست و یک، هشتاد و هشت، پنجاه و دو، سی، صفر شش"
    assert n.process("(۰۲۱) ۸۸۵۲۳۰۰۶") == "(صفر بیست و یک)، هشتاد و هشت، پنجاه و دو، سی، صفر شش"
    assert n.process("(۰۲۱)۸۸۵۲۳۰۰۶") == "(صفر بیست و یک)، هشتاد و هشت، پنجاه و دو، سی، صفر شش"
    assert n.process("۰۰۱-۸۸۵۲۳۰۰۶") == "دو صفر یک، هشتاد و هشت، پنجاه و دو، سی، صفر شش"
    assert n.process("09156486320") == "zero nine one five, six four eight, six three, two zero"
    assert n.process("0915-6486320") == "zero nine one five, six four eight, six three, two zero"
    assert n.process("(0915) 6486320") == "(zero nine one five), six four eight, six three, two zero"
    assert n.process("(0915)6486320") == "(zero nine one five), six four eight, six three, two zero"
    assert n.process("+989156486320") == "plus nine eight, nine one five, six four eight, six three, two zero"
    assert n.process("(+98915) 6486320") == "(plus nine eight, nine one five), six four eight, six three, two zero"
    assert n.process("02188523006") == "zero two one, eight eight, five two, three zero, zero six"
    assert n.process("021-88523006") == "zero two one, eight eight, five two, three zero, zero six"
    assert n.process("Call 1-800-555-1234") == "Call one, eight zero zero, five five five, one two three four"
    assert n.process("زنگ بزن به 09356486320") == "زنگ بزن به صفر نهصد و سی و پنج، ششصد و چهل و هشت، شصت و سه، بیست"
    
    print("✅ All phone normalization tests passed successfully!")
#----------------------------------------------------------------------------------------------------------------------------    
def test_card_normalization():
    n = Normalizer()

    assert n.process("6219-8619-1635-6362") == "sixty-two, nineteen - eighty-six, nineteen - sixteen, thirty-five - sixty-three, sixty-two"
    assert n.process("6200-8619-1635-6305") == "sixty-two, double zero - eighty-six, nineteen - sixteen, thirty-five - sixty-three, oh five"
    assert n.process("6200861916356305") == "sixty-two, double zero - eighty-six, nineteen - sixteen, thirty-five - sixty-three, oh five"
    assert n.process("۶۲۱۹-۸۶۱۹-۱۶۳۵-۶۳۶۲") == "شصت و دو، نوزده - هشتاد و شش، نوزده - شانزده، سی و پنج - شصت و سه، شصت و دو"
    assert n.process("۶۲۰۰-۸۶۱۹-۱۶۳۵-۶۳۰۵") == "شصت و دو، دو صفر - هشتاد و شش، نوزده - شانزده، سی و پنج - شصت و سه، صفر پنج"
    assert n.process("۶۲۰۰۸۶۱۹۱۶۳۵۶۳۰۵") == "شصت و دو، دو صفر - هشتاد و شش، نوزده - شانزده، سی و پنج - شصت و سه، صفر پنج"
    assert n.process("شماره کارت من رو یادداشت کنین: 6200861916356305") == "شماره کارت من رو یادداشت کنین: شصت و دو، دو صفر - هشتاد و شش، نوزده - شانزده، سی و پنج - شصت و سه، صفر پنج"
    
    print("✅ All card normalization tests passed successfully!")
#----------------------------------------------------------------------------------------------------------------------------    
def test_postal_nationalId_normalization():
    n = Normalizer()

    assert n.process("1514717118") == "fifteen, fourteen, seventy-one, seventy-one, eighteen"
    assert n.process("15147-17118") == "fifteen, fourteen, seventy-one, seventy-one, eighteen"
    assert n.process("۱۵۱۴۷۱۷۱۱۸") == "پانزده، چهارده، هفتاد و یک، هفتاد و یک، هجده"
    assert n.process("۱۵۱۴۷-۱۷۱۱۸") == "پانزده، چهارده، هفتاد و یک، هفتاد و یک، هجده"

    assert n.process("0010062637") == "double zero, ten, oh six, twenty-six, thirty-seven"
    assert n.process("[0010062637]") == "[double zero, ten, oh six, twenty-six, thirty-seven]"
    assert n.process("۰۰۱۰۰۶۲۶۳۷") == "دو صفر، ده، صفر شش، بیست و شش، سی و هفت"

    print("✅ All postal and national id normalization tests passed successfully!")
    
#----------------------------------------------------------------------------------------------------------------------------    
def test_plain_number_normalization():
    n = Normalizer()

    assert n.process("۳.۵") == "سه و پنج دهم"
    assert n.process("3.5") == "three point five"
    assert n.process("من ۲۰ سیب دارم") == "من بیست سیب دارم"
    assert n.process("۱۴۰۳") == "یک هزار و چهارصد و سه"
    assert n.process("سال ۱۴۰۳") == "سال هزار و چهارصد و سه"
    assert n.process("4338135") == "four million, three hundred and thirty-eight thousand, one hundred and thirty-five"

    print("✅ All plain number normalization tests passed successfully!")
    
#----------------------------------------------------------------------------------------------------------------------------    
if __name__ == "__main__":
    test_currency_normalization()
    test_unit_normalization()
    test_fraction_normalization()
    test_symbol_normalization()
    test_phone_normalization()
    test_card_normalization()
    test_postal_nationalId_normalization()
    test_plain_number_normalization()