Commit 744f614ad8c71fc3b9b0f9775a3f8b6f88721550
1 parent
08259118
Exists in
master
and in
1 other branch
Corrige quebra de orações
Showing
2 changed files
with
49 additions
and
5 deletions
Show diff stats
src/LerDicionarios.py
| @@ -29,7 +29,8 @@ class LerDicionarios(Singleton): | @@ -29,7 +29,8 @@ class LerDicionarios(Singleton): | ||
| 29 | self.set_art = [] | 29 | self.set_art = [] |
| 30 | self.set_prep = [] | 30 | self.set_prep = [] |
| 31 | self.dic_sin = {} | 31 | self.dic_sin = {} |
| 32 | - self.set_sb_2_gen = [] | 32 | + self.set_sb_2_gen = [] |
| 33 | + self.set_pron_trat = [] | ||
| 33 | self.dic_vb_infinitivo = {} | 34 | self.dic_vb_infinitivo = {} |
| 34 | self.set_vb_ligacao = [] | 35 | self.set_vb_ligacao = [] |
| 35 | self.dic_vb_muda_negacao = [] | 36 | self.dic_vb_muda_negacao = [] |
| @@ -165,6 +166,17 @@ class LerDicionarios(Singleton): | @@ -165,6 +166,17 @@ class LerDicionarios(Singleton): | ||
| 165 | rows.append(row[0].decode("utf-8")) | 166 | rows.append(row[0].decode("utf-8")) |
| 166 | self.set_vb_ligacao = set(rows) | 167 | self.set_vb_ligacao = set(rows) |
| 167 | 168 | ||
| 169 | + def carregar_pronomes_tratamento(self): | ||
| 170 | + try: | ||
| 171 | + self.file = csv.reader(open(self.path+"pronomesTratamento.csv")) | ||
| 172 | + except IOError, (errno, strerror): | ||
| 173 | + print "I/O error(%s): %s" % (errno, strerror) | ||
| 174 | + print "carregar_pronomes_tratamento" | ||
| 175 | + | ||
| 176 | + rows = [] | ||
| 177 | + for row in self.file: | ||
| 178 | + rows.append(row[0].decode("utf-8")) | ||
| 179 | + self.set_pron_trat = set(rows) | ||
| 168 | 180 | ||
| 169 | def carregar_verbos_muda_negacao(self): | 181 | def carregar_verbos_muda_negacao(self): |
| 170 | try: | 182 | try: |
| @@ -195,6 +207,9 @@ class LerDicionarios(Singleton): | @@ -195,6 +207,9 @@ class LerDicionarios(Singleton): | ||
| 195 | def has_sinonimo(self, token): | 207 | def has_sinonimo(self, token): |
| 196 | return self.dic_sin.has_key(token) | 208 | return self.dic_sin.has_key(token) |
| 197 | 209 | ||
| 210 | + def has_pron_tratam(self, token): | ||
| 211 | + return token in self.set_pron_trat | ||
| 212 | + | ||
| 198 | def has_subst_2_generos (self, token): | 213 | def has_subst_2_generos (self, token): |
| 199 | return token in self.set_sb_2_gen | 214 | return token in self.set_sb_2_gen |
| 200 | 215 |
src/PortGlosa.py
| @@ -8,9 +8,11 @@ | @@ -8,9 +8,11 @@ | ||
| 8 | 8 | ||
| 9 | from ThreadTradutor import * | 9 | from ThreadTradutor import * |
| 10 | from TraduzSentencas import * | 10 | from TraduzSentencas import * |
| 11 | +from LerDicionarios import * | ||
| 11 | 12 | ||
| 12 | 13 | ||
| 13 | tradutor = TraduzSentencas() | 14 | tradutor = TraduzSentencas() |
| 15 | +dicionario = LerDicionarios() | ||
| 14 | 16 | ||
| 15 | def traduzir(texto, threads=False): | 17 | def traduzir(texto, threads=False): |
| 16 | if texto.isspace() or texto == "": | 18 | if texto.isspace() or texto == "": |
| @@ -42,18 +44,45 @@ def iniciar_com_threads(texto): | @@ -42,18 +44,45 @@ def iniciar_com_threads(texto): | ||
| 42 | return None | 44 | return None |
| 43 | 45 | ||
| 44 | def iniciar_sem_threads(texto): | 46 | def iniciar_sem_threads(texto): |
| 45 | - return tradutor.iniciar_traducao(texto) | ||
| 46 | - | 47 | + texto_quebrado = quebrar_texto(texto) |
| 48 | + texto_traduzido = [] | ||
| 49 | + for texto in texto_quebrado: | ||
| 50 | + glosa = tradutor.iniciar_traducao(texto) | ||
| 51 | + texto_traduzido.append(glosa) | ||
| 52 | + return " ".join(texto_traduzido) | ||
| 53 | + | ||
| 54 | +''' | ||
| 47 | def quebrar_texto(texto): | 55 | def quebrar_texto(texto): |
| 48 | quantidade_pontos = texto.count('. ') | 56 | quantidade_pontos = texto.count('. ') |
| 49 | sentencas = [] | 57 | sentencas = [] |
| 58 | + if quantidade_pontos == 0: | ||
| 59 | + return [texto] | ||
| 50 | for i in range(quantidade_pontos): | 60 | for i in range(quantidade_pontos): |
| 51 | posicao_ponto = texto.find('.') | 61 | posicao_ponto = texto.find('.') |
| 52 | if texto[posicao_ponto+2].isupper(): | 62 | if texto[posicao_ponto+2].isupper(): |
| 53 | sentencas.append(texto[:posicao_ponto]) | 63 | sentencas.append(texto[:posicao_ponto]) |
| 54 | texto = texto[posicao_ponto+2:] | 64 | texto = texto[posicao_ponto+2:] |
| 55 | - if len(texto) > 0: | ||
| 56 | - sentencas.append(texto) | 65 | + return sentencas |
| 66 | +''' | ||
| 67 | + | ||
| 68 | +def quebrar_texto(texto): | ||
| 69 | + if '.' not in texto: | ||
| 70 | + return [texto] | ||
| 71 | + | ||
| 72 | + texto_quebrado = texto.split() | ||
| 73 | + tamanho_texto_quebrado = len(texto_quebrado) | ||
| 74 | + sentencas = [] | ||
| 75 | + lista_texto = [] | ||
| 76 | + for i in range(tamanho_texto_quebrado): | ||
| 77 | + lista_texto.append(texto_quebrado[i]) | ||
| 78 | + if '.' in texto_quebrado[i]: | ||
| 79 | + if not dicionario.has_pron_tratam(texto_quebrado[i].lower()) and i < tamanho_texto_quebrado-1 and texto_quebrado[i+1][0].isupper(): | ||
| 80 | + sentenca = " ".join(lista_texto)[:-1] | ||
| 81 | + sentencas.append(sentenca) | ||
| 82 | + lista_texto = [] | ||
| 83 | + continue | ||
| 84 | + if lista_texto: | ||
| 85 | + sentencas.append( " ".join(lista_texto)) | ||
| 57 | return sentencas | 86 | return sentencas |
| 58 | 87 | ||
| 59 | def ajuda(): | 88 | def ajuda(): |