Commit 4c653c2e87ba5fb2735ccbbf04d78a4d56c60dd1
1 parent
647ef3f2
Exists in
devel
Corrige tratamento de palavras compostas
Showing
1 changed file
with
7 additions
and
3 deletions
Show diff stats
src/AplicaSinonimos.py
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | #LAViD - Laboratório de Aplicações de Vídeo Digital |
8 | 8 | |
9 | 9 | import os |
10 | +import re | |
10 | 11 | import csv |
11 | 12 | import sys |
12 | 13 | from nltk.tree import Tree |
... | ... | @@ -58,12 +59,15 @@ class AplicaSinonimos(object): |
58 | 59 | sentenca_corrigida = "_".join(lista).upper() |
59 | 60 | except: |
60 | 61 | sentenca_corrigida = "_".join([str(x[0]) for x in lista]).upper() |
61 | - | |
62 | 62 | for p in palavras_compostas: |
63 | - if p in sentenca_corrigida: | |
64 | - sentenca_corrigida = sentenca_corrigida.replace(p, p.replace("_", "#*#")) | |
63 | + for m in re.finditer(p, sentenca_corrigida): | |
64 | + first = "_" if m.start() == 0 else sentenca_corrigida[m.start()-1] | |
65 | + last = "_" if m.end() == len(sentenca_corrigida)-1 else sentenca_corrigida[m.end()] | |
66 | + if first == "_" and last == "_": | |
67 | + sentenca_corrigida = sentenca_corrigida.replace(p, p.replace("_", "#*#")) | |
65 | 68 | return sentenca_corrigida.replace("_", " ").replace("#*#", "_") |
66 | 69 | |
70 | + | |
67 | 71 | def carregar_palavras_compostas(self): |
68 | 72 | path = self.localizar_arquivo_palavras_compostas() |
69 | 73 | return set(open(path).read().decode('utf-8').split()) | ... | ... |