From 260bb19db24586d6bc17e3d69dcac6ba5cf6a1fc Mon Sep 17 00:00:00 2001 From: Erickson Silva Date: Fri, 30 May 2014 16:28:42 -0300 Subject: [PATCH] Converte individualmente numeral para sua representacao textual --- tradutor/src/py/Output.py | 3 +-- tradutor/src/py/StringAux.py | 69 ++++++++++++++++++--------------------------------------------------- 2 files changed, 19 insertions(+), 53 deletions(-) diff --git a/tradutor/src/py/Output.py b/tradutor/src/py/Output.py index 1ffcea1..3259d3c 100644 --- a/tradutor/src/py/Output.py +++ b/tradutor/src/py/Output.py @@ -19,7 +19,6 @@ class Output(object): self.it.load(ts) while(self.it.hasNext()): self.__glosa.append(self.it.getAtualW()) - self.__glosa.append(" ") self.it.reset() - return ''.join(self.__glosa) + return ' '.join(self.__glosa) diff --git a/tradutor/src/py/StringAux.py b/tradutor/src/py/StringAux.py index b8045a3..e690a6b 100644 --- a/tradutor/src/py/StringAux.py +++ b/tradutor/src/py/StringAux.py @@ -3,58 +3,26 @@ from unicodedata import normalize -ext = [{1:"um", 2:"dois", 3:"três", 4:"quatro", 5:"cinco", 6:"seis", -7:"sete", 8:"oito", 9:"nove", 10:"dez", 11:"onze", 12:"doze", -13:"treze", 14:"quatorze", 15:"quinze", 16:"dezesseis", -17:"dezessete", 18:"dezoito", 19:"dezenove"}, {2:"vinte", 3:"trinta", -4:"quarenta", 5:"cinquenta", 6:"sessenta", 7:"setenta", 8:"oitenta", -9:"noventa"}, {1:"cento", 2:"duzentos", 3:"trezentos", -4:"quatrocentos", 5:"quinhentos", 6:"seissentos", 7:"setessentos", -8:"oitocentos", 9:"novecentos"}] +ext = {1:"um", 2:"dois", 3:"três", 4:"quatro", 5:"cinco", 6:"seis", 7:"sete", 8:"oito", 9:"nove", 0:"zero"} -und = ['', ' mil', (' milhão', ' milhões'), (' bilhão', ' bilhões'), -(' trilhão', ' trilhões')] - -numeral_map = zip( - (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1), - ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I') -) - -def cent(s, grand): - s = '0' * (3 - len(s)) + s - if s == '000': - return '' - if s == '100': - return 'cem' - ret = '' - dez = s[1] + s[2] - if s[0] != '0': - ret += ext[2][int(s[0])] - if dez != '00': - ret += ' e ' - else: - return ret + (type(und[grand]) == type(()) and (int(s) > 1 and und[grand][1] or und[grand][0]) or und[grand]) - if int(dez) < 20: - ret += ext[0][int(dez)] - else: - if s[1] != '0': - ret += ext[1][int(s[1])] - if s[2] != '0': - ret += ' e ' + ext[0][int(s[2])] - - return ret + (type(und[grand]) == type(()) and (int(s) > 1 and und[grand][1] or und[grand][0]) or und[grand]) +def extenso(n): + strn = str(n) + sizen = len(strn) + tokens = [] + for i in range (0, sizen): + x = int(strn[i]) + tokens.append(ext[x]) + return ' '.join(tokens) +""" def extenso(n): - sn = str(int(n)) - ret = [] - grand = 0 - while sn: - s = sn[-3:] - sn = sn[:-3] - ret.append(cent(s, grand)) - grand += 1 - ret.reverse() - return ' e '.join([r for r in ret if r]) + strn = str(n) + sizen = len(strn) + tokens = [] + for i in range (0, sizen): + tokens.append(strn[i]) + return ' '.join(tokens) +""" def remover_acentos(txt): @@ -97,8 +65,7 @@ def roman_to_int(input): raise ValueError, 'input is not a valid Roman numeral: %s' % input if int_to_roman(sum) == input: return sum - else: - raise ValueError, 'input is not a valid Roman numeral: %s' % input + else: raise ValueError, 'input is not a valid Roman numeral: %s' % input def int_to_roman(input): if not isinstance(input, type(1)): -- libgit2 0.21.2