JP-SystemsX commited on
Commit
3a62611
1 Parent(s): 3ab377c

Changed Dataset script to accommodate for new structuring

Browse files
Files changed (1) hide show
  1. super_eurlex.py +62 -47
super_eurlex.py CHANGED
@@ -55,8 +55,9 @@ _HOMEPAGE = ""
55
  # TODO: Add the licence for the dataset here if you can find it
56
  _LICENSE = ""
57
 
58
- AVAILABLE_LANGUAGES=['DE', 'EN']
59
  SECTORS=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'C', 'E']
 
60
 
61
  # Features to override the standard most Features were scrapped as a sequence
62
  # of strings with only the following exceptions
@@ -67,16 +68,14 @@ FEATURES = {
67
  'text_html_raw': datasets.Value("string"),
68
  }
69
  FEATURES_IN_SECTOR={
70
- '0':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned', 'form'],
71
- '1':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned', 'form',
72
- 'subject_matter', 'current_consolidated_version',
73
  'harmonisation_of_customs_law_community_transit', 'harmonisation_of_customs_law_customs_territory',
74
  'harmonisation_of_customs_law_value_for_customs_purposes', 'directory_code', 'eurovoc',
75
  'customs_duties_community_tariff_quotas', 'customs_duties_community_tariff_quotas',
76
  'customs_duties_authorisation_to_defer_application_of_cct', 'harmonisation_of_customs_law_various',
77
  'customs_duties_suspensions'],
78
- '2':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned',
79
- 'harmonisation_of_customs_law_origin_of_goods', 'form', 'directory_code',
80
  'subject_matter', 'eurovoc', 'harmonisation_of_customs_law_community_transit',
81
  '02.40.10.20_customs_union_and_free_movement_of_goods_/_specific_customs_rules_/_movement_of_goods_/_extra-community_trade_efta_agreements',
82
  'current_consolidated_version',
@@ -100,8 +99,7 @@ FEATURES_IN_SECTOR={
100
  '13.30.10.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_motor_vehicles',
101
  'common_customs_tariff_temporary_importation'
102
  ],
103
- '3':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned', 'form', 'cct_derogations',
104
- 'directory_code', 'subject_matter','eurovoc', 'cct_franchise',
105
  'harmonisation_of_customs_law_various', 'latest_consolidated_version',
106
  '02.40.10.20_customs_union_and_free_movement_of_goods_/_specific_customs_rules_/_movement_of_goods_/_extra-community_trade_efta_agreements',
107
  'harmonisation_of_customs_law_community_transit',
@@ -152,8 +150,7 @@ FEATURES_IN_SECTOR={
152
  '13.20.30.00_industrial_policy_and_internal_market_/_industrial_policy_sectoral_operations_/_aeronautical_industry',
153
  '13.20.00.00_industrial_policy_and_internal_market_/_industrial_policy_sectoral_operations'
154
  ],
155
- '4':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned', 'form', 'eurovoc',
156
- 'subject_matter', 'current_consolidated_version', 'directory_code',
157
  '13.30.10.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_motor_vehicles',
158
  '13.30.11.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_agricultural_and_forestry_tractors',
159
  '13.30.05.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_general,_programmes',
@@ -171,7 +168,7 @@ FEATURES_IN_SECTOR={
171
  '13.10.30.10_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_research_and_technological_development_/_general_principles',
172
  '13.10.20.00_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_programmes_and_statistics',
173
  '13.30.99.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_other_sectors_for_approximation_of_laws'],
174
- '5':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned', 'form', 'directory_code', 'subject_matter', 'eurovoc',
175
  '13.30.05.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_general,_programmes',
176
  '13.10.30.00_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_research_and_technological_development',
177
  '13.10.30.20_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_research_and_technological_development_/_research_sectors',
@@ -218,8 +215,7 @@ FEATURES_IN_SECTOR={
218
  'harmonisation_of_customs_law_value_for_customs_purposes',
219
  'harmonisation_of_customs_law_customs_territory',
220
  'current_consolidated_version'],
