Commit 28dd7772cd094362c397c42da3e97990df006634
1 parent
b268ad23
Exists in
master
and in
1 other branch
Adiciona conversão de número por extenso para numeral
Showing
2 changed files
with
48 additions
and
5 deletions
Show diff stats
src/new/AplicaRegras.py
... | ... | @@ -9,6 +9,8 @@ |
9 | 9 | from LeitorDicionarios import * |
10 | 10 | from Iterator import * |
11 | 11 | from StringAux import * |
12 | +from ConversorExtenso import * | |
13 | +from collections import deque | |
12 | 14 | |
13 | 15 | class AplicaRegras(object): |
14 | 16 | |
... | ... | @@ -23,6 +25,7 @@ class AplicaRegras(object): |
23 | 25 | self.__ts = [] |
24 | 26 | self.__verb = False |
25 | 27 | self.__adv = False |
28 | + self.__num = False | |
26 | 29 | self.__plural = False |
27 | 30 | self.__countVerb = 0 |
28 | 31 | self.__countAdv = 0 |
... | ... | @@ -33,6 +36,9 @@ class AplicaRegras(object): |
33 | 36 | |
34 | 37 | if self.__dicionarios.hasPalavraIgnorada(tag) == False: # verifica se nao eh artigo/preposicao |
35 | 38 | |
39 | + if tag == "NUM": | |
40 | + self.__num = True | |
41 | + | |
36 | 42 | if tag[-2:] == "-P": |
37 | 43 | self.__plural = True |
38 | 44 | |
... | ... | @@ -75,7 +81,11 @@ class AplicaRegras(object): |
75 | 81 | self.__ts = self.verbalAnalysis(self.__ts) |
76 | 82 | |
77 | 83 | #VERIFICA SE É PLURAL |
78 | - if self.__plural: return self.hasPlural(self.__ts) | |
84 | + if self.__plural: | |
85 | + self.__ts = self.hasPlural(self.__ts) | |
86 | + | |
87 | + #CONVERTE EXTENSO PARA NUMERO | |
88 | + if self.__num: return self.converteExtenso(self.__ts) | |
79 | 89 | |
80 | 90 | return self.__ts |
81 | 91 | |
... | ... | @@ -138,7 +148,7 @@ class AplicaRegras(object): |
138 | 148 | tmp = lista |
139 | 149 | for e in tmp: |
140 | 150 | if e[1][-2:] == "-P": |
141 | - e[0] = analisarPlural(e[0]) | |
151 | + e[0] = self.analisarPlural(e[0]) | |
142 | 152 | |
143 | 153 | return tmp |
144 | 154 | |
... | ... | @@ -165,4 +175,37 @@ class AplicaRegras(object): |
165 | 175 | #TODO: Palavras paroxítonas ou proparoxítonas terminadas em S. Ex: lápis, vírus, tagênis, ônibus, etc |
166 | 176 | return word[0:-1] |
167 | 177 | else: |
168 | - return word | |
169 | 178 | \ No newline at end of file |
179 | + return word | |
180 | + | |
181 | + | |
182 | + def converteExtenso(self, lista): | |
183 | + | |
184 | + listAux = [] | |
185 | + indexDel = [] | |
186 | + count = 0 | |
187 | + isRunning = False | |
188 | + | |
189 | + for i in range(0, len(lista)): | |
190 | + token = lista[i][0] | |
191 | + tag = lista[i][1] | |
192 | + if (tag == "NUM"): | |
193 | + if (isRunning == False and len(listAux) == count): | |
194 | + listAux.append([i,[token]]) | |
195 | + isRunning = True | |
196 | + else: | |
197 | + listAux[count][1].append(token) | |
198 | + indexDel.append(i) | |
199 | + elif (isRunning == True): | |
200 | + if ((lista[i-1][1] == "NUM") and (lista[i+1][1] == "NUM") and (tag == "CONJ")): | |
201 | + indexDel.append(i) | |
202 | + else: | |
203 | + isRunning = False | |
204 | + count += 1 | |
205 | + | |
206 | + for i in listAux: | |
207 | + ext = extenso(' '.join(i[1])) | |
208 | + lista[i[0]] = [ext, "NUM"] | |
209 | + | |
210 | + deque((list.pop(lista, i) for i in sorted(indexDel, reverse=True)), maxlen=0) | |
211 | + | |
212 | + return lista | ... | ... |
src/new/Tradutor.py
... | ... | @@ -18,7 +18,7 @@ def iniciarTraducao(texto): |
18 | 18 | textoDividido = texto.split(".") |
19 | 19 | for w in textoDividido: |
20 | 20 | if len(w) > 0: |
21 | - gerarAnalise(w) | |
21 | + return gerarAnalise(w) | |
22 | 22 | |
23 | 23 | def gerarAnalise(sentenca): |
24 | 24 | '''tokens = alexp.toqueniza(sentenca) |
... | ... | @@ -30,7 +30,7 @@ def gerarAnalise(sentenca): |
30 | 30 | |
31 | 31 | if (isinstance(analise,type(None))): |
32 | 32 | analise = alexp.getAnaliseMorfologica() |
33 | - print analiseMorfologica(analise) | |
33 | + return analiseMorfologica(analise) | |
34 | 34 | else: |
35 | 35 | print analiseSintatica(analise) |
36 | 36 | ... | ... |