Commit 7131db790b96008978183dceb0d3004c282035c5
1 parent
622366b7
Exists in
master
and in
1 other branch
Adiciona logging na análise sintática para obter feedback para futuras correções
Showing
3 changed files
with
35 additions
and
12 deletions
Show diff stats
data/regras.xml
... | ... | @@ -267,6 +267,15 @@ |
267 | 267 | <action>remove</action> |
268 | 268 | </class> |
269 | 269 | </rule> |
270 | + <rule name = "SR-P"><!-- tempo verbal - presente com AdvP(t) --> | |
271 | + <active>true</active> | |
272 | + <count>1</count> | |
273 | + <class> | |
274 | + <title>SR-P</title> | |
275 | + <action>change_vb</action> | |
276 | + <newprop>SR</newprop> | |
277 | + </class> | |
278 | + </rule> | |
270 | 279 | <rule name = "VB-P"><!-- tempo verbal - presente com AdvP(t) --> |
271 | 280 | <active>true</active> |
272 | 281 | <count>1</count> |
... | ... | @@ -391,14 +400,14 @@ |
391 | 400 | </rule> |
392 | 401 | </morphological> |
393 | 402 | <syntactic> |
394 | - <rule name = "S(NP_VP)"><!-- Ordem direta da sentença --> | |
403 | + <rule name = "S(VP_NP)"><!-- Ordem direta da sentença --> | |
395 | 404 | <active>true</active> |
396 | 405 | <count>2</count> |
397 | 406 | <class> |
398 | 407 | <action>invert</action> |
399 | 408 | </class> |
400 | 409 | </rule> |
401 | - <rule name = "SV(Vbar_AP)"><!-- Eliminar vebo de ligação --> | |
410 | + <rule name = "VP(Vbar_AP)"><!-- Eliminar vebo de ligação --> | |
402 | 411 | <active>true</active> |
403 | 412 | <count>2</count> |
404 | 413 | <class> | ... | ... |
src/new/TraduzSentencas.py
... | ... | @@ -10,6 +10,7 @@ from threading import Thread |
10 | 10 | import alexp |
11 | 11 | from AplicaSinonimos import * |
12 | 12 | from AplicaRegras import * |
13 | +import logging | |
13 | 14 | |
14 | 15 | class TraduzSentencas(Thread): |
15 | 16 | |
... | ... | @@ -19,20 +20,33 @@ class TraduzSentencas(Thread): |
19 | 20 | self.glosa = "" |
20 | 21 | self.aplic_sinonimos = AplicaSinonimos() |
21 | 22 | self.aplic_regras = AplicaRegras() |
23 | + logging.basicConfig(filename='translate.log', | |
24 | + format='%(asctime)s - %(levelname)s:\n%(message)s\n\n\n##############################################\n\n', | |
25 | + level=logging.ERROR) | |
26 | + | |
22 | 27 | |
23 | 28 | def run(self): |
24 | - analise_sintatica = alexp.run(self.sentenca) | |
29 | + try: | |
30 | + analise_sintatica = alexp.run(self.sentenca) | |
31 | + except Exception as ex: | |
32 | + self.salvar_log(str(ex)) | |
33 | + analise_sintatica = None | |
34 | + | |
25 | 35 | analise_morfologica = alexp.getAnaliseMorfologica() |
26 | - | |
36 | + | |
27 | 37 | if (isinstance(analise_sintatica,type(None))): |
38 | + print "# ANÁLISE MORFÓLIGCA" | |
28 | 39 | regras_aplicadas = self.aplic_regras.aplicar_regras_morfo(analise_morfologica) |
29 | 40 | else: |
41 | + print "# ANÁLISE SINTÁTICA" | |
30 | 42 | regras_aplicadas = self.aplic_regras.aplicar_regras_sint(analise_morfologica, analise_sintatica) |
31 | 43 | |
32 | - # separar tokens quando tem um newtoken | |
33 | - self.aplic_regras.separar_new_tokens(regras_aplicadas) | |
34 | - sinonimos_aplicados = self.aplic_sinonimos.aplicar_sinonimos(regras_aplicadas) | |
44 | + sentenca_corrigida = self.aplic_regras.simplificar_sentenca(regras_aplicadas) | |
45 | + sinonimos_aplicados = self.aplic_sinonimos.aplicar_sinonimos(sentenca_corrigida) | |
35 | 46 | self.glosa = sinonimos_aplicados.encode('utf-8') |
36 | 47 | |
37 | 48 | def obter_glosa(self): |
38 | - return self.glosa | |
39 | 49 | \ No newline at end of file |
50 | + return self.glosa | |
51 | + | |
52 | + def salvar_log(self, erro): | |
53 | + logging.error(erro) | |
40 | 54 | \ No newline at end of file | ... | ... |
src/new/alexp.py
... | ... | @@ -29,6 +29,7 @@ |
29 | 29 | """ |
30 | 30 | import re,nltk,platform, time, random |
31 | 31 | from os.path import expanduser |
32 | +from os import environ | |
32 | 33 | from Aelius.Extras import carrega |
33 | 34 | from Aelius import AnotaCorpus |
34 | 35 | from unicodedata import normalize |
... | ... | @@ -51,11 +52,10 @@ def etiquetaSentenca(s): |
51 | 52 | """ |
52 | 53 | etiquetador = carrega("AeliusHunPos") |
53 | 54 | anotada = AnotaCorpus.anota_sentencas([s],etiquetador,"hunpos")[0] |
54 | - while (len(anotada) is 0): | |
55 | + while (anotada[0][1] is None): | |
55 | 56 | time.sleep(random.choice(sleep_times)) |
56 | 57 | anotada = AnotaCorpus.anota_sentencas([s],etiquetador,"hunpos")[0] |
57 | - anotada[0] = (anotada[0][0].lower(), anotada[0][1]) | |
58 | - return anotada | |
58 | + return [[x[0].upper(), x[1]] for x in anotada] | |
59 | 59 | |
60 | 60 | def geraEntradasLexicais(lista): |
61 | 61 | """Gera entradas lexicais no formato CFG do NLTK a partir de lista de pares constituídos de tokens e suas etiquetas. |
... | ... | @@ -83,7 +83,7 @@ def encontraArquivo(): |
83 | 83 | """ |
84 | 84 | so = platform.system() |
85 | 85 | if so == 'Windows': |
86 | - return expanduser("~") + "\vlibras-translate\data\cfg.syn.nltk" | |
86 | + return os.environ.get("HOMEDRIVE") + "\\vlibras-libs\vlibras-translate\data\cfg.syn.nltk" | |
87 | 87 | else: |
88 | 88 | return expanduser("~") + "/vlibras-translate/data/cfg.syn.nltk" |
89 | 89 | ... | ... |