diff --git a/src/new/AplicaRegras.py b/src/new/AplicaRegras.py index 609a04f..19d33ae 100644 --- a/src/new/AplicaRegras.py +++ b/src/new/AplicaRegras.py @@ -9,6 +9,8 @@ from LeitorDicionarios import * from Iterator import * from StringAux import * +from ConversorExtenso import * +from collections import deque class AplicaRegras(object): @@ -23,6 +25,7 @@ class AplicaRegras(object): self.__ts = [] self.__verb = False self.__adv = False + self.__num = False self.__plural = False self.__countVerb = 0 self.__countAdv = 0 @@ -33,6 +36,9 @@ class AplicaRegras(object): if self.__dicionarios.hasPalavraIgnorada(tag) == False: # verifica se nao eh artigo/preposicao + if tag == "NUM": + self.__num = True + if tag[-2:] == "-P": self.__plural = True @@ -75,7 +81,11 @@ class AplicaRegras(object): self.__ts = self.verbalAnalysis(self.__ts) #VERIFICA SE É PLURAL - if self.__plural: return self.hasPlural(self.__ts) + if self.__plural: + self.__ts = self.hasPlural(self.__ts) + + #CONVERTE EXTENSO PARA NUMERO + if self.__num: return self.converteExtenso(self.__ts) return self.__ts @@ -138,7 +148,7 @@ class AplicaRegras(object): tmp = lista for e in tmp: if e[1][-2:] == "-P": - e[0] = analisarPlural(e[0]) + e[0] = self.analisarPlural(e[0]) return tmp @@ -165,4 +175,37 @@ class AplicaRegras(object): #TODO: Palavras paroxítonas ou proparoxítonas terminadas em S. Ex: lápis, vírus, tagênis, ônibus, etc return word[0:-1] else: - return word \ No newline at end of file + return word + + + def converteExtenso(self, lista): + + listAux = [] + indexDel = [] + count = 0 + isRunning = False + + for i in range(0, len(lista)): + token = lista[i][0] + tag = lista[i][1] + if (tag == "NUM"): + if (isRunning == False and len(listAux) == count): + listAux.append([i,[token]]) + isRunning = True + else: + listAux[count][1].append(token) + indexDel.append(i) + elif (isRunning == True): + if ((lista[i-1][1] == "NUM") and (lista[i+1][1] == "NUM") and (tag == "CONJ")): + indexDel.append(i) + else: + isRunning = False + count += 1 + + for i in listAux: + ext = extenso(' '.join(i[1])) + lista[i[0]] = [ext, "NUM"] + + deque((list.pop(lista, i) for i in sorted(indexDel, reverse=True)), maxlen=0) + + return lista diff --git a/src/new/Tradutor.py b/src/new/Tradutor.py index e0c2bbc..4489be5 100644 --- a/src/new/Tradutor.py +++ b/src/new/Tradutor.py @@ -18,7 +18,7 @@ def iniciarTraducao(texto): textoDividido = texto.split(".") for w in textoDividido: if len(w) > 0: - gerarAnalise(w) + return gerarAnalise(w) def gerarAnalise(sentenca): '''tokens = alexp.toqueniza(sentenca) @@ -30,7 +30,7 @@ def gerarAnalise(sentenca): if (isinstance(analise,type(None))): analise = alexp.getAnaliseMorfologica() - print analiseMorfologica(analise) + return analiseMorfologica(analise) else: print analiseSintatica(analise) -- libgit2 0.21.2