From 64fee908ac9b0e3d238ea25cac350927ce8b7ccd Mon Sep 17 00:00:00 2001 From: Mariano de Deus Date: Thu, 11 Apr 2024 15:51:36 +0900 Subject: [PATCH 1/6] add new source code for to_cardinal tet --- num2words/lang_TET.py | 48 ++++++++++++------------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/num2words/lang_TET.py b/num2words/lang_TET.py index a9cde915..8d0556f5 100644 --- a/num2words/lang_TET.py +++ b/num2words/lang_TET.py @@ -86,15 +86,15 @@ def setup(self): }, { 0: "", - 1: "daatusidak", - 2: "daatusruak", - 3: "daatustoluk", - 4: "daatushaat", - 5: "daatuslimak", - 6: "daatusneen", - 7: "daatushituk", - 8: "daatusualuk", - 9: "daatussiak", + 1: "daatus idak", + 2: "daatus ruak", + 3: "daatus toluk", + 4: "daatus haat", + 5: "daatus limak", + 6: "daatus neen", + 7: "daatus hituk", + 8: "daatus ualuk", + 9: "daatus siak", }, ] self.thousand_separators = { @@ -159,32 +159,10 @@ def to_cardinal(self, value): def to_ordinal(self, value): # Before changing this function remember this is used by pt-BR # so act accordingly - self.verify_ordinal(value) - - result = [] - value = str(value) - thousand_separator = '' - - for idx, char in enumerate(value[::-1]): - if idx and idx % 3 == 0: - thousand_separator = self.thousand_separators[idx] - - if char != '0' and thousand_separator: - # avoiding "segundo milionésimo milésimo" for 6000000, - # for instance - result.append(thousand_separator) - thousand_separator = '' - - result.append(self.ords[idx % 3][int(char)]) - - result = ' '.join(result[::-1]) - result = result.strip() - result = re.sub('\\s+', ' ', result) - - if result.startswith('primeiru') and value != '1': - # avoiding "primeiro milésimo", "primeiro milionésimo" and so on - result = result[9:] - + self.verify_ordinal(number) + cardinal = self.to_cardinal(value) + cardinal = cardinal.split() + result = " ".join(cardinal) return result def to_ordinal_num(self, value): From e49694b7581e6023a00d667985c0fb81305cacab Mon Sep 17 00:00:00 2001 From: Mariano de Deus Date: Fri, 12 Apr 2024 12:06:01 +0900 Subject: [PATCH 2/6] add ordinal to tetun --- num2words/lang_TET.py | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/num2words/lang_TET.py b/num2words/lang_TET.py index 8d0556f5..d285e8eb 100644 --- a/num2words/lang_TET.py +++ b/num2words/lang_TET.py @@ -159,11 +159,42 @@ def to_cardinal(self, value): def to_ordinal(self, value): # Before changing this function remember this is used by pt-BR # so act accordingly - self.verify_ordinal(number) - cardinal = self.to_cardinal(value) - cardinal = cardinal.split() - result = " ".join(cardinal) - return result + self.verify_ordinal(value) + try: + assert int(value) == value + except (ValueError, TypeError, AssertionError): + return self.to_cardinal_float(value) + + out = "" + if value < 0: + value = abs(value) + out = "%s " % self.negword.strip() + + if value >= self.MAXVAL: + raise OverflowError(self.errmsg_toobig % (value, self.MAXVAL)) + + val = self.splitnum(value) + outs = val + while len(val) != 1: + outs = [] + left, right = val[:2] + if isinstance(left, tuple) and isinstance(right, tuple): + outs.append(self.merge(left, right)) + if val[2:]: + outs.append(val[2:]) + else: + for elem in val: + if isinstance(elem, list): + if len(elem) == 1: + outs.append(elem[0]) + else: + outs.append(self.clean(elem)) + else: + outs.append(('da'+str(elem[0]), elem[1])) + val = outs + words, num = outs[0] + #words, num = self.clean(val) + return self.title(out + words) def to_ordinal_num(self, value): # Before changing this function remember this is used by pt-BR From ec96fd38c4694a4bc411656e6940622e72d236ee Mon Sep 17 00:00:00 2001 From: Mariano de Deus Date: Fri, 12 Apr 2024 14:57:04 +0900 Subject: [PATCH 3/6] add da and k --- num2words/lang_TET.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/num2words/lang_TET.py b/num2words/lang_TET.py index d285e8eb..e78be755 100644 --- a/num2words/lang_TET.py +++ b/num2words/lang_TET.py @@ -193,6 +193,21 @@ def to_ordinal(self, value): outs.append(('da'+str(elem[0]), elem[1])) val = outs words, num = outs[0] + if num in [90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 5, 3, 2]: + words = 'da'+words+'k' + if num in [6,4]: + words = 'da'+words + if num == 1: + words = 'dahuluk' + if num in [900, 800, 700, 600, 500, 400, 300, 200, 100]: + words = words+'k' + liafuan = words.split() + liafuan_primeiro = liafuan[0] + if liafuan_primeiro == 'daatus' and len(liafuan) >=3: + liafuan_segundo = liafuan[1]+'k' + liafuan_terseiro = " ".join(liafuan[2:]) + words = liafuan_primeiro+" "+liafuan_segundo+" "+lianfuan_terseiro + #words, num = self.clean(val) return self.title(out + words) From 06dc175c49afdc4869712a0e67961061889f3ff5 Mon Sep 17 00:00:00 2001 From: Mariano de Deus Date: Fri, 12 Apr 2024 16:48:33 +0900 Subject: [PATCH 4/6] fixed ordinal number for tetun language --- num2words/lang_TET.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/num2words/lang_TET.py b/num2words/lang_TET.py index e78be755..eb2f9e29 100644 --- a/num2words/lang_TET.py +++ b/num2words/lang_TET.py @@ -190,7 +190,7 @@ def to_ordinal(self, value): else: outs.append(self.clean(elem)) else: - outs.append(('da'+str(elem[0]), elem[1])) + outs.append(elem) val = outs words, num = outs[0] if num in [90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 5, 3, 2]: @@ -199,16 +199,30 @@ def to_ordinal(self, value): words = 'da'+words if num == 1: words = 'dahuluk' - if num in [900, 800, 700, 600, 500, 400, 300, 200, 100]: - words = words+'k' + if num in [900, 800, 700, 500, 300, 200, 100]: + words = 'da'+words+'k' + if num in [600, 400]: + words = 'da'+words + liafuan = words.split() - liafuan_primeiro = liafuan[0] + if len(liafuan) >= 3 and num < 100: + lia_primeiro = 'da'+liafuan[0]+'k' + lia_segundo = " ".join(liafuan[1:]) + words = lia_primeiro+" "+lia_segundo + + liafuan_primeiro = 'da'+liafuan[0] if liafuan_primeiro == 'daatus' and len(liafuan) >=3: - liafuan_segundo = liafuan[1]+'k' + test_lia = liafuan[1] + if test_lia in ['haat', 'neen']: + liafuan_segundo = liafuan[1] + else: + liafuan_segundo = liafuan[1]+'k' liafuan_terseiro = " ".join(liafuan[2:]) - words = liafuan_primeiro+" "+liafuan_segundo+" "+lianfuan_terseiro + words = liafuan_primeiro+" "+liafuan_segundo+" "+liafuan_terseiro + + if len(str(num)) >= 4: + words = 'da'+words - #words, num = self.clean(val) return self.title(out + words) def to_ordinal_num(self, value): From af53518133ce015dd3c23681fe70c3c858382ada Mon Sep 17 00:00:00 2001 From: Mariano de Deus Date: Fri, 12 Apr 2024 21:56:19 +0900 Subject: [PATCH 5/6] changed variavel to english --- num2words/lang_TET.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/num2words/lang_TET.py b/num2words/lang_TET.py index eb2f9e29..0e69db9f 100644 --- a/num2words/lang_TET.py +++ b/num2words/lang_TET.py @@ -192,7 +192,9 @@ def to_ordinal(self, value): else: outs.append(elem) val = outs + words, num = outs[0] + if num in [90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 5, 3, 2]: words = 'da'+words+'k' if num in [6,4]: @@ -204,21 +206,21 @@ def to_ordinal(self, value): if num in [600, 400]: words = 'da'+words - liafuan = words.split() - if len(liafuan) >= 3 and num < 100: - lia_primeiro = 'da'+liafuan[0]+'k' - lia_segundo = " ".join(liafuan[1:]) - words = lia_primeiro+" "+lia_segundo - - liafuan_primeiro = 'da'+liafuan[0] - if liafuan_primeiro == 'daatus' and len(liafuan) >=3: - test_lia = liafuan[1] - if test_lia in ['haat', 'neen']: - liafuan_segundo = liafuan[1] + words_split = words.split() + if len(words_split) >= 3 and num < 100: + first_word = 'da'+words_split[0]+'k' + second_word = " ".join(words_split[1:]) + words = first_word+" "+second_word + + word_first = 'da'+words_split[0] + if word_first == 'daatus' and len(words_split) >=3: + check_word = words_split[1] + if check_word in ['haat', 'neen']: + word_second = words_split[1] else: - liafuan_segundo = liafuan[1]+'k' - liafuan_terseiro = " ".join(liafuan[2:]) - words = liafuan_primeiro+" "+liafuan_segundo+" "+liafuan_terseiro + word_second = words_split[1]+'k' + word_third = " ".join(words_split[2:]) + words = word_first+" "+word_second+" "+word_third if len(str(num)) >= 4: words = 'da'+words From 4901b30ae1d0ff5f42fc9fa06bbdb5e0e672bc93 Mon Sep 17 00:00:00 2001 From: Mariano de Deus Date: Sat, 13 Apr 2024 08:20:41 +0900 Subject: [PATCH 6/6] fixed logic for ordinal number --- num2words/lang_TET.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/num2words/lang_TET.py b/num2words/lang_TET.py index 0e69db9f..1d81c50b 100644 --- a/num2words/lang_TET.py +++ b/num2words/lang_TET.py @@ -202,28 +202,32 @@ def to_ordinal(self, value): if num == 1: words = 'dahuluk' if num in [900, 800, 700, 500, 300, 200, 100]: - words = 'da'+words+'k' + words = 'dah'+words+'k' if num in [600, 400]: - words = 'da'+words + words = 'dah'+words words_split = words.split() if len(words_split) >= 3 and num < 100: - first_word = 'da'+words_split[0]+'k' + first_word = 'da'+words_split[0] second_word = " ".join(words_split[1:]) - words = first_word+" "+second_word + if 'haat' in second_word or 'neen' in second_word: + words = first_word+" "+second_word + else: + words = first_word+" "+second_word+'k' - word_first = 'da'+words_split[0] - if word_first == 'daatus' and len(words_split) >=3: - check_word = words_split[1] - if check_word in ['haat', 'neen']: - word_second = words_split[1] + word_first = 'dah'+words_split[0] + if word_first == 'dahatus' and len(words_split) >=3: + word_second = " ".join(words_split[2:]) + if 'haat' in word_second or 'neen' in word_second: + words = word_first+" "+word_second else: - word_second = words_split[1]+'k' - word_third = " ".join(words_split[2:]) - words = word_first+" "+word_second+" "+word_third + words = word_first+" "+word_second+'k' - if len(str(num)) >= 4: - words = 'da'+words + if len(str(num)) > 3: + if 'haat' in words or 'neen' in words: + words = 'da'+words + else: + words = 'da'+words+'k' return self.title(out + words)