221
- '6':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned', 'form',
222
- 'case-law_directory_code_before_lisbon', 'subject_matter', 'b-03.07.01_european_community_eec/ec_/_agriculture_/_structural_policy_/_structural_reform_of_agriculture_joint_action',
223
  'b-03.03.07_european_community_eec/ec_/_agriculture_/_common_organization_of_the_markets_principles_and_mechanisms_/_import_and_export_licences_and_advance-fixing_certificates',
224
  'b-03.03.06_european_community_eec/ec_/_agriculture_/_common_organization_of_the_markets_principles_and_mechanisms_/_export_refunds',
225
  'b-04.06.04.02_european_community_eec/ec_/_eec/ec_-_free_movement_of_persons_and_services_*_free_movement_of_persons_and_services_/_social_security_for_workers_/_social_security_for_workers_-_old_age_and_death_*_old_age_and_death_/_calculation_of_benefits_provisions_against_overlapping',
@@ -240,11 +236,10 @@ FEATURES_IN_SECTOR={
240
  '13.30.14.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_foodstuffs',
241
  '13.10.30.00_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_research_and_technological_development',
242
  'b-07.05.04.01_european_community_eec/ec_/_eec/ec_-_competition_*_competition_/_concentrations_between_undertakings_/_examination_by_the_commission_/_initiation_of_proceedings_notification_and_complaints'],
243
- '7':['celex_id', 'text_cleaned', 'form', 'transposed_legal_acts'],#, 'text_html_raw', 'text_html_cleaned',
244
- '8':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned', 'form',
245
- 'case-law_directory_code_before_lisbon', 'subject_matter',
246
  'b-03.03_european_community_eec/ec_/_agriculture_/_common_organization_of_the_markets_principles_and_mechanisms'],
247
- '9':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned', 'form', 'eurovoc', 'subject_matter', 'directory_code',
248
  '13.10.30.10_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_research_and_technological_development_/_general_principles',
249
  '13.30.99.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_other_sectors_for_approximation_of_laws',
250
  '13.30.05.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_general,_programmes',
@@ -285,8 +280,8 @@ FEATURES_IN_SECTOR={
285
  '13.20.10.00_industrial_policy_and_internal_market_/_industrial_policy_sectoral_operations_/_iron_and_steel_industry',
286
  '13.30.11.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_agricultural_and_forestry_tractors',
287
  'harmonisation_of_customs_law_warehouses,_free_zones'],
288
- 'C':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned', 'form', 'eurovoc'],
289
- 'E':['celex_id', 'text_html_raw', 'text_html_cleaned', 'text_cleaned', 'form', 'directory_code',
290
  'subject_matter', 'eurovoc',
291
  '13.30.14.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_foodstuffs',
292
  '13.30.10.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_motor_vehicles',
@@ -295,28 +290,42 @@ FEATURES_IN_SECTOR={
295
  '13.20.60.00_industrial_policy_and_internal_market_/_industrial_policy_sectoral_operations_/_information_technology,_telecommunications_and_data-processing',
296
  '13.30.99.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_other_sectors_for_approximation_of_laws'],
297
  }
298
- AVAILABLE_FEATURES={sector: datasets.Features({feature:(FEATURES[feature] if feature in FEATURES else datasets.Sequence(datasets.Value("string"))) for feature in FEATURES_IN_SECTOR[sector]}) for sector in SECTORS}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
 
300
  SECTOR_DESCRIPTIONS={
301
- '0':"Consolidated acts ",
302
- '1':"Treaties",
303
- '2':"International agreements",
304
- '3':"Legislation",
305
- '4':"Complementary legislation",
306
- '5':"Preparatory acts and working documents",
307
- '6':"Case-law",
308
- '7':"National transposition measures",
309
- '8':"References to national case-law concerning EU law",
310
- '9':"Parliamentary questions",
311
- 'C':"Other documents published in the Official Journal C series",
312
- 'E':"EFTA documents",
313
  }
314
 
315
 
316
  class SuperEurlexConfig(datasets.BuilderConfig):
317
  """BuilderConfig for SuperGLUE."""
318
 
319
- def __init__(self, sector, language, features, citation, url, **kwargs):
320
  """BuilderConfig for SuperGLUE.
321
 
322
  Args:
@@ -329,12 +338,13 @@ class SuperEurlexConfig(datasets.BuilderConfig):
329
  url: *string*, url for information about the data set.
330
  **kwargs: keyword arguments forwarded to super.
331
  """
