Datasets:

Modalities:
Tabular
Text
Formats:
parquet
Languages:
Portuguese
Tags:
legal
DOI:
Libraries:
Datasets
Dask
License:
vic35get commited on
Commit
27802a6
·
verified ·
1 Parent(s): b60fb97

Upload cleaner.py

Browse files
Files changed (1) hide show
  1. cleaner.py +595 -0
cleaner.py ADDED
@@ -0,0 +1,595 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from copy import deepcopy
2
+ import re
3
+ from unidecode import unidecode
4
+ from pandarallel import pandarallel
5
+ import pandas as pd
6
+
7
+
8
+ class Cleaner:
9
+
10
+ def clear(self, paragraphs):
11
+ if not paragraphs:
12
+ return paragraphs
13
+ texts = deepcopy(paragraphs)
14
+
15
+ texts = self._removeParenteses(texts)
16
+ texts = self._remove_undesired_chars(texts)
17
+ texts = self._remove_barraNInvertido(texts)
18
+ texts = self._remove_multiplos_hifens(texts)
19
+ texts = self._remove_multiples_dots(texts)
20
+ texts = self._remove_multiples_x(texts)
21
+ texts = self._corrigeNumPalavra(texts)
22
+ texts = self._corrigePalavraNum(texts)
23
+ texts = self._d_ataToData(texts)
24
+ texts = self._removeAnigap(texts)
25
+ texts = self._removeNumSecoesInicio(texts)
26
+ texts = self._removeNumSecoesInicio(texts)
27
+ texts = self._removeNumSecoes(texts)
28
+ texts = self._removeNumSecoes(texts)
29
+ texts = self._remove_alternativas(texts)
30
+ return texts
31
+
32
+ @staticmethod
33
+ def _removeParenteses(paragraphs):
34
+ """
35
+ Remove padrões do tipo (conteudo).
36
+ """
37
+ return re.sub(r'\(([^()]+)\)', ' ', paragraphs)
38
+
39
+ @staticmethod
40
+ def _remove_undesired_chars(paragraphs):
41
+ """
42
+ Remove caracteres indesejados.
43
+ """
44
+ return re.sub(r'([”“\\\\•●▪•_·□»«#£¢¿&!;*{}^~´`=|[\]²¹\+¨\t\'\"\)\(]|(0xx))', ' ', paragraphs)
45
+
46
+ @staticmethod
47
+ def _remove_barraNInvertido(paragraphs):
48
+ """
49
+ Remove /n invertido.
50
+ """
51
+ return re.sub(r'((\/n(\s))|(\/n$))', ' ', paragraphs)
52
+
53
+ @staticmethod
54
+ def _remove_multiplos_hifens(paragraphs):
55
+ """
56
+ Remove multiplos hifens.
57
+ O espaço antes e depois do token é por conta do padrão que retira os espaços antes e depois do texto.
58
+ """
59
+ paragraphs = re.sub(r'((\s)-)+', ' - ', paragraphs)
60
+ return re.sub(r'[-–]+', '-', paragraphs)
61
+
62
+ @staticmethod
63
+ def _remove_multiples_dots(paragraphs):
64
+ """
65
+ Remove multiplos pontos.
66
+ """
67
+ paragraphs = re.sub(r'\.+', '.', paragraphs)
68
+ return re.sub(r'^\.\s', '', paragraphs)
69
+
70
+ @staticmethod
71
+ def _remove_multiples_x(paragraphs):
72
+ """
73
+ Reduz multiplos x para apenas um x.
74
+ """
75
+ return re.sub(r'(([xX]){2,})', 'x', paragraphs)
76
+
77
+ @staticmethod
78
+ def _corrigeNumPalavra(paragraphs):
79
+ """
80
+ Corrige sentenças do tipo 1palavra para 1 palavra.
81
+ """
82
+ return re.sub(r'((\d+)([a-zA-Z]{2,}))', r'\2 \3', paragraphs)
83
+
84
+ @staticmethod
85
+ def _corrigePalavraNum(paragraphs):
86
+ """
87
+ Corrige sentenças do tipo palavra1 para palavra 1.
88
+ """
89
+ return re.sub(r'(([a-zA-Z]{2,})(\d+))', r'\2 \3', paragraphs)
90
+
91
+ @staticmethod
92
+ def _d_ataToData(paragraphs):
93
+ """
94
+ Corrige d ata para data.
95
+ """
96
+ return re.sub(r'(([Dd] ata)|(D ATA))', 'data', paragraphs)
97
+
98
+ @staticmethod
99
+ def _removeAnigap(paragraphs):
100
+ """
101
+ Remove padrões do tipo a n i g á p.
102
+ """
103
+ return re.sub(r'(([aA] [Nn] [Ii] [Gg] [Áá] [Pp])|([aA] [Nn] [Ii] [Gg] [Áá]))', '', paragraphs)
104
+
105
+ @staticmethod
106
+ def _removeNumSecoesInicio(paragraphs):
107
+ """
108
+ Remove padrões de numeros de secao no início.
109
+ """
110
+ return re.sub(r'(^((\s)*(((\d{1,2}\.)(\d{1,2}(\.)?)*)|(\d)+)(\s)?[\-–]?))', ' ', paragraphs)
111
+
112
+ @staticmethod
113
+ def _removeNumSecoes(paragraphs):
114
+ """
115
+ Remove padrões de numeros de secao.
116
+ """
117
+ return re.sub(r'(\d{1,2}\.){1,}(\d{1,2}\s[\-–])?', ' ', paragraphs)
118
+
119
+ @staticmethod
120
+ def _remove_alternativas(paragraphs):
121
+ """
122
+ Remove alternativas de questões.
123
+ """
124
+ return re.sub(r'(^[bcdfghijklmnpqrstuvwxyz\:\/\,\.\;@-]([\.)-])?(\s)|(^[aeo][\.)-](\s)))', '', paragraphs, flags=re.IGNORECASE)
125
+
126
+
127
+ class Corretor:
128
+ def __init__(self, cased: bool, accents: bool) -> None:
129
+ self.accents = accents
130
+ self.cased = cased
131
+
132
+ def corrige_termos(self, paragraphs):
133
+ if not paragraphs:
134
+ return paragraphs
135
+ texts = deepcopy(paragraphs)
136
+
137
+ texts = self._padraoEmail(texts)
138
+ texts = self._corrigeCapitulo(texts)
139
+ texts = self._telToTelefone(texts)
140
+ texts = self._NtoNumero(texts)
141
+ texts = self._artToArtigo(texts)
142
+ texts = self._ccToCumulativamenteCom(texts)
143
+ texts = self._remove_SbarraN(texts)
144
+ texts = self._c_ontratacaoToContratacao(texts)
145
+ texts = self._memoToMemorando(texts)
146
+ texts = self._corrigeParagrafo(texts)
147
+ texts = self._corrigeLicitacao(texts)
148
+ texts = self._corrigeContratacao(texts)
149
+ texts = self._corrigePregao(texts)
150
+ texts = self._corrigeFiscal(texts)
151
+ texts = self._corrigeObjeto(texts)
152
+ texts = self._corrigeValor(texts)
153
+ texts = self._corrigeCertidao(texts)
154
+ texts = self._corrigeEmpenho(texts)
155
+ texts = self._corrigeQuantidade(texts)
156
+ texts = self._corrigeAditivo(texts)
157
+ texts = self._corrigeSancao(texts)
158
+ texts = self._corrigeEdital(texts)
159
+ texts = self._corrigeGarantia(texts)
160
+ texts = self._corrigeOnus(texts)
161
+ texts = self._corrigeReajuste(texts)
162
+ texts = self._corrigeDigital(texts)
163
+ texts = self._incToInciso(texts)
164
+ texts = self._padronizaCNPJ(texts)
165
+ texts = self._padronizaSiglas(texts)
166
+ texts = self._tokenizaURL(texts)
167
+ texts = self._tokenizaEmail(texts)
168
+ texts = self._tokenizaData(texts)
169
+ texts = self._tokenizaHora(texts)
170
+ texts = self._tokenizaNumero(texts)
171
+ texts = self._tokenizaNumeroRomano(texts)
172
+ texts = self._reduzNumeros(texts)
173
+ texts = self._removeHifenInicial(texts)
174
+ texts = self._corrigePontuacao(texts)
175
+ texts = self._remove_characters_inicial(texts)
176
+ texts = self._remove_characters_final(texts)
177
+ texts = self._remove_multiples_spaces(texts)
178
+ texts = self._remove_space_in_last_period(texts)
179
+ texts = self._strip_spaces(texts)
180
+
181
+ if not self.accents:
182
+ texts = self._removeAcentos(texts)
183
+
184
+ if not self.cased:
185
+ texts = self._toLowerCase(texts)
186
+
187
+ return texts
188
+
189
+ @staticmethod
190
+ def _padraoEmail(paragraphs):
191
+ """
192
+ Padroniza a palavra email.
193
+ """
194
+ return re.sub(r'(([eE][\-–]?mail([.:])*)|(E[\-–]?MAIL([.:])*))', 'email', paragraphs)
195
+
196
+ @staticmethod
197
+ def _corrigeCapitulo(paragraphs):
198
+ """
199
+ Corrige c apitulo para capitulo.
200
+ """
201
+ return re.sub(r'(c(\s)ap[ií]tulo)', 'capítulo', paragraphs, flags=re.IGNORECASE)
202
+
203
+ @staticmethod
204
+ def _telToTelefone(paragraphs):
205
+ """
206
+ Corrige tel para telefone.
207
+ """
208
+ return re.sub(r'(\b(tel)\b)', 'telefone', paragraphs, flags=re.IGNORECASE)
209
+
210
+ @staticmethod
211
+ def _NtoNumero(paragraphs):
212
+ """
213
+ Convert nº para numero.
214
+ """
215
+ paragraphs = re.sub(r'((\s)((([nN][º°])|(n[uú]mero)\.)|((([nN])|(([Nn][uÚ]mero)|(N[UÚ]MERO)))\.[º°])|([nN][º°])|([nN]\.)|([Nn][rR]))(\s)?)', ' número ', paragraphs)
216
+ return re.sub(r'([º°])', ' ', paragraphs)
217
+
218
+ @staticmethod
219
+ def _artToArtigo(paragraphs):
220
+ """
221
+ Corrige art. para artigo.
222
+ """
223
+ return re.sub(r'(\b([Aa]rt\.)|(ART\.)|(([Aa]rt)|(ART))\b)', 'artigo', paragraphs)
224
+
225
+ @staticmethod
226
+ def _ccToCumulativamenteCom(paragraphs):
227
+ """
228
+ Corrige c/c para cumulativamente com.
229
+ """
230
+ return re.sub(r'(\b[cC]\/[cC]\b)', 'cumulativamente com', paragraphs)
231
+
232
+ @staticmethod
233
+ def _remove_SbarraN(paragraphs):
234
+ """
235
+ Corrige padrões do tipo s/n para sem numero.
236
+ """
237
+ return re.sub(r'(((\b([sS]\/(([nN]º)|([nN]))[,.]?))|([sS]\/(([nN]º)|([nN]))[,.]))(\s|\,|\.|\:|\;))', 'sem número ', paragraphs)
238
+
239
+ @staticmethod
240
+ def _c_ontratacaoToContratacao(paragraphs):
241
+ """
242
+ Corrige c ontratação para contratação.
243
+ """
244
+ return re.sub(r'(\b([cC] ontrata[cç][aã]o)|(C ONTRATA[CÇ][AÃ]O)\b)', 'contratação', paragraphs)
245
+
246
+ @staticmethod
247
+ def _memoToMemorando(paragraphs):
248
+ """
249
+ Corrige memo para memorando.
250
+ O espaço antes e depois do token é por conta do padrão que retira os espaços antes e depois do texto.
251
+ """
252
+ return re.sub(r'(\b(([mM]emo)|(MEMO))\b)', 'memorando', paragraphs)
253
+
254
+ @staticmethod
255
+ def _corrigeParagrafo(paragraphs):
256
+ """
257
+ Corrige formas de parágrafo para parágrafo.
258
+ O espaço antes e depois do token é por conta do padrão que retira os espaços antes e depois do texto.
259
+ """
260
+ paragraphs = re.sub(r'((\s|\.|\,|\;|\:|^)(§{2,})º?(\s|\.|\,|\;|\:|$))', ' parágrafos ', paragraphs)
261
+ return re.sub(r'((\s|\.|\,|\;|\:|^)(§)º?(\s|\.|\,|\;|\:|$))', ' parágrafo ', paragraphs)
262
+
263
+ @staticmethod
264
+ def _corrigeLicitacao(paragraphs):
265
+ """
266
+ Corrige ocorrências da palavra ou Licitaçã o" para "licitação".
267
+ Corrige ocorrências da palavra ou "Licitaçã" para "licitação".
268
+ """
269
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:)(iicitante)(\s|\.|\,|\;|\:)', ' licitante ', paragraphs, flags=re.IGNORECASE)
270
+ paragraphs = re.sub(r'((\s|\.|\,|\;|\:)(licita[çc][aã](\s)o)(\s|\.|\,|\;|\:))', ' licitação ', paragraphs, flags=re.IGNORECASE)
271
+ return re.sub(r'((\s|\.|\,|\;|\:)(licita[çc][aã])(\s|\.|\,|\;|\:))', ' licitação ', paragraphs, flags=re.IGNORECASE)
272
+
273
+ @staticmethod
274
+ def _corrigeContratacao(paragraphs):
275
+ """
276
+ Corrige ocorrências da palavra Contrataçã o" para "contratação".
277
+ Corrige ocorrências da palavra "Contrataçã" para "contratação".
278
+ """
279
+ paragraphs = re.sub(r'((\s|\.|\,|\;|\:)(contrata[çc][aã](\s)o)(\s|\.|\,|\;|\:))', ' contratação ', paragraphs, flags=re.IGNORECASE)
280
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:)(contrante)(\s|\.|\,|\;|\:)', ' contratante ', paragraphs, flags=re.IGNORECASE)
281
+ return re.sub(r'((\s|\.|\,|\;|\:)(contrata[çc][aã])(\s|\.|\,|\;|\:))', ' contratação ', paragraphs, flags=re.IGNORECASE)
282
+
283
+ @staticmethod
284
+ def _corrigePregao(paragraphs):
285
+ """
286
+ Corrige ocorrências da palavra "P REGÃO" para "pregão".
287
+ Corrige ocorrências da palavra "regão" para "pregão".
288
+ """
289
+ paragraphs = re.sub(r'((\s|\.|\,|\;|\:)(p(\s)reg[ãa]o)(\s|\.|\,|\;|\:))', ' pregão ', paragraphs, flags=re.IGNORECASE)
290
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:)(pregoelro)(\s|\.|\,|\;|\:)', ' pregoeiro ', paragraphs, flags=re.IGNORECASE)
291
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:)(opregoeiro)(\s|\.|\,|\;|\:)', ' o pregoeiro ', paragraphs, flags=re.IGNORECASE)
292
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:)(apregoeira)(\s|\.|\,|\;|\:)', ' a pregoeira ', paragraphs, flags=re.IGNORECASE)
293
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:)(pelopregoeiro)(\s|\.|\,|\;|\:)', ' pelo pregoeiro ', paragraphs, flags=re.IGNORECASE)
294
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:)(pelapregoeira)(\s|\.|\,|\;|\:)', ' pela pregoeira ', paragraphs, flags=re.IGNORECASE)
295
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:)(pregoeir a)(\s|\.|\,|\;|\:)', ' pregoeira ', paragraphs, flags=re.IGNORECASE)
296
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:)(pregoeir o)(\s|\.|\,|\;|\:)', ' pregoeiro ', paragraphs, flags=re.IGNORECASE)
297
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:)(pregoeir)(\s|\.|\,|\;|\:)', ' pregoeiro ', paragraphs, flags=re.IGNORECASE)
298
+ paragraphs = re.sub(r'((\s|\.|\,|\;|\:)(reg[ãa]o)(\s|\.|\,|\;|\:))', ' pregão ', paragraphs, flags=re.IGNORECASE)
299
+ paragraphs = re.sub(r'((\s|\.|\,|\;|\:)((preg)(\s)(pregoeira)|(pregoeira(\s)preg))(\s|\.|\,|\;|\:))', ' pregoeira ', paragraphs, flags=re.IGNORECASE)
300
+ paragraphs = re.sub(r'((\s|\.|\,|\;|\:)((preg)(\s)(pregoeiro)|(pregoeiro(\s)preg))(\s|\.|\,|\;|\:))', ' pregoeiro ', paragraphs, flags=re.IGNORECASE)
301
+ paragraphs = re.sub(r'((\s|\.|\,|\;|\:)(preg(\s)[aã]o)(\s|\.|\,|\;|\:))', ' pregão ', paragraphs, flags=re.IGNORECASE)
302
+ return re.sub(r'((\s|\.|\,|\;|\:)(preg)(\s|\.|\,|\;|\:))', ' pregão ', paragraphs, flags=re.IGNORECASE)
303
+
304
+ @staticmethod
305
+ def _corrigeFiscal(paragraphs):
306
+ """
307
+ Corrige ocorrências da palavra "F i scal" para "fiscal".
308
+ Corrige ocorrências da palavra "scal" para "fiscal".
309
+ """
310
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:|^)(f(\s)i(\s)scal)(\s|\.|\,|\;|\:)', ' fiscal ', paragraphs, flags=re.IGNORECASE)
311
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(scal)(\s|\.|\,|\;|\:)', ' fiscal ', paragraphs, flags=re.IGNORECASE)
312
+
313
+ @staticmethod
314
+ def _corrigeObjeto(paragraphs):
315
+ """
316
+ Corrige ocorrências da palavra "O bjeto" para "objeto".
317
+ Corrige ocorrências da palavra "bjeto" para "objeto".
318
+ """
319
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:|^)(o?bjeto(\s)(o(\s))?bjeto)(\s|\.|\,|\;|\:)', ' objeto ', paragraphs, flags=re.IGNORECASE)
320
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:|^)(abjeto)(\s|\.|\,|\;|\:)', ' objeto ', paragraphs, flags=re.IGNORECASE)
321
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(bjeto)(\s|\.|\,|\;|\:)', ' objeto ', paragraphs, flags=re.IGNORECASE)
322
+
323
+ @staticmethod
324
+ def _corrigeValor(paragraphs):
325
+ """
326
+ Corrige ocorrências da palavra "valo r" para "valor".
327
+ Corrige ocorrências da palavra "valo" para "valor".
328
+ """
329
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:|^)(valo(\s)r)(\s|\.|\,|\;|\:)', ' valor ', paragraphs, flags=re.IGNORECASE)
330
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(valo)(\s|\.|\,|\;|\:)', ' valor ', paragraphs, flags=re.IGNORECASE)
331
+
332
+ @staticmethod
333
+ def _corrigeCertidao(paragraphs):
334
+ """
335
+ Corrige ocorrências da palavra "cer dão" para "certidão".
336
+ """
337
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(cer(\s)d[ãa]o)(\s|\.|\,|\;|\:)', ' certidão ', paragraphs, flags=re.IGNORECASE)
338
+
339
+ @staticmethod
340
+ def _corrigeEmpenho(paragraphs):
341
+ """
342
+ Corrige ocorrências da palavra "emprenho" para "empenho".
343
+ """
344
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(emprenho)(\s|\.|\,|\;|\:)', ' empenho ', paragraphs, flags=re.IGNORECASE)
345
+
346
+ @staticmethod
347
+ def _corrigeQuantidade(paragraphs):
348
+ """
349
+ Corrige ocorrências da palavra "quantidad" para "quantidade".
350
+ """
351
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(quantidad)(\s|\.|\,|\;|\:)', ' quantidade ', paragraphs, flags=re.IGNORECASE)
352
+
353
+ @staticmethod
354
+ def _corrigeAditivo(paragraphs):
355
+ """
356
+ Corrige ocorrências da palavra "adi vo" para "aditivo".
357
+ """
358
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(adi(\s|\.|\,|\;|\:)vo[s]?)(\s|\.|\,|\;|\:)', ' aditivo ', paragraphs, flags=re.IGNORECASE)
359
+
360
+ @staticmethod
361
+ def _corrigeSancao(paragraphs):
362
+ """
363
+ Corrige ocorrências da palavra "sansão" para "sanção".
364
+ Corrige ocorrências da palavra "sansões" para "sanções".
365
+ """
366
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:|^)(sans[ãa]o)(\s|\.|\,|\;|\:)', ' sanção ', paragraphs, flags=re.IGNORECASE)
367
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(sans[oõ]es)(\s|\.|\,|\;|\:)', ' sanções ', paragraphs, flags=re.IGNORECASE)
368
+
369
+ @staticmethod
370
+ def _corrigeEdital(paragraphs):
371
+ """
372
+ Corrige ocorrências da palavra "editai" para "edital".
373
+ """
374
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:|^)(edita(\s)l)(\s|\.|\,|\;|\:)', ' edital ', paragraphs, flags=re.IGNORECASE)
375
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:|^)(editai)(\s|\.|\,|\;|\:)', ' edital ', paragraphs, flags=re.IGNORECASE)
376
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(edita)(\s|\.|\,|\;|\:)', ' edital ', paragraphs, flags=re.IGNORECASE)
377
+
378
+ @staticmethod
379
+ def _corrigeGarantia(paragraphs):
380
+ """
381
+ Corrige ocorrências da palavra "garana" para "garantia".
382
+ """
383
+ paragraphs = re.sub(r'(\s|\.|\,|\;|\:|^)(garanti(\s|\.|\,|\;|\:)a)(\s|\.|\,|\;|\:)', ' garantia ', paragraphs, flags=re.IGNORECASE)
384
+ return re.sub(r'(\s|\.|\,|\;|\:|^)((garana)|(garania))(\s|\.|\,|\;|\:)', ' garantia ', paragraphs, flags=re.IGNORECASE)
385
+
386
+ @staticmethod
387
+ def _corrigeOnus(paragraphs):
388
+ """
389
+ Corrige ocorrências da palavra "anus" para "ônus".
390
+ """
391
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(anus)(\s|\.|\,|\;|\:)', ' ônus ', paragraphs, flags=re.IGNORECASE)
392
+
393
+ @staticmethod
394
+ def _corrigeReajuste(paragraphs):
395
+ """
396
+ Corrige ocorrências da palavra "parareajuste" para "para reajuste".
397
+ """
398
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(parareajuste)(\s|\.|\,|\;|\:)', ' para reajuste ', paragraphs, flags=re.IGNORECASE)
399
+
400
+ @staticmethod
401
+ def _corrigeDigital(paragraphs):
402
+ """
403
+ Corrige ocorrências da palavra "digitai" para "digital".
404
+ """
405
+ return re.sub(r'(\s|\.|\,|\;|\:|^)(digitai)(\s|\.|\,|\;|\:|$)', ' digital ', paragraphs, flags=re.IGNORECASE)
406
+
407
+ @staticmethod
408
+ def _incToInciso(paragraphs):
409
+ """
410
+ Corrige inc. para inciso.
411
+ O espaço antes e depois do token é por conta do padrão que retira os espaços antes e depois do texto.
412
+ """
413
+ return re.sub(r'(\b(inc)\b)', 'inciso', paragraphs, flags=re.IGNORECASE)
414
+
415
+ @staticmethod
416
+ def _padronizaCNPJ(paragraphs):
417
+ """
418
+ Padroniza CNPJ.
419
+ """
420
+ return re.sub(r'(\b(c\.n\.p\.j\.?)\b)', 'cnpj', paragraphs, flags=re.IGNORECASE)
421
+
422
+ @staticmethod
423
+ def _padronizaSiglas(paragraphs):
424
+ """
425
+ Corrige lc para lei complementar.
426
+ O espaço antes e depois do token é por conta do padrão que retira os espaços antes e depois do texto.
427
+ """
428
+ paragraphs = re.sub(r'(\b(cf)\b)', 'Constituição Federal', paragraphs, flags=re.IGNORECASE)
429
+ paragraphs = re.sub(r'(\b(n?cpc)(\/15)?\b)', 'Código de Processo Civil', paragraphs, flags=re.IGNORECASE)
430
+ paragraphs = re.sub(r'(\b(clt)\b)', 'Consolidação das Leis do Trabalho', paragraphs, flags=re.IGNORECASE)
431
+ paragraphs = re.sub(r'(\b(cdc)\b)', 'Código de Defesa do Consumidor', paragraphs, flags=re.IGNORECASE)
432
+ return re.sub(r'(\b(lc)\b)', 'lei complementar', paragraphs, flags=re.IGNORECASE)
433
+
434
+ @staticmethod
435
+ def _tokenizaURL(paragraphs):
436
+ """
437
+ Tokeniza URL.
438
+ """
439
+ return re.sub(r'(((https?:\/\/)(www\.))|(www\.)|(https?:\/\/))[-a-zA-Z0-9@:%.\+~#=]{1,256}\.[a-zA-Z@0-9()]{1,6}\b([-a-zA-Z0-9()@:%\+.~#?&\/=]*)', ' url ', paragraphs)
440
+
441
+ @staticmethod
442
+ def _tokenizaEmail(paragraphs):
443
+ """
444
+ Tokeniza email.
445
+ """
446
+ return re.sub(r'(\b([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})\b)', ' mail ', paragraphs)
447
+
448
+ @staticmethod
449
+ def _tokenizaData(paragraphs):
450
+ """
451
+ Tokeniza data.
452
+ """
453
+ return re.sub(r'(\b([0-3][0-9]\/[0-1][0-9]\/(([0-9]{2})|([0-2][0-9]{3})))\b)', ' date ', paragraphs)
454
+
455
+ @staticmethod
456
+ def _tokenizaHora(paragraphs):
457
+ """
458
+ Tokeniza hora.
459
+ """
460
+ return re.sub(r'(\b(([0-1][0-9])|(2[0-3]))(\:|h)([0-5][0-9])?\b)', ' hour ', paragraphs)
461
+
462
+ @staticmethod
463
+ def _tokenizaNumero(paragraphs):
464
+ """
465
+ Tokeniza número.
466
+ """
467
+ return re.sub(r'([0-9])+', ' number ', paragraphs)
468
+
469
+ @staticmethod
470
+ def _tokenizaNumeroRomano(paragraphs):
471
+ """
472
+ Tokeniza número romano.
473
+ """
474
+ return re.sub(r"(\s|\.|\,|\;|\:|^)(?=[XVIΙ])(XC|XL|L?X{0,3})([IΙ]X|[IΙ]V|V?[IΙ]{0,3})(\s|\.|\,|\;|\:|$)", ' number ', paragraphs, flags=re.IGNORECASE)
475
+
476
+ @staticmethod
477
+ def _reduzNumeros(paragraphs):
478
+ """
479
+ Reduz números.
480
+ """
481
+ return re.sub(r'(([\.\\\/\;\:\s])*(number([\-–\.\\\/\;\:\,\s])*)+)', ' number ', paragraphs)
482
+
483
+ @staticmethod
484
+ def _removeHifenInicial(paragraphs):
485
+ """
486
+ Remove hifen inicial.
487
+ """
488
+ return re.sub(r'^\s*[\-–]\s*', '', paragraphs)
489
+
490
+ @staticmethod
491
+ def _corrigePontuacao(paragraphs):
492
+ """
493
+ Corrige má formatação nas vírgulas (nome , outro nome).
494
+ Corrige má formatação nos pontos (nome . Outro nome).
495
+ Corrige má formatação na pontuação (.,:).
496
+ """
497
+ paragraphs = re.sub(r'((\s)+(\,))', ',', paragraphs)
498
+ paragraphs = re.sub(r'((\s)+(\.))', '.', paragraphs)
499
+ paragraphs = re.sub(r'((\s)+(\:))', ':', paragraphs)
500
+ # Mais de uma pontuação
501
+ paragraphs = re.sub(r'((\,)+)', ',', paragraphs)
502
+ paragraphs = re.sub(r'((\.)+)', '.', paragraphs)
503
+ paragraphs = re.sub(r'((\:)+)', ':', paragraphs)
504
+ return re.sub(r'((\.\,)|(\,\.))', '.', paragraphs)
505
+
506
+ @staticmethod
507
+ def _remove_characters_inicial(paragraphs):
508
+ """
509
+ Remove caracteres finais.
510
+ """
511
+ return re.sub(r'(^((\s)*[ª\%\·\.\:\\\/\,\;@\-–]){1,})', '', paragraphs)
512
+
513
+ @staticmethod
514
+ def _remove_characters_final(paragraphs):
515
+ """
516
+ Remove caracteres finais.
517
+ """
518
+ return re.sub(r'(((\s)*[ª\·\:\\\/\,\;@\-–]){1,}$)', '', paragraphs)
519
+
520
+ @staticmethod
521
+ def _remove_multiples_spaces(paragraphs):
522
+ """
523
+ Remove multiplos espaços nas sentenças.
524
+ """
525
+ return re.sub(r'\s+', ' ', paragraphs)
526
+
527
+ @staticmethod
528
+ def _remove_space_in_last_period(paragraphs):
529
+ """
530
+ Remove espaços finais na sentença e coloca o ponto final.
531
+ """
532
+ return re.sub(r'\s\.$', '.', paragraphs)
533
+
534
+ @staticmethod
535
+ def _strip_spaces(paragraphs):
536
+ """
537
+ Remove espaços antes e depois do texto.
538
+ """
539
+ return paragraphs.strip()
540
+
541
+ @staticmethod
542
+ def _removeAcentos(paragraphs):
543
+ """
544
+ Remove acentos das palavras.
545
+ """
546
+ return unidecode(paragraphs)
547
+
548
+ @staticmethod
549
+ def _toLowerCase(paragraphs):
550
+ """
551
+ Converte o texto para caixa baixa.
552
+ """
553
+ return paragraphs.lower()
554
+
555
+
556
+ class Remover:
557
+ def removeSentences(self, paragraphs):
558
+ if not paragraphs:
559
+ return paragraphs
560
+ texts = deepcopy(paragraphs)
561
+
562
+ texts = self._removeSentencasComCaracteresIndesejados(texts)
563
+ texts = self._removePalavrasQuebradas(texts)
564
+
565
+ return texts
566
+
567
+ @staticmethod
568
+ def _removeSentencasComCaracteresIndesejados(paragraphs):
569
+ """
570
+ Remove sentenças que têm interrogação.
571
+ """
572
+ if re.search(r'([\@\?ʼˢ˫βδθιμξοσφωώасфֹֻ־׀׃ׄ؛؟عُ٭ڊڎڡଋ฀ขงจฉซญฏทนผภวษฬᴏᴓᴼᵌᵒᶟᶲᶾḉṕầẽễ‐‑‒–—―‖‗‘’‚‛„‟†‡‥…‰′″‹›‾⁄⁒⁰⁴⁵⁶⁻⁽⁾ⁿ₀₂₄ₒ€₹⃝⃰℃℉ℎℓ№™⅓⅔⅜⅝ⅱ()+,-:=ェコチノヘᄂ𝐀𝐂𝐋𝐍𝐎𝐏𝐐𝐑𝐒𝐕𝐚𝐜𝐞𝐠𝐢𝐥𝐦𝐧𝐨𝐫𝐬𝐭𝐮𝐯𝐳𝐴𝐵𝐶𝐷𝐸𝐹𝐺𝐻𝐼𝐿𝑀𝑁𝑂𝑃𝑄𝑅𝑆𝑇𝑈𝑉𝑋𝑍𝑎𝑏𝑐𝑑𝑒𝑓𝑔𝑖𝑗𝑘𝑙𝑚𝑛𝑜𝑝𝑞𝑟𝑠𝑡𝑢𝑣𝑥𝑧𝑨𝑩𝑪𝑫𝑭𝑮𝑰𝑲𝑳𝑴𝑵𝑶𝑷𝑸𝑹𝑺𝑽𝒂𝒄𝒅𝒆𝒇𝒈𝒊𝒌𝒍𝒎𝒏𝒐𝒑𝒒𝒓𝒔𝒕𝒖𝒗𝒛🌞←↑→↓↔↩⇁⇒⇛∅∆∑−∕∗∘∙√∝∞∫∬∴≃≅≈≠≤≥≦≺≼⊠⋅⋯⌧〈〉⎓⎛⎜⎝⎞⎟⎠⎡⎢⎣⎤⎯①②③④⑤⑥⑦⑧⑨⑩⓭⓮⓯─│┤═▒■▲▶▷►▼◄◆◊○◐◗◙◦◯◻◼◾☐☒☺♀♠♣♥♦♪♯⚫✇✈✉✐✓✔✗✦✱✲✳✴✵✶✷✹✺✻✼✽✾✿❀❁❂❄❆❇❈❉❊❋❍❏❑❒❖❘❙❚❜❤❥❦❧❯❱❲❳❴❶❷❸❹❺❻❼❽❾❿➀➁➂➃➄➅➋➔➙➛➢➷⦁⩾⮚。〃「」】〔〕〖ꞏꟷ갇갭떷퐀fffiflffifflε¸äåæèëìîï𩅅ñòöøùûüýþÿăęőœŕřšžǧ˝あえがきくさしすつでなぬねふまむめもやゆるれわゑをイセタトブプミムヰン・㊦㌧㌫㌱㍉㍍㘷丁七上且丘乞亀云互五亘亜亡亨京亭什仰仲伍会佃低何使來倉健側儀億允克冊出函切別到則剛副劇加劣助勘勾匂匝匤印卲厄厨句叩叫可台叶吃各合同名吠含呑呼商喜喝喧嗣嘩嘱噌噴回国圄址坤垂埠場士壬壷奮如姫孤宜宣寄富寒対尊尤屯山岨岳嵩嶋川州工左巳巴巾幼庇廿当心急意慧成手押抽担拙持挿捕捻揃描損撃整旧晦暮曲書最朋楓檲櫨歡止正毎毛治注浮灣為焔煎照爪独獄王班璯生田申町畦番疵的皿盃盆直着瞳確磨祖禽秘種竜章競筋簡簿紅純細紺組締縊缶置罵翻耽聞聾肋肌肥肴胞脆脇脚膏臆自至舟舶艇色芯荷萱葦蘭虹蜜蝿融血裏西���言訃訊討証詰誇誓語説読誼調論諾謀謹譜議豆象豹貂負蹄車軋軍軸輩辞迎迫造都醜重量金釦鈍鈎鈬鋏鋤鋳録鍋鐘関閥閲阀階随雀雄雪電震霜露面音韸餌館馘香馨馰馴髄魯鯖鰹鳶鴫鵬鶴ǿ˙ɛɵʃśʺʽ˂ˇ˃ˆː˗˘˛˜\d])', paragraphs, flags=re.IGNORECASE):
573
+ return ''
574
+ else:
575
+ return paragraphs
576
+
577
+ @staticmethod
578
+ def _removePalavrasQuebradas(paragraphs):
579
+ """
580
+ Remove palavras quebradas.
581
+ """
582
+ if re.search(r'([A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ\?\,\.\:\;@\/\<\>]\s){4,}', paragraphs):
583
+ return ''
584
+ else:
585
+ return paragraphs
586
+
587
+
588
+ def executaLimpeza(dataframe: pd.DataFrame, column: str, cased, accents) -> pd.DataFrame:
589
+ """
590
+ Executa a limpeza do DataFrame usando as classes Cleaner e Corretor.
591
+ """
592
+ pandarallel.initialize(progress_bar=True)
593
+ dataframe[column] = dataframe[column].parallel_apply(lambda x: Cleaner().clear(x))
594
+ dataframe[column] = dataframe[column].parallel_apply(lambda x: Corretor(cased, accents).corrige_termos(x))
595
+ return dataframe