Commit 02e4652aecfd78a071e6311a56e2d05b2a05929a

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

Verifica se texto recebido é compatível com a codificação cp1252

Showing 1 changed file with 7 additions and 1 deletions   Show diff stats
src/PortGlosa.py
... ... @@ -18,7 +18,7 @@ taxas = []
18 18  
19 19 def traduzir(texto, log=None, threads=False, taxa_qualidade=False):
20 20 tradutor.set_level(log) if log != None else tradutor.desativar_logging()
21   - if texto.isspace() or texto == "":
  21 + if texto.isspace() or texto == "" or not checar_idioma(texto):
22 22 return "ESCOLHER TEXTO CERTO"
23 23  
24 24 elif threads:
... ... @@ -93,6 +93,12 @@ def gerar_taxa_qualidade(lista_saidas):
93 93 taxa_sentenca = (float(soma_taxas)/len(lista_saidas)) * 0.80
94 94 return {'glosa':" ".join(glosas), 'taxa_qualidade': float("%.2f" % (taxa_sintatica+taxa_sentenca))}
95 95  
  96 +def checar_idioma(texto):
  97 + try:
  98 + texto.decode('cp1252')
  99 + except:
  100 + return False
  101 + return True
96 102  
97 103 def ajuda():
98 104 #TODO: Adicionar um pequeno tuto aqui
... ...