332
- name=sector+'.'+language
333
  super().__init__(name=name, version=datasets.Version("0.1.0"), **kwargs)
334
  self.features = features
335
  self.language = language
336
  self.sector = sector
337
- self.text_data_url = f"text_data/{language}/{sector}.parquet"
 
338
  self.meta_data_url = f"meta_data/{sector}.parquet"
339
  self.citation = citation
340
  self.url = url
@@ -357,18 +367,20 @@ class SuperEurlex(datasets.GeneratorBasedBuilder):
357
  SuperEurlexConfig(#version=VERSION,
358
  sector=sect,
359
  language=lang,
 
360
  description=SECTOR_DESCRIPTIONS[sect],
361
- features=AVAILABLE_FEATURES[sect],
362
  citation=_CITATION,
363
  url=_HOMEPAGE)
364
- for lang in AVAILABLE_LANGUAGES for sect in SECTORS
365
  ]
366
 
367
  #DEFAULT_CONFIG_NAME = "3.DE" # It's not mandatory to have a default configuration. Just use one if it make sense.
368
 
369
  def _info(self):
370
  # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
371
- features = AVAILABLE_FEATURES[self.config.sector]
 
372
  info = datasets.DatasetInfo(
373
  # This is the description that will appear on the datasets page.
374
  description=_DESCRIPTION,
@@ -436,12 +448,15 @@ if __name__ == '__main__':
436
  print(sys.argv[0])
437
  for sector in SECTORS:
438
  for lang in AVAILABLE_LANGUAGES:
439
- print(f'{sector}.{lang}')
440
- try:
441
- dataset = ds.load_dataset(sys.argv[0],f'{sector}.{lang}')
442
- print(dataset)
443
- print('\n')
444
- except Exception as e:
445
- # Handle the exception
446
- print("An error occurred: " + e.with_traceback())
447
- print(f"\n{sector}.{lang} Couldn't be loaded\n")
 
 
 
 
55
  # TODO: Add the licence for the dataset here if you can find it
56
  _LICENSE = ""
57
 
58
+ AVAILABLE_LANGUAGES=['DE']#, 'EN'
59
  SECTORS=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'C', 'E']
60
+ VERSIONS=[None, 'html', 'clean']
61
 
62
  # Features to override the standard most Features were scrapped as a sequence
63
  # of strings with only the following exceptions
 
68
  'text_html_raw': datasets.Value("string"),
69
  }
