Datasets:

Modalities:
Text
Formats:
json
Libraries:
Datasets
pandas
License:
scampion commited on
Commit
40c1311
1 Parent(s): 23f7443
Files changed (2) hide show
  1. README.md +417 -0
  2. update.py +253 -0
README.md CHANGED
@@ -1,3 +1,420 @@
1
  ---
2
  license: eupl-1.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
1
  ---
2
  license: eupl-1.1
3
+ configs:
4
+ - config_name: 2006-04
5
+ data_files: "files/2006-04.jsonl.gz"
6
+ - config_name: 2006-05
7
+ data_files: "files/2006-05.jsonl.gz"
8
+ - config_name: 2006-06
9
+ data_files: "files/2006-06.jsonl.gz"
10
+ - config_name: 2006-07
11
+ data_files: "files/2006-07.jsonl.gz"
12
+ - config_name: 2006-08
13
+ data_files: "files/2006-08.jsonl.gz"
14
+ - config_name: 2006-09
15
+ data_files: "files/2006-09.jsonl.gz"
16
+ - config_name: 2006-10
17
+ data_files: "files/2006-10.jsonl.gz"
18
+ - config_name: 2006-11
19
+ data_files: "files/2006-11.jsonl.gz"
20
+ - config_name: 2006-12
21
+ data_files: "files/2006-12.jsonl.gz"
22
+ - config_name: 2007-01
23
+ data_files: "files/2007-01.jsonl.gz"
24
+ - config_name: 2007-02
25
+ data_files: "files/2007-02.jsonl.gz"
26
+ - config_name: 2007-03
27
+ data_files: "files/2007-03.jsonl.gz"
28
+ - config_name: 2007-04
29
+ data_files: "files/2007-04.jsonl.gz"
30
+ - config_name: 2007-05
31
+ data_files: "files/2007-05.jsonl.gz"
32
+ - config_name: 2007-06
33
+ data_files: "files/2007-06.jsonl.gz"
34
+ - config_name: 2007-07
35
+ data_files: "files/2007-07.jsonl.gz"
36
+ - config_name: 2007-08
37
+ data_files: "files/2007-08.jsonl.gz"
38
+ - config_name: 2007-09
39
+ data_files: "files/2007-09.jsonl.gz"
40
+ - config_name: 2007-10
41
+ data_files: "files/2007-10.jsonl.gz"
42
+ - config_name: 2007-11
43
+ data_files: "files/2007-11.jsonl.gz"
44
+ - config_name: 2007-12
45
+ data_files: "files/2007-12.jsonl.gz"
46
+ - config_name: 2008-01
47
+ data_files: "files/2008-01.jsonl.gz"
48
+ - config_name: 2008-02
49
+ data_files: "files/2008-02.jsonl.gz"
50
+ - config_name: 2008-03
51
+ data_files: "files/2008-03.jsonl.gz"
52
+ - config_name: 2008-04
53
+ data_files: "files/2008-04.jsonl.gz"
54
+ - config_name: 2008-05
55
+ data_files: "files/2008-05.jsonl.gz"
56
+ - config_name: 2008-06
57
+ data_files: "files/2008-06.jsonl.gz"
58
+ - config_name: 2008-07
59
+ data_files: "files/2008-07.jsonl.gz"
60
+ - config_name: 2008-08
61
+ data_files: "files/2008-08.jsonl.gz"
62
+ - config_name: 2008-09
63
+ data_files: "files/2008-09.jsonl.gz"
64
+ - config_name: 2008-10
65
+ data_files: "files/2008-10.jsonl.gz"
66
+ - config_name: 2008-11
67
+ data_files: "files/2008-11.jsonl.gz"
68
+ - config_name: 2008-12
69
+ data_files: "files/2008-12.jsonl.gz"
70
+ - config_name: 2009-01
71
+ data_files: "files/2009-01.jsonl.gz"
72
+ - config_name: 2009-02
73
+ data_files: "files/2009-02.jsonl.gz"
74
+ - config_name: 2009-03
75
+ data_files: "files/2009-03.jsonl.gz"
76
+ - config_name: 2009-04
77
+ data_files: "files/2009-04.jsonl.gz"
78
+ - config_name: 2009-05
79
+ data_files: "files/2009-05.jsonl.gz"
80
+ - config_name: 2009-06
81
+ data_files: "files/2009-06.jsonl.gz"
82
+ - config_name: 2009-07
83
+ data_files: "files/2009-07.jsonl.gz"
84
+ - config_name: 2009-08
85
+ data_files: "files/2009-08.jsonl.gz"
86
+ - config_name: 2009-09
87
+ data_files: "files/2009-09.jsonl.gz"
88
+ - config_name: 2009-10
89
+ data_files: "files/2009-10.jsonl.gz"
90
+ - config_name: 2009-11
91
+ data_files: "files/2009-11.jsonl.gz"
92
+ - config_name: 2009-12
93
+ data_files: "files/2009-12.jsonl.gz"
94
+ - config_name: 2010-01
95
+ data_files: "files/2010-01.jsonl.gz"
96
+ - config_name: 2010-02
97
+ data_files: "files/2010-02.jsonl.gz"
98
+ - config_name: 2010-03
99
+ data_files: "files/2010-03.jsonl.gz"
100
+ - config_name: 2010-04
101
+ data_files: "files/2010-04.jsonl.gz"
102
+ - config_name: 2010-05
103
+ data_files: "files/2010-05.jsonl.gz"
104
+ - config_name: 2010-06
105
+ data_files: "files/2010-06.jsonl.gz"
106
+ - config_name: 2010-07
107
+ data_files: "files/2010-07.jsonl.gz"
108
+ - config_name: 2010-08
109
+ data_files: "files/2010-08.jsonl.gz"
110
+ - config_name: 2010-09
111
+ data_files: "files/2010-09.jsonl.gz"
112
+ - config_name: 2010-10
113
+ data_files: "files/2010-10.jsonl.gz"
114
+ - config_name: 2010-11
115
+ data_files: "files/2010-11.jsonl.gz"
116
+ - config_name: 2010-12
117
+ data_files: "files/2010-12.jsonl.gz"
118
+ - config_name: 2011-01
119
+ data_files: "files/2011-01.jsonl.gz"
120
+ - config_name: 2011-02
121
+ data_files: "files/2011-02.jsonl.gz"
122
+ - config_name: 2011-03
123
+ data_files: "files/2011-03.jsonl.gz"
124
+ - config_name: 2011-04
125
+ data_files: "files/2011-04.jsonl.gz"
126
+ - config_name: 2011-05
127
+ data_files: "files/2011-05.jsonl.gz"
128
+ - config_name: 2011-06
129
+ data_files: "files/2011-06.jsonl.gz"
130
+ - config_name: 2011-07
131
+ data_files: "files/2011-07.jsonl.gz"
132
+ - config_name: 2011-08
133
+ data_files: "files/2011-08.jsonl.gz"
134
+ - config_name: 2011-09
135
+ data_files: "files/2011-09.jsonl.gz"
136
+ - config_name: 2011-10
137
+ data_files: "files/2011-10.jsonl.gz"
138
+ - config_name: 2011-11
139
+ data_files: "files/2011-11.jsonl.gz"
140
+ - config_name: 2011-12
141
+ data_files: "files/2011-12.jsonl.gz"
142
+ - config_name: 2012-01
143
+ data_files: "files/2012-01.jsonl.gz"
144
+ - config_name: 2012-02
145
+ data_files: "files/2012-02.jsonl.gz"
146
+ - config_name: 2012-03
147
+ data_files: "files/2012-03.jsonl.gz"
148
+ - config_name: 2012-04
149
+ data_files: "files/2012-04.jsonl.gz"
150
+ - config_name: 2012-05
151
+ data_files: "files/2012-05.jsonl.gz"
152
+ - config_name: 2012-06
153
+ data_files: "files/2012-06.jsonl.gz"
154
+ - config_name: 2012-07
155
+ data_files: "files/2012-07.jsonl.gz"
156
+ - config_name: 2012-08
157
+ data_files: "files/2012-08.jsonl.gz"
158
+ - config_name: 2012-09
159
+ data_files: "files/2012-09.jsonl.gz"
160
+ - config_name: 2012-10
161
+ data_files: "files/2012-10.jsonl.gz"
162
+ - config_name: 2012-11
163
+ data_files: "files/2012-11.jsonl.gz"
164
+ - config_name: 2012-12
165
+ data_files: "files/2012-12.jsonl.gz"
166
+ - config_name: 2013-01
167
+ data_files: "files/2013-01.jsonl.gz"
168
+ - config_name: 2013-02
169
+ data_files: "files/2013-02.jsonl.gz"
170
+ - config_name: 2013-03
171
+ data_files: "files/2013-03.jsonl.gz"
172
+ - config_name: 2013-04
173
+ data_files: "files/2013-04.jsonl.gz"
174
+ - config_name: 2013-05
175
+ data_files: "files/2013-05.jsonl.gz"
176
+ - config_name: 2013-06
177
+ data_files: "files/2013-06.jsonl.gz"
178
+ - config_name: 2013-07
179
+ data_files: "files/2013-07.jsonl.gz"
180
+ - config_name: 2013-08
181
+ data_files: "files/2013-08.jsonl.gz"
182
+ - config_name: 2013-09
183
+ data_files: "files/2013-09.jsonl.gz"
184
+ - config_name: 2013-10
185
+ data_files: "files/2013-10.jsonl.gz"
186
+ - config_name: 2013-11
187
+ data_files: "files/2013-11.jsonl.gz"
188
+ - config_name: 2013-12
189
+ data_files: "files/2013-12.jsonl.gz"
190
+ - config_name: 2014-01
191
+ data_files: "files/2014-01.jsonl.gz"
192
+ - config_name: 2014-02
193
+ data_files: "files/2014-02.jsonl.gz"
194
+ - config_name: 2014-03
195
+ data_files: "files/2014-03.jsonl.gz"
196
+ - config_name: 2014-04
197
+ data_files: "files/2014-04.jsonl.gz"
198
+ - config_name: 2014-05
199
+ data_files: "files/2014-05.jsonl.gz"
200
+ - config_name: 2014-06
201
+ data_files: "files/2014-06.jsonl.gz"
202
+ - config_name: 2014-07
203
+ data_files: "files/2014-07.jsonl.gz"
204
+ - config_name: 2014-08
205
+ data_files: "files/2014-08.jsonl.gz"
206
+ - config_name: 2014-09
207
+ data_files: "files/2014-09.jsonl.gz"
208
+ - config_name: 2014-10
209
+ data_files: "files/2014-10.jsonl.gz"
210
+ - config_name: 2014-11
211
+ data_files: "files/2014-11.jsonl.gz"
212
+ - config_name: 2014-12
213
+ data_files: "files/2014-12.jsonl.gz"
214
+ - config_name: 2015-01
215
+ data_files: "files/2015-01.jsonl.gz"
216
+ - config_name: 2015-02
217
+ data_files: "files/2015-02.jsonl.gz"
218
+ - config_name: 2015-03
219
+ data_files: "files/2015-03.jsonl.gz"
220
+ - config_name: 2015-04
221
+ data_files: "files/2015-04.jsonl.gz"
222
+ - config_name: 2015-05
223
+ data_files: "files/2015-05.jsonl.gz"
224
+ - config_name: 2015-06
225
+ data_files: "files/2015-06.jsonl.gz"
226
+ - config_name: 2015-07
227
+ data_files: "files/2015-07.jsonl.gz"
228
+ - config_name: 2015-08
229
+ data_files: "files/2015-08.jsonl.gz"
230
+ - config_name: 2015-09
231
+ data_files: "files/2015-09.jsonl.gz"
232
+ - config_name: 2015-10
233
+ data_files: "files/2015-10.jsonl.gz"
234
+ - config_name: 2015-11
235
+ data_files: "files/2015-11.jsonl.gz"
236
+ - config_name: 2015-12
237
+ data_files: "files/2015-12.jsonl.gz"
238
+ - config_name: 2016-01
239
+ data_files: "files/2016-01.jsonl.gz"
240
+ - config_name: 2016-02
241
+ data_files: "files/2016-02.jsonl.gz"
242
+ - config_name: 2016-03
243
+ data_files: "files/2016-03.jsonl.gz"
244
+ - config_name: 2016-04
245
+ data_files: "files/2016-04.jsonl.gz"
246
+ - config_name: 2016-05
247
+ data_files: "files/2016-05.jsonl.gz"
248
+ - config_name: 2016-06
249
+ data_files: "files/2016-06.jsonl.gz"
250
+ - config_name: 2016-07
251
+ data_files: "files/2016-07.jsonl.gz"
252
+ - config_name: 2016-08
253
+ data_files: "files/2016-08.jsonl.gz"
254
+ - config_name: 2016-09
255
+ data_files: "files/2016-09.jsonl.gz"
256
+ - config_name: 2016-10
257
+ data_files: "files/2016-10.jsonl.gz"
258
+ - config_name: 2016-11
259
+ data_files: "files/2016-11.jsonl.gz"
260
+ - config_name: 2016-12
261
+ data_files: "files/2016-12.jsonl.gz"
262
+ - config_name: 2017-01
263
+ data_files: "files/2017-01.jsonl.gz"
264
+ - config_name: 2017-02
265
+ data_files: "files/2017-02.jsonl.gz"
266
+ - config_name: 2017-03
267
+ data_files: "files/2017-03.jsonl.gz"
268
+ - config_name: 2017-04
269
+ data_files: "files/2017-04.jsonl.gz"
270
+ - config_name: 2017-05
271
+ data_files: "files/2017-05.jsonl.gz"
272
+ - config_name: 2017-06
273
+ data_files: "files/2017-06.jsonl.gz"
274
+ - config_name: 2017-07
275
+ data_files: "files/2017-07.jsonl.gz"
276
+ - config_name: 2017-08
277
+ data_files: "files/2017-08.jsonl.gz"
278
+ - config_name: 2017-09
279
+ data_files: "files/2017-09.jsonl.gz"
280
+ - config_name: 2017-10
281
+ data_files: "files/2017-10.jsonl.gz"
282
+ - config_name: 2017-11
283
+ data_files: "files/2017-11.jsonl.gz"
284
+ - config_name: 2017-12
285
+ data_files: "files/2017-12.jsonl.gz"
286
+ - config_name: 2018-01
287
+ data_files: "files/2018-01.jsonl.gz"
288
+ - config_name: 2018-02
289
+ data_files: "files/2018-02.jsonl.gz"
290
+ - config_name: 2018-03
291
+ data_files: "files/2018-03.jsonl.gz"
292
+ - config_name: 2018-04
293
+ data_files: "files/2018-04.jsonl.gz"
294
+ - config_name: 2018-05
295
+ data_files: "files/2018-05.jsonl.gz"
296
+ - config_name: 2018-06
297
+ data_files: "files/2018-06.jsonl.gz"
298
+ - config_name: 2018-07
299
+ data_files: "files/2018-07.jsonl.gz"
300
+ - config_name: 2018-08
301
+ data_files: "files/2018-08.jsonl.gz"
302
+ - config_name: 2018-09
303
+ data_files: "files/2018-09.jsonl.gz"
304
+ - config_name: 2018-10
305
+ data_files: "files/2018-10.jsonl.gz"
306
+ - config_name: 2018-11
307
+ data_files: "files/2018-11.jsonl.gz"
308
+ - config_name: 2018-12
309
+ data_files: "files/2018-12.jsonl.gz"
310
+ - config_name: 2019-01
311
+ data_files: "files/2019-01.jsonl.gz"
312
+ - config_name: 2019-02
313
+ data_files: "files/2019-02.jsonl.gz"
314
+ - config_name: 2019-03
315
+ data_files: "files/2019-03.jsonl.gz"
316
+ - config_name: 2019-04
317
+ data_files: "files/2019-04.jsonl.gz"
318
+ - config_name: 2019-05
319
+ data_files: "files/2019-05.jsonl.gz"
320
+ - config_name: 2019-06
321
+ data_files: "files/2019-06.jsonl.gz"
322
+ - config_name: 2019-07
323
+ data_files: "files/2019-07.jsonl.gz"
324
+ - config_name: 2019-08
325
+ data_files: "files/2019-08.jsonl.gz"
326
+ - config_name: 2019-09
327
+ data_files: "files/2019-09.jsonl.gz"
328
+ - config_name: 2019-10
329
+ data_files: "files/2019-10.jsonl.gz"
330
+ - config_name: 2019-11
331
+ data_files: "files/2019-11.jsonl.gz"
332
+ - config_name: 2019-12
333
+ data_files: "files/2019-12.jsonl.gz"
334
+ - config_name: 2020-01
335
+ data_files: "files/2020-01.jsonl.gz"
336
+ - config_name: 2020-02
337
+ data_files: "files/2020-02.jsonl.gz"
338
+ - config_name: 2020-03
339
+ data_files: "files/2020-03.jsonl.gz"
340
+ - config_name: 2020-04
341
+ data_files: "files/2020-04.jsonl.gz"
342
+ - config_name: 2020-05
343
+ data_files: "files/2020-05.jsonl.gz"
344
+ - config_name: 2020-06
345
+ data_files: "files/2020-06.jsonl.gz"
346
+ - config_name: 2020-07
347
+ data_files: "files/2020-07.jsonl.gz"
348
+ - config_name: 2020-08
349
+ data_files: "files/2020-08.jsonl.gz"
350
+ - config_name: 2020-09
351
+ data_files: "files/2020-09.jsonl.gz"
352
+ - config_name: 2020-10
353
+ data_files: "files/2020-10.jsonl.gz"
354
+ - config_name: 2020-11
355
+ data_files: "files/2020-11.jsonl.gz"
356
+ - config_name: 2020-12
357
+ data_files: "files/2020-12.jsonl.gz"
358
+ - config_name: 2021-01
359
+ data_files: "files/2021-01.jsonl.gz"
360
+ - config_name: 2021-02
361
+ data_files: "files/2021-02.jsonl.gz"
362
+ - config_name: 2021-03
363
+ data_files: "files/2021-03.jsonl.gz"
364
+ - config_name: 2021-04
365
+ data_files: "files/2021-04.jsonl.gz"
366
+ - config_name: 2021-05
367
+ data_files: "files/2021-05.jsonl.gz"
368
+ - config_name: 2021-06
369
+ data_files: "files/2021-06.jsonl.gz"
370
+ - config_name: 2021-07
371
+ data_files: "files/2021-07.jsonl.gz"
372
+ - config_name: 2021-08
373
+ data_files: "files/2021-08.jsonl.gz"
374
+ - config_name: 2021-09
375
+ data_files: "files/2021-09.jsonl.gz"
376
+ - config_name: 2021-10
377
+ data_files: "files/2021-10.jsonl.gz"
378
+ - config_name: 2021-11
379
+ data_files: "files/2021-11.jsonl.gz"
380
+ - config_name: 2021-12
381
+ data_files: "files/2021-12.jsonl.gz"
382
+ - config_name: 2022-01
383
+ data_files: "files/2022-01.jsonl.gz"
384
+ - config_name: 2022-02
385
+ data_files: "files/2022-02.jsonl.gz"
386
+ - config_name: 2022-03
387
+ data_files: "files/2022-03.jsonl.gz"
388
+ - config_name: 2022-04
389
+ data_files: "files/2022-04.jsonl.gz"
390
+ - config_name: 2022-05
391
+ data_files: "files/2022-05.jsonl.gz"
392
+ - config_name: 2022-06
393
+ data_files: "files/2022-06.jsonl.gz"
394
+ - config_name: 2022-07
395
+ data_files: "files/2022-07.jsonl.gz"
396
+ - config_name: 2022-08
397
+ data_files: "files/2022-08.jsonl.gz"
398
+ - config_name: 2022-09
399
+ data_files: "files/2022-09.jsonl.gz"
400
+ - config_name: 2022-10
401
+ data_files: "files/2022-10.jsonl.gz"
402
+ - config_name: 2022-11
403
+ data_files: "files/2022-11.jsonl.gz"
404
+ - config_name: 2022-12
405
+ data_files: "files/2022-12.jsonl.gz"
406
+ - config_name: 2023-01
407
+ data_files: "files/2023-01.jsonl.gz"
408
+ - config_name: 2023-02
409
+ data_files: "files/2023-02.jsonl.gz"
410
+ - config_name: 2023-03
411
+ data_files: "files/2023-03.jsonl.gz"
412
+ - config_name: 2023-04
413
+ data_files: "files/2023-04.jsonl.gz"
414
+ - config_name: 2023-05
415
+ data_files: "files/2023-05.jsonl.gz"
416
+ - config_name: 2023-06
417
+ data_files: "files/2023-06.jsonl.gz"
418
+ - config_name: 2023-07
419
+ data_files: "files/2023-07.jsonl.gz"
420
  ---
