Commit 260bb19db24586d6bc17e3d69dcac6ba5cf6a1fc

Authored by Erickson Silva
1 parent ff91b8b1
Exists in master and in 1 other branch devel

Converte individualmente numeral para sua representacao textual

tradutor/src/py/Output.py
... ... @@ -19,7 +19,6 @@ class Output(object):
19 19 self.it.load(ts)
20 20 while(self.it.hasNext()):
21 21 self.__glosa.append(self.it.getAtualW())
22   - self.__glosa.append(" ")
23 22 self.it.reset()
24   - return ''.join(self.__glosa)
  23 + return ' '.join(self.__glosa)
25 24  
... ...
tradutor/src/py/StringAux.py
... ... @@ -3,58 +3,26 @@
3 3  
4 4 from unicodedata import normalize
5 5  
6   -ext = [{1:"um", 2:"dois", 3:"três", 4:"quatro", 5:"cinco", 6:"seis",
7   -7:"sete", 8:"oito", 9:"nove", 10:"dez", 11:"onze", 12:"doze",
8   -13:"treze", 14:"quatorze", 15:"quinze", 16:"dezesseis",
9   -17:"dezessete", 18:"dezoito", 19:"dezenove"}, {2:"vinte", 3:"trinta",
10   -4:"quarenta", 5:"cinquenta", 6:"sessenta", 7:"setenta", 8:"oitenta",
11   -9:"noventa"}, {1:"cento", 2:"duzentos", 3:"trezentos",
12   -4:"quatrocentos", 5:"quinhentos", 6:"seissentos", 7:"setessentos",
13   -8:"oitocentos", 9:"novecentos"}]
  6 +ext = {1:"um", 2:"dois", 3:"três", 4:"quatro", 5:"cinco", 6:"seis", 7:"sete", 8:"oito", 9:"nove", 0:"zero"}
14 7  
15   -und = ['', ' mil', (' milhão', ' milhões'), (' bilhão', ' bilhões'),
16   -(' trilhão', ' trilhões')]
17   -
18   -numeral_map = zip(
19   - (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
20   - ('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
21   -)
22   -
23   -def cent(s, grand):
24   - s = '0' * (3 - len(s)) + s
25   - if s == '000':
26   - return ''
27   - if s == '100':
28   - return 'cem'
29   - ret = ''
30   - dez = s[1] + s[2]
31   - if s[0] != '0':
32   - ret += ext[2][int(s[0])]
33   - if dez != '00':
34   - ret += ' e '
35   - else:
36   - return ret + (type(und[grand]) == type(()) and (int(s) > 1 and und[grand][1] or und[grand][0]) or und[grand])
37   - if int(dez) < 20:
38   - ret += ext[0][int(dez)]
39   - else:
40   - if s[1] != '0':
41   - ret += ext[1][int(s[1])]
42   - if s[2] != '0':
43   - ret += ' e ' + ext[0][int(s[2])]
44   -
45   - return ret + (type(und[grand]) == type(()) and (int(s) > 1 and und[grand][1] or und[grand][0]) or und[grand])
  8 +def extenso(n):
  9 + strn = str(n)
  10 + sizen = len(strn)
  11 + tokens = []
  12 + for i in range (0, sizen):
  13 + x = int(strn[i])
  14 + tokens.append(ext[x])
  15 + return ' '.join(tokens)
46 16  
  17 +"""
47 18 def extenso(n):
48   - sn = str(int(n))
49   - ret = []
50   - grand = 0
51   - while sn:
52   - s = sn[-3:]
53   - sn = sn[:-3]
54   - ret.append(cent(s, grand))
55   - grand += 1
56   - ret.reverse()
57   - return ' e '.join([r for r in ret if r])
  19 + strn = str(n)
  20 + sizen = len(strn)
  21 + tokens = []
  22 + for i in range (0, sizen):
  23 + tokens.append(strn[i])
  24 + return ' '.join(tokens)
  25 +"""
58 26  
59 27 def remover_acentos(txt):
60 28  
... ... @@ -97,8 +65,7 @@ def roman_to_int(input):
97 65 raise ValueError, 'input is not a valid Roman numeral: %s' % input
98 66  
99 67 if int_to_roman(sum) == input: return sum
100   - else:
101   - raise ValueError, 'input is not a valid Roman numeral: %s' % input
  68 + else: raise ValueError, 'input is not a valid Roman numeral: %s' % input
102 69  
103 70 def int_to_roman(input):
104 71 if not isinstance(input, type(1)):
... ...