70
  FEATURES_IN_SECTOR={
71
+ '0':['form'],
72
+ '1':['form', 'subject_matter', 'current_consolidated_version',
 
73
  'harmonisation_of_customs_law_community_transit', 'harmonisation_of_customs_law_customs_territory',
74
  'harmonisation_of_customs_law_value_for_customs_purposes', 'directory_code', 'eurovoc',
75
  'customs_duties_community_tariff_quotas', 'customs_duties_community_tariff_quotas',
76
  'customs_duties_authorisation_to_defer_application_of_cct', 'harmonisation_of_customs_law_various',
77
  'customs_duties_suspensions'],
78
+ '2':['harmonisation_of_customs_law_origin_of_goods', 'form', 'directory_code',
 
79
  'subject_matter', 'eurovoc', 'harmonisation_of_customs_law_community_transit',
80
  '02.40.10.20_customs_union_and_free_movement_of_goods_/_specific_customs_rules_/_movement_of_goods_/_extra-community_trade_efta_agreements',
81
  'current_consolidated_version',
 
99
  '13.30.10.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_motor_vehicles',
100
  'common_customs_tariff_temporary_importation'
101
  ],
102
+ '3':['form', 'cct_derogations', 'directory_code', 'subject_matter','eurovoc', 'cct_franchise',
 
103
  'harmonisation_of_customs_law_various', 'latest_consolidated_version',
104
  '02.40.10.20_customs_union_and_free_movement_of_goods_/_specific_customs_rules_/_movement_of_goods_/_extra-community_trade_efta_agreements',
105
  'harmonisation_of_customs_law_community_transit',
 
150
  '13.20.30.00_industrial_policy_and_internal_market_/_industrial_policy_sectoral_operations_/_aeronautical_industry',
151
  '13.20.00.00_industrial_policy_and_internal_market_/_industrial_policy_sectoral_operations'
152
  ],
153
+ '4':['form', 'eurovoc', 'subject_matter', 'current_consolidated_version', 'directory_code',
 
154
  '13.30.10.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_motor_vehicles',
155
  '13.30.11.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_agricultural_and_forestry_tractors',
156
  '13.30.05.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_general,_programmes',
 
168
  '13.10.30.10_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_research_and_technological_development_/_general_principles',
169
  '13.10.20.00_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_programmes_and_statistics',
170
  '13.30.99.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_other_sectors_for_approximation_of_laws'],
171
+ '5':['form', 'directory_code', 'subject_matter', 'eurovoc',
172
  '13.30.05.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_general,_programmes',
173
  '13.10.30.00_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_research_and_technological_development',
174
  '13.10.30.20_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_research_and_technological_development_/_research_sectors',
 
215
  'harmonisation_of_customs_law_value_for_customs_purposes',
216
  'harmonisation_of_customs_law_customs_territory',
217
  'current_consolidated_version'],
218
+ '6':['form', 'case-law_directory_code_before_lisbon', 'subject_matter', 'b-03.07.01_european_community_eec/ec_/_agriculture_/_structural_policy_/_structural_reform_of_agriculture_joint_action',
 
219
  'b-03.03.07_european_community_eec/ec_/_agriculture_/_common_organization_of_the_markets_principles_and_mechanisms_/_import_and_export_licences_and_advance-fixing_certificates',
220
  'b-03.03.06_european_community_eec/ec_/_agriculture_/_common_organization_of_the_markets_principles_and_mechanisms_/_export_refunds',
221
  'b-04.06.04.02_european_community_eec/ec_/_eec/ec_-_free_movement_of_persons_and_services_*_free_movement_of_persons_and_services_/_social_security_for_workers_/_social_security_for_workers_-_old_age_and_death_*_old_age_and_death_/_calculation_of_benefits_provisions_against_overlapping',
 
236
  '13.30.14.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_foodstuffs',
237
  '13.10.30.00_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_research_and_technological_development',
238
  'b-07.05.04.01_european_community_eec/ec_/_eec/ec_-_competition_*_competition_/_concentrations_between_undertakings_/_examination_by_the_commission_/_initiation_of_proceedings_notification_and_complaints'],
239
+ '7':['form', 'transposed_legal_acts'],#, 'text_html_raw', 'text_html_cleaned',
240
+ '8':['form', 'case-law_directory_code_before_lisbon', 'subject_matter',
 
241
  'b-03.03_european_community_eec/ec_/_agriculture_/_common_organization_of_the_markets_principles_and_mechanisms'],
242
+ '9':['form', 'eurovoc', 'subject_matter', 'directory_code',
243
  '13.10.30.10_industrial_policy_and_internal_market_/_industrial_policy_general,_programmes,_statistics_and_research_/_research_and_technological_development_/_general_principles',
244
  '13.30.99.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_other_sectors_for_approximation_of_laws',
245
  '13.30.05.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_general,_programmes',
 
280
  '13.20.10.00_industrial_policy_and_internal_market_/_industrial_policy_sectoral_operations_/_iron_and_steel_industry',
281
  '13.30.11.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_agricultural_and_forestry_tractors',
282
  'harmonisation_of_customs_law_warehouses,_free_zones'],
283
+ 'C':['form', 'eurovoc'],
284
+ 'E':['form', 'directory_code',
285
  'subject_matter', 'eurovoc',
286
  '13.30.14.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_foodstuffs',
287
  '13.30.10.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_motor_vehicles',
 
290
  '13.20.60.00_industrial_policy_and_internal_market_/_industrial_policy_sectoral_operations_/_information_technology,_telecommunications_and_data-processing',
291
  '13.30.99.00_industrial_policy_and_internal_market_/_internal_market_approximation_of_laws_/_other_sectors_for_approximation_of_laws'],
292
  }