update.py ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Cellar text and eurovoc extraction
3
+
4
+ python update.py 10000 dataset.jsonl
5
+
6
+ will extract for the last 10,000 days text in english and eurovoc labels in the JSON line file.
7
+
8
+
9
+ requirements:
10
+ beautifulsoup4==4.12.2
11
+ docx2txt==0.8
12
+ ipython==8.14.0
13
+ jinja2==3.1.2
14
+ joblib==1.3.1
15
+ pdfminer.six==20221105
16
+ pip-chill==1.0.3
17
+ pycryptodome==3.18.0
18
+ requests==2.31.0
19
+ tqdm==4.65.0
20
+ xmltodict==0.13.0
21
+ """
22
+ import datetime
23
+ import json
24
+ from concurrent.futures import ProcessPoolExecutor
25
+
26
+ from bs4 import BeautifulSoup
27
+ import logging
28
+ import re
29
+ import sys
30
+
31
+ from tqdm import tqdm
32
+ from io import BytesIO
33
+ import jinja2
34
+ from joblib import Memory
35
+
36
+ location = './cache'
37
+ memory = Memory(location, verbose=0)
38
+
39
+ log = logging.getLogger(__name__)
40
+ log.addHandler(logging.FileHandler('collect.log'))
41
+ log.setLevel(logging.DEBUG)
42
+
43
+ import xmltodict
44
+
45
+ import docx2txt as docx2txt
46
+ import requests
47
+ from joblib import expires_after
48
+ from pdfminer.high_level import extract_text
49
+
50
+
51
+ def clean_text(func):
52
+ """
53
+ Decorator used to clean the text
54
+ :param func:
55
+ :return:
56
+ """
57
+
58
+ def inner(*args, **kwargs):
59
+ text = func(*args, **kwargs)
60
+ text = text.replace("\n", " ")
61
+ text = text.replace(" .", ".")
62
+ text = re.sub(' +', ' ', text)
63
+ text = re.sub(' *[.] *', '. ', text)
64
+ text = re.sub('\.\s*\.\s*\.+', '. ', text)
65
+ text = '. '.join([s.strip() for s in text.split(".") if len(s.strip())])
66
+ return text
67
+
68
+ return inner
69
+
70
+
71
+ @memory.cache(cache_validation_callback=expires_after(minutes=120))
72
+ def get_eurovoc_terms_and_id():
73
+ eurovoc_terms_and_id = {}
74
+ response = requests.get('http://publications.europa.eu/resource/dataset/eurovoc',
75
+ headers={'Accept': 'application/xml',
76
+ 'Accept-Language': 'en'}
77
+ )
78
+ data = xmltodict.parse(response.content)
79
+ for term in data['xs:schema']['xs:simpleType']['xs:restriction']['xs:enumeration']:
80
+ try:
81
+ name = term['xs:annotation']['xs:documentation'].split('/')[0].strip()
82
+ for r in term['xs:annotation']['xs:appinfo']['record']:
83
+ if r['@thesaurus_id'] != '':
84
+ eurovoc_terms_and_id[name.lower()] = r['@thesaurus_id']
85
+ except KeyError as e:
86
+ log.warning("⚠️ Could not parse", term)
87
+ return eurovoc_terms_and_id
88
+
89
+
90
+ def get_sparql_query(d):
91
+ start = d.strftime('%Y-%m-%d')
92
+ end = d + datetime.timedelta(days=2)
93
+ end = end.strftime('%Y-%m-%d')
94
+ environment = jinja2.Environment()
95
+ template = environment.from_string(open("query.j2", 'r').read())
96
+ return template.render(start=start, end=end)
97
+
98
+
99
+ def get_json_response(d):
100
+ url = "https://publications.europa.eu/webapi/rdf/sparql"
101
+ params = {"default-graph-uri": "",
102
+ "query": get_sparql_query(d),
103
+ "format": "application/sparql-results+json",
104
+ "timeout": "0",
105
+ "debug": "on",
106
+ "run": "Run Query"}
107
+
108
+ response = requests.get(url, params)
109
+ assert response.status_code == 200
110
+ return response.json()
111
+
112
+
113
+ def get_concepts_id(list_of_eurovoc_terms):
114
+ terms = get_eurovoc_terms_and_id()
115
+ for e in list_of_eurovoc_terms:
116
+ try:
117
+ yield terms[e.strip().lower()]
118
+ except KeyError:
119
+ log.warning(f"⚠️ Could not find {e} in Eurovoc")
120
+
121
+
122
+ def get_docs(d):
123
+ results = get_json_response(d)
124
+ for r in results['results']['bindings']:
125
+ terms = r['subjects']['value'].replace(u'\xa0', u' ').split(',')
126
+ r['eurovoc_concepts'] = terms #list(get_concepts_id(terms))
127
+ r['url'] = r['cellarURIs']['value']
128
+ r['title'] = r['title']['value']
129
+ r['date'] = r['date']['value']
130
+ r['lang'] = r['langIdentifier']['value'].lower()
131
+ r['formats'] = [t for t in r['mtypes']['value'].split(',')]
132
+ for c in ['cellarURIs', 'mtypes', 'langIdentifier', 'subjects', 'authors', 'workTypes', 'workIds']:
133
+ del r[c]
134
+ yield r
135
+
136
+
137
+ def get_docs_text(d):
138
+ docs = list(get_docs(d))
139
+ print(f"Processing documents ... {len(docs)}")
140
+ with ProcessPoolExecutor(max_workers=16) as executor:
141
+ for v in tqdm(executor.map(get_body, docs), total=len(docs), colour='green'):
142
+ yield v
143
+
144
+
145
+ def get_body(r):
146
+ try:
147
+ if 'pdf' in r['formats']:
148
+ r['text'] = get_pdf_body(r)
149
+ elif 'docx' in r['formats']:
150
+ r['text'] = get_docx_body(r)
151
+ elif 'doc' in r['formats']:
152
+ r['text'] = get_doc_body(r)
153
+ elif 'xhtml' in r['formats']:
154
+ r['text'] = get_xhtml_body(r)
155
+ else:
156
+ log.warning(f"⚠️ Could not find a parser for {r['formats']}")
157
+ return r
158
+ except Exception as e:
159
+ log.error(str(e) + str(r) )
160
+
161
+
162
+
163
+ @clean_text
164
+ @memory.cache()
165
+ def get_pdf_body(r):
166
+ url = r['url']
167
+ language = r['lang']
168
+ accept = 'application/pdf'
169
+ response = requests.get(url, headers={'Accept': accept, 'Accept-Language': language})
170
+ if response.status_code == 300:
171
+ return " ".join(_multiple_choice(get_pdf_body, response, accept, language))
172
+ elif response.status_code == 200:
173
+ mem = BytesIO(response.content)
174
+ return extract_text(mem)
175
+
176
+ @clean_text
177
+ @memory.cache()
178
+ def get_xhtml_body(r):
179
+ url = r['url']
180
+ language = r['lang']
181
+ accept = 'application/xhtml+xml'
182
+ response = requests.get(url, headers={'Accept': accept, 'Accept-Language': language})
183
+ if response.status_code == 300:
184
+ return " ".join(_multiple_choice(get_xhtml_body, response, accept, language))
185
+ elif response.status_code == 200:
186
+ soup = BeautifulSoup(response.content, 'html.parser')
187
+ return soup.get_text()
188
+
189
+ def get_docx_body(r):
190
+ accept = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'
191
+ url = r['url']
192
+ lang = r['lang']
193
+ try:
194
+ return _get_doc_body(url, accept, lang)
195
+ except AssertionError as e:
196
+ log.warning(f"⚠️ Could not download {url} {e}")
197
+ print(f"⚠️ Could not download {r} --- {accept} {e}")
198
+ return ""
199
+
200
+
201
+ def get_doc_body(r):
202
+ accept = 'application/msword'
203
+ url = r['url']
204
+ lang = r['lang']
205
+ try:
206
+ return _get_doc_body(url, accept, lang)
207
+ except AssertionError as e:
208
+ log.warning(f"⚠️ Could not download {url} {e}")
209
+ print(f"⚠️ Could not download {r} --- {accept} {e}")
210
+ return ""
211
+
212
+ def _multiple_choice(func, response, accept, language):
213
+ soup = BeautifulSoup(response.text, 'html.parser')
214
+ for link in soup.find_all('a'):
215
+ if 'href' in link.attrs:
216
+ url = link.attrs['href']
217
+ yield func(url, accept, language)
218
+
219
+ @clean_text
220
+ @memory.cache()
221
+ def _get_doc_body(url, accept, language='en'):
222
+ response = requests.get(url, headers={'Accept': accept, 'Accept-Language': language})
223
+ if response.status_code == 300:
224
+ return " ".join(_multiple_choice(_get_doc_body, response, accept, language))
225
+ elif response.status_code == 200:
226
+ mem = BytesIO(response.content)
227
+ log.info(f"📄 MS Word doc download and parsed {url}")
228
+ return docx2txt.process(mem)
229
+ else:
230
+ raise AssertionError(f"📄 MS Word doc download failed {url} {response.status_code} {response.content}")
231
+
232
+
233
+ if __name__ == '__main__':
234
+ output = sys.argv[1]
235
+ max = int(sys.argv[2])
236
+ ofiles = {}
237
+ for i in range(max):
238
+ d = datetime.date.today() - datetime.timedelta(days=i)
239
+ print(d)
240
+ ym = d.strftime('%Y-%m')
241
+ if ym not in ofiles:
242
+ ofiles[ym] = open(output + ym + '.jsonl', 'w')
243
+ try:
244
+ for d in get_docs_text(d):
245
+ ofiles[ym].write(json.dumps(d) + '\n')
246
+ ofiles[ym].flush()
247
+ except Exception as e:
248
+ log.error('Day ' + str(d) + ' ' + str(e))
249
+ print ('Day ' + str(d) + ' ' + str(e))
250
+ for f in ofiles.values():
251
+ f.close()
252
+
253
+