Commit 82a7f1e6a2cec486252bb248a19a024fafac072f

Authored by Erickson Silva
1 parent 4e2fc3df
Exists in devel

Implementa tradução em nova thread

Showing 1 changed file with 7 additions and 23 deletions   Show diff stats
src/PortGlosa.py
@@ -8,22 +8,15 @@ @@ -8,22 +8,15 @@
8 8
9 import sys 9 import sys
10 from ThreadTradutor import * 10 from ThreadTradutor import *
11 -from TraduzSentencas import *  
12 from LerDicionarios import * 11 from LerDicionarios import *
13 12
14 -tradutor = TraduzSentencas()  
15 taxas = [] 13 taxas = []
16 14
17 -def traduzir(texto, log=None, threads=False, taxa_qualidade=False):  
18 - #tradutor.set_level(log) if log != None else tradutor.desativar_logging() 15 +def traduzir(texto, threads=False, taxa_qualidade=False):
19 if texto.isspace() or texto == "": 16 if texto.isspace() or texto == "":
20 - #or not checar_idioma(texto):  
21 return "ESCOLHER TEXTO CERTO" 17 return "ESCOLHER TEXTO CERTO"
22 -  
23 - #elif threads:  
24 - # return iniciar_com_threads(texto, taxa_qualidade)  
25 -  
26 - #else: 18 + elif threads:
  19 + return iniciar_com_threads(texto, taxa_qualidade)
27 return iniciar_sem_threads(texto, taxa_qualidade) 20 return iniciar_sem_threads(texto, taxa_qualidade)
28 21
29 def iniciar_com_threads(texto, taxa_qualidade): 22 def iniciar_com_threads(texto, taxa_qualidade):
@@ -52,8 +45,10 @@ def iniciar_sem_threads(texto, taxa_qualidade): @@ -52,8 +45,10 @@ def iniciar_sem_threads(texto, taxa_qualidade):
52 texto_quebrado = quebrar_texto(texto) 45 texto_quebrado = quebrar_texto(texto)
53 saidas = [] 46 saidas = []
54 for texto in texto_quebrado: 47 for texto in texto_quebrado:
55 - saida = tradutor.iniciar_traducao(texto, taxa_qualidade)  
56 - saidas.append(saida) 48 + thread_tradutor = ThreadTradutor(texto,taxa_qualidade)
  49 + thread_tradutor.start()
  50 + thread_tradutor.join()
  51 + saidas.append(thread_tradutor.obter_glosa())
57 if taxa_qualidade: 52 if taxa_qualidade:
58 return gerar_taxa_qualidade(saidas) 53 return gerar_taxa_qualidade(saidas)
59 return " ".join(saidas) 54 return " ".join(saidas)
@@ -101,17 +96,6 @@ def gerar_taxa_qualidade(lista_saidas): @@ -101,17 +96,6 @@ def gerar_taxa_qualidade(lista_saidas):
101 taxa_sentenca = (float(soma_taxas)/len(lista_saidas)) * 0.80 96 taxa_sentenca = (float(soma_taxas)/len(lista_saidas)) * 0.80
102 return {'glosa':" ".join(glosas), 'taxa_qualidade': float("%.2f" % (taxa_sintatica+taxa_sentenca))} 97 return {'glosa':" ".join(glosas), 'taxa_qualidade': float("%.2f" % (taxa_sintatica+taxa_sentenca))}
103 98
104 -def checar_idioma(texto):  
105 - try:  
106 - texto.decode('cp1252')  
107 - except:  
108 - return False  
109 - return True  
110 -  
111 -def ajuda():  
112 - #TODO: Adicionar um pequeno tuto aqui  
113 - print "Help"  
114 -  
115 if __name__ == '__main__': 99 if __name__ == '__main__':
116 texto = sys.argv[1] 100 texto = sys.argv[1]
117 glosa = traduzir(texto) 101 glosa = traduzir(texto)