293
+
294
+ VERSION_FEATURES={
295
+ None: ['celex_id', 'text_cleaned'],
296
+ 'clean': ['celex_id', 'text_cleaned'],
297
+ 'html': ['celex_id', 'text_html_raw'],
298
+ }
299
+
300
+ available_features_tmp = []
301
+ for version in VERSIONS:
302
+ v = '' if version is None else f"_{version}"
303
+ available_features_tmp.append(
304
+ {sector+v: datasets.Features({feature:(FEATURES[feature] if feature in FEATURES else datasets.Sequence(datasets.Value("string"))) for feature in VERSION_FEATURES[version] + FEATURES_IN_SECTOR[sector]}) for sector in SECTORS}
305
+ )
306
+ # Combine Features Lists into single dictionary with the Features of each version of each sector
307
+ AVAILABLE_FEATURES={k: v for d in available_features_tmp for k, v in d.items()}
308
 
309
  SECTOR_DESCRIPTIONS={
310
+ '0': "Consolidated acts ",
311
+ '1': "Treaties",
312
+ '2': "International agreements",
313
+ '3': "Legislation",
314
+ '4': "Complementary legislation",
315
+ '5': "Preparatory acts and working documents",
316
+ '6': "Case-law",
317
+ '7': "National transposition measures",
318
+ '8': "References to national case-law concerning EU law",
319
+ '9': "Parliamentary questions",
320
+ 'C': "Other documents published in the Official Journal C series",
321
+ 'E': "EFTA documents",
322
  }
323
 
324
 
325
  class SuperEurlexConfig(datasets.BuilderConfig):
326
  """BuilderConfig for SuperGLUE."""
327
 
328
+ def __init__(self, sector, language, feature_version, features, citation, url, **kwargs):
329
  """BuilderConfig for SuperGLUE.
330
 
331
  Args:
 
338
  url: *string*, url for information about the data set.
339
  **kwargs: keyword arguments forwarded to super.
340
  """
341
+ name=sector+'.'+language+('' if feature_version==None else f".{feature_version}")
342
  super().__init__(name=name, version=datasets.Version("0.1.0"), **kwargs)
343
  self.features = features
344
  self.language = language
345
  self.sector = sector
346
+ self.feature_version = str(feature_version)
347
+ self.text_data_url = f"text_data/{language}/{sector}_{'clean' if feature_version is None else feature_version}.parquet"
348
  self.meta_data_url = f"meta_data/{sector}.parquet"
349
  self.citation = citation
350
  self.url = url
 
367
  SuperEurlexConfig(#version=VERSION,
368
  sector=sect,
369
  language=lang,
370
+ feature_version=version,
371
  description=SECTOR_DESCRIPTIONS[sect],
372
+ features=AVAILABLE_FEATURES[sect+("" if version is None else f"_{version}")],
373
  citation=_CITATION,
374
  url=_HOMEPAGE)
375
+ for lang in AVAILABLE_LANGUAGES for sect in SECTORS for version in VERSIONS
376
  ]
377
 
378
  #DEFAULT_CONFIG_NAME = "3.DE" # It's not mandatory to have a default configuration. Just use one if it make sense.
379
 
380
  def _info(self):
381
  # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
382
+ v = "" if self.config.feature_version=="None" else "_"+self.config.feature_version
383
+ features = AVAILABLE_FEATURES[self.config.sector+v]
384
  info = datasets.DatasetInfo(
385
  # This is the description that will appear on the datasets page.
386
  description=_DESCRIPTION,
 
448
  print(sys.argv[0])
449
  for sector in SECTORS:
450
  for lang in AVAILABLE_LANGUAGES:
451
+ for version in VERSIONS:
452
+ v = "" if version is None else f".{version}"
453
+ print(f'{sector}.{lang}{v}')
454
+
455
+ try:
456
+ dataset = ds.load_dataset(sys.argv[0],f'{sector}.{lang}{v}')
457
+ print(dataset)
458
+ print('\n')
459
+ except Exception as e:
460
+ # Handle the exception
461
+ print("An error occurred: " + str(e.with_traceback(None)))
462
+ print(f"\n{sector}.{lang} Couldn't be loaded\n")