From 02e4652aecfd78a071e6311a56e2d05b2a05929a Mon Sep 17 00:00:00 2001 From: Erickson Silva Date: Mon, 13 Jul 2015 09:49:12 -0300 Subject: [PATCH] Verifica se texto recebido é compatível com a codificação cp1252 --- src/PortGlosa.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/PortGlosa.py b/src/PortGlosa.py index 83c8825..be90b9b 100644 --- a/src/PortGlosa.py +++ b/src/PortGlosa.py @@ -18,7 +18,7 @@ taxas = [] def traduzir(texto, log=None, threads=False, taxa_qualidade=False): tradutor.set_level(log) if log != None else tradutor.desativar_logging() - if texto.isspace() or texto == "": + if texto.isspace() or texto == "" or not checar_idioma(texto): return "ESCOLHER TEXTO CERTO" elif threads: @@ -93,6 +93,12 @@ def gerar_taxa_qualidade(lista_saidas): taxa_sentenca = (float(soma_taxas)/len(lista_saidas)) * 0.80 return {'glosa':" ".join(glosas), 'taxa_qualidade': float("%.2f" % (taxa_sintatica+taxa_sentenca))} +def checar_idioma(texto): + try: + texto.decode('cp1252') + except: + return False + return True def ajuda(): #TODO: Adicionar um pequeno tuto aqui -- libgit2 0.21.2