Commit 6022aeba9a7a1063c5cbe7e9d92c083ca5ee22d2
1 parent
2caa83ac
Exists in
master
and in
1 other branch
Melhora acesso ao Leitor de Dicionarios e adiciona os metodos para novos dicionarios
Showing
1 changed file
with
126 additions
and
107 deletions
Show diff stats
src/new/LerDicionarios.py
... | ... | @@ -7,140 +7,159 @@ |
7 | 7 | #LAViD - Laboratório de Aplicações de Vídeo Digital |
8 | 8 | |
9 | 9 | from os.path import expanduser |
10 | -import csv, platform | |
11 | - | |
12 | -class LeitorDicionarios(object): | |
13 | - #_iInstance = None | |
14 | - | |
15 | - #class Singleton: | |
16 | - # def __init__(self): | |
17 | - # self.LeitorDicionarios = None | |
18 | - | |
19 | - #def __init__( self ): | |
20 | - # if LeitorDicionarios._iInstance is None: | |
21 | - # LeitorDicionarios._iInstance = LeitorDicionarios.Singleton() | |
22 | - | |
23 | - # self._EventHandler_instance = LeitorDicionarios._iInstance | |
24 | - | |
25 | - #def __getattr__(self, aAttr): | |
26 | - # return getattr(self._iInstance, aAttr) | |
27 | - | |
28 | - #def __setattr__(self, aAttr, aValue): | |
29 | - # return setattr(self._iInstance, aAttr, aValue) | |
30 | - | |
31 | - # Define e inicializa os atributos | |
32 | - def __init__(self): | |
10 | +import csv | |
11 | +import platform | |
12 | + | |
13 | +class LerDicionarios(object): | |
33 | 14 | |
34 | - so = platform.system() | |
35 | - if so == 'Windows': | |
36 | - self.__path = expanduser("~") + "\\vlibras-translate\data\\" | |
37 | - else: | |
38 | - self.__path = expanduser("~") + "/vlibras-translate/data/" | |
39 | - | |
40 | - self.__dicInf = {} | |
41 | - self.__dicSin = {} | |
42 | - self.__dicWords = {} | |
43 | - self.__dic2Gen = {} | |
44 | - self.__dicTemVerbs = {} | |
45 | - self.__fileDic = '' | |
46 | - self.carregarVerbosInfinitivos() | |
47 | - self.carregarSinonimos() | |
48 | - self.carregarPalavrasIgnoradas() | |
49 | - self.carregarSubst2Generos() | |
50 | - self.carregarTemposVerbais() | |
51 | - | |
52 | - # Abre o self.__fileDic que contem os verbos no infinitivo e preenche o dicionario com os mesmos | |
53 | - def carregarVerbosInfinitivos(self): | |
15 | + def __init__(self): | |
16 | + self.path = self.get_path() | |
17 | + self.dic_adv_intensidade = [] | |
18 | + self.dic_adv_tempo = [] | |
19 | + self.dic_art = [] | |
20 | + self.dic_prep = [] | |
21 | + self.dic_sin = {} | |
22 | + self.dic_sb_2_gen = [] | |
23 | + self.dic_vb_infinitivo = {} | |
24 | + self.dic_vb_ligacao = [] | |
25 | + self.file = '' | |
26 | + self.carregar_dicionarios() | |
27 | + | |
28 | + def get_path(self): | |
29 | + if platform.system() == 'Windows': | |
30 | + return expanduser("~") + "\\vlibras-translate\data\\" | |
31 | + return expanduser("~") + "/vlibras-translate/data/" | |
32 | + | |
33 | + def carregar_dicionarios(self): | |
34 | + self.carregar_adverbios_intensidade() | |
35 | + self.carregar_adverbios_tempo() | |
36 | + self.carregar_artigos() | |
37 | + self.carregar_preposicoes() | |
38 | + self.carregar_sinonimos() | |
39 | + self.carregar_subs_2_generos() | |
40 | + self.carregar_verbos_infinitivo() | |
41 | + self.carregar_verbos_ligacao() | |
42 | + | |
43 | + def carregar_adverbios_intensidade(self): | |
54 | 44 | try: |
55 | - self.__fileDic = csv.reader(open(self.__path+"dicPortGlosa.csv"), delimiter=";") | |
56 | - except IOError, (errno, strerror): | |
45 | + self.file = csv.reader(open(self.path+"adverbiosIntensidade.csv")) | |
46 | + except IOError, (errno, strerror): | |
57 | 47 | print "I/O error(%s): %s" % (errno, strerror) |
58 | - print "carregarVerbosInfinitivos" | |
48 | + print "carregar_adverbios_intensidade" | |
49 | + | |
50 | + rows = [] | |
51 | + for row in self.file: | |
52 | + rows.append(row[0].decode("utf-8")) | |
53 | + self.dic_adv_intensidade = set(rows) | |
59 | 54 | |
60 | - for row in self.__fileDic: | |
61 | - if row[1] != "": | |
62 | - try: | |
63 | - self.__dicInf[row[0].decode("utf-8")] = row[1].decode("utf-8") | |
64 | - except UnicodeDecodeError: | |
65 | - self.__dicInf[row[0].decode('iso8859-1').encode('utf-8')] = row[1].decode('iso8859-1').encode('utf-8') | |
55 | + def carregar_adverbios_tempo(self): | |
56 | + try: | |
57 | + self.file = csv.reader(open(self.path+"adverbiosTempo.csv")) | |
58 | + except IOError, (errno, strerror): | |
59 | + print "I/O error(%s): %s" % (errno, strerror) | |
60 | + print "carregar_adverbios_tempo" | |
66 | 61 | |
67 | - # Abre o self.__fileDic que contem os sinonimos e preenche o dicionario com os mesmos | |
68 | - def carregarSinonimos(self): | |
62 | + rows = [] | |
63 | + for row in self.file: | |
64 | + rows.append(row[0].decode("utf-8")) | |
65 | + self.dic_adv_tempo = set(rows) | |
66 | + | |
67 | + def carregar_artigos(self): | |
69 | 68 | try: |
70 | - self.__fileDic = csv.reader(open(self.__path+"portuguesGlosa.csv"), delimiter=";") | |
69 | + self.file = csv.reader(open(self.path+"artigos.csv")) | |
71 | 70 | except IOError, (errno, strerror): |
72 | 71 | print "I/O error(%s): %s" % (errno, strerror) |
73 | - print "carregarSinonimos" | |
74 | - | |
75 | - for row in self.__fileDic: | |
76 | - if row[1] != "": | |
77 | - self.__dicSin[row[0].decode("utf-8")] = row[1].decode("utf-8") | |
78 | - | |
72 | + print "carregar_artigos" | |
73 | + | |
74 | + rows = [] | |
75 | + for row in self.file: | |
76 | + rows.append(row[0].decode("utf-8")) | |
77 | + self.dic_art = set(rows) | |
79 | 78 | |
80 | - # Abre o self.__fileDic que contem os tempos verbais | |
81 | - def carregarTemposVerbais(self): | |
79 | + def carregar_preposicoes(self): | |
82 | 80 | try: |
83 | - self.__fileDic = csv.reader(open(self.__path+"temposVerbais.csv"), delimiter=";") | |
81 | + self.file = csv.reader(open(self.path+"preposicoes.csv")) | |
84 | 82 | except IOError, (errno, strerror): |
85 | 83 | print "I/O error(%s): %s" % (errno, strerror) |
86 | - print "carregarTemposVerbais" | |
87 | - | |
88 | - for row in self.__fileDic: | |
89 | - self.__dicTemVerbs[row[0].decode("utf-8")] = row[0].decode("utf-8") | |
84 | + print "carregar_preposicoes" | |
85 | + | |
86 | + rows = [] | |
87 | + for row in self.file: | |
88 | + rows.append(row[0].decode("utf-8")) | |
89 | + self.dic_prep = set(rows) | |
90 | 90 | |
91 | - # Abre o self.__fileDic que contem os artigos e preposicoes de acordo com o modelo de idioma passado na chamada e preenche o dicionario com os mesmos | |
92 | - def carregarPalavrasIgnoradas(self): | |
91 | + def carregar_sinonimos(self): | |
93 | 92 | try: |
94 | - self.__fileDic = csv.reader(open(self.__path+"hWordsRemove.csv"), delimiter=";") | |
93 | + self.file = csv.reader(open(self.path+"sinonimos.csv"), delimiter=";") | |
95 | 94 | except IOError, (errno, strerror): |
96 | 95 | print "I/O error(%s): %s" % (errno, strerror) |
97 | - print "carregarPalavrasIgnoradas" | |
96 | + print "carregar_sinonimos" | |
97 | + | |
98 | + for row in self.file: | |
99 | + if row[1] != "": | |
100 | + self.dic_sin[row[0].decode("utf-8")] = row[1].decode("utf-8") | |
98 | 101 | |
99 | - for row in self.__fileDic: | |
100 | - self.__dicWords[row[0].decode("utf-8")] = row[0].decode("utf-8") | |
101 | - | |
102 | - # Abre o self.__fileDic que contem os substantivos que sao comuns dos 2 generos e preenche o dicionario com os mesmos | |
103 | - def carregarSubst2Generos(self): | |
102 | + def carregar_subs_2_generos(self): | |
104 | 103 | try: |
105 | - self.__fileDic = csv.reader(open(self.__path+"subs2Generos.csv"), delimiter=";") | |
104 | + self.file = csv.reader(open(self.path+"subs2Generos.csv")) | |
106 | 105 | except IOError, (errno, strerror): |
107 | 106 | print "I/O error(%s): %s" % (errno, strerror) |
108 | - print "carregarSubst2Generos" | |
109 | - | |
110 | - for row in self.__fileDic: | |
111 | - self.__dic2Gen[row[0].decode("utf-8")] = row[0].decode("utf-8") | |
107 | + print "carregar_subs_2_generos" | |
108 | + | |
109 | + rows = [] | |
110 | + for row in self.file: | |
111 | + rows.append(row[0].decode("utf-8")) | |
112 | + self.dic_sb_2_gen = set(rows) | |
113 | + | |
114 | + def carregar_verbos_infinitivo(self): | |
115 | + try: | |
116 | + self.file = csv.reader(open(self.path+"verbosInfinitivo.csv"), delimiter=";") | |
117 | + except IOError, (errno, strerror): | |
118 | + print "I/O error(%s): %s" % (errno, strerror) | |
119 | + print "carregar_verbos_infinitivo" | |
120 | + | |
121 | + for row in self.file: | |
122 | + if row[1] != "": | |
123 | + self.dic_vb_infinitivo[row[0].decode("utf-8")] = row[1].decode("utf-8") | |
112 | 124 | |
113 | - # Retorna o dicionario dos verbos no infinitivo | |
114 | - def getVerboInfinitivo(self, token): | |
115 | - return self.__dicInf[token] | |
125 | + def carregar_verbos_ligacao(self): | |
126 | + try: | |
127 | + self.file = csv.reader(open(self.path+" verbosLigacao.csv")) | |
128 | + except IOError, (errno, strerror): | |
129 | + print "I/O error(%s): %s" % (errno, strerror) | |
130 | + print "carregar_verbos_ligacao" | |
131 | + | |
132 | + rows = [] | |
133 | + for row in self.file: | |
134 | + rows.append(row[0].decode("utf-8")) | |
135 | + self.dic_vb_ligacao = set(rows) | |
116 | 136 | |
117 | - # Retorna o dicionario dos sinonimos | |
118 | - def getSinonimo(self, token): | |
119 | - return self.__dicSin[token] | |
137 | + def has_adverbio_intensidade(self, token): | |
138 | + return token in self.dic_adv_intensidade | |
120 | 139 | |
121 | - # Retorna o dicionario dos artigos e preposicoes a serem removidos pelo simplificador | |
122 | - def getPalavraIgnorada(self, token): | |
123 | - return self.__dicWords[token] | |
140 | + def has_adverbio_tempo(self, token): | |
141 | + return token in self.dic_adv_tempo | |
124 | 142 | |
125 | - # Retorna o dicionario dos substantivos a serem analisados pelo simplificador | |
126 | - def getSubst2Generos(self, token): | |
127 | - return self.__dic2Gen[token] | |
143 | + def has_artigo(self, token): | |
144 | + return token in self.dic_art | |
128 | 145 | |
129 | - # Retorna o dicionario dos tempos verbais | |
130 | - def getTempoVerbal(self, token): | |
131 | - return self.__dicTemVerbs[token] | |
146 | + def has_preposicao(self, token): | |
147 | + return token in self.dic_prep | |
148 | + | |
149 | + def has_sinonimo(self, token): | |
150 | + return self.dic_sin.has_key(token) | |
132 | 151 | |
133 | - def hasVerboInfinitivo(self, token): | |
134 | - return self.__dicInf.has_key(token) | |
152 | + def has_subst_2_generos (self, token): | |
153 | + return token in self.dic_sb_2_gen | |
135 | 154 | |
136 | - def hasSinonimo(self, token): | |
137 | - return self.__dicSin.has_key(token) | |
155 | + def has_verbo_infinitivo(self, token): | |
156 | + return self.dic_vb_infinitivo.has_key(token) | |
138 | 157 | |
139 | - def hasPalavraIgnorada(self, token): | |
140 | - return self.__dicWords.has_key(token) | |
158 | + def has_verbo_ligacao(self, token): | |
159 | + return token in self.dic_vb_ligacao | |
141 | 160 | |
142 | - def hasSubst2Genero(self, token): | |
143 | - return self.__dic2Gen.has_key(token) | |
161 | + def get_sinonimo(self, token): | |
162 | + return self.dic_sin[token] | |
144 | 163 | |
145 | - def hasTempoVerbal(self, token): | |
146 | - return self.__dicTemVerbs.has_key(token) | |
164 | + def get_verbo_infinitivo(self, token): | |
165 | + return self.dic_vb_infinitivo[token] | |
147 | 166 | \ No newline at end of file | ... | ... |