Busani commited on
Commit
2cafdd0
1 Parent(s): 18ab9e5

Resolved dataset loding script

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. cosuju.py +21 -23
.gitignore CHANGED
@@ -127,3 +127,4 @@ dmypy.json
127
 
128
  # Pyre type checker
129
  .pyre/
 
 
127
 
128
  # Pyre type checker
129
  .pyre/
130
+ cosuju.py.lock
cosuju.py CHANGED
@@ -25,6 +25,7 @@ _DESCRIPTION = """\
25
  Court Summaries and Judgements (CoSuJu)
26
  """
27
 
 
28
  _URL = 'https://github.com/FRTNX/ml-data-scraper/blob/main/dataset/'
29
  _URLS = {
30
  'train': _URL + 'mini-train-v1.0.json'
@@ -63,24 +64,20 @@ class Cosuju(datasets.GeneratorBasedBuilder):
63
  'url': datasets.Value('string'),
64
  'year': datasets.Value('string'),
65
  'update_date': datasets.Value('string'),
66
- 'summary_document': datasets.features.Sequence(
67
- {
68
  'filename': datasets.Value('string'),
69
  'file_url': datasets.Value('string'),
70
  'file_content': datasets.Value('string')
71
- }
72
- ),
73
- 'judgement_document': datasets.features.Sequence(
74
- {
75
- 'filename': datasets.Value('string'),
76
- 'file_url': datasets.Value('string'),
77
- 'file_content': datasets.Value('string')
78
- }
79
- ),
80
- }
81
  ),
82
  supervised_keys=None,
83
- homepage='https://github.com/FRTNX/ml-data-scraper',
84
  citation=_CITATION,
85
  )
86
 
@@ -94,21 +91,22 @@ class Cosuju(datasets.GeneratorBasedBuilder):
94
  def _generate_examples(self, filepath):
95
  """This function returns the examples in the raw (text) form."""
96
  logger.info('generating examples from = %s', filepath)
97
- with open(filepath, encoding="utf-8") as f:
98
- for id_, row in enumerate(f):
99
- data = json.loads(row)
 
100
  result = {
101
- 'id': data['id'],
102
- 'title': data['title'],
103
- 'url': data['url'],
104
- 'year': data['year'],
105
- 'update_date': data['update_date']
106
  }
107
 
108
  # as some court decisions have no summaries, may filter these out in future
109
  for prop in ['summary_document', 'judgement_document']:
110
- if data[prop]:
111
- result[prop] = data[prop]
112
  else:
113
  result[prop] = { 'filename': '', 'file_url': '', 'file_content': '' }
114
 
 
25
  Court Summaries and Judgements (CoSuJu)
26
  """
27
 
28
+ # Redundant but may use in future.
29
  _URL = 'https://github.com/FRTNX/ml-data-scraper/blob/main/dataset/'
30
  _URLS = {
31
  'train': _URL + 'mini-train-v1.0.json'
 
64
  'url': datasets.Value('string'),
65
  'year': datasets.Value('string'),
66
  'update_date': datasets.Value('string'),
67
+ 'summary_document': {
 
68
  'filename': datasets.Value('string'),
69
  'file_url': datasets.Value('string'),
70
  'file_content': datasets.Value('string')
71
+ },
72
+ 'judgement_document': {
73
+ 'filename': datasets.Value('string'),
74
+ 'file_url': datasets.Value('string'),
75
+ 'file_content': datasets.Value('string')
76
+ },
77
+ }
 
 
 
78
  ),
79
  supervised_keys=None,
80
+ homepage='https://huggingface.co/datasets/FRTNX/cosuju',
81
  citation=_CITATION,
82
  )
83
 
 
91
  def _generate_examples(self, filepath):
92
  """This function returns the examples in the raw (text) form."""
93
  logger.info('generating examples from = %s', filepath)
94
+ with open('train-v1.0.json', 'r') as f:
95
+ cosuju = json.loads(f.read())
96
+ for row in cosuju['data']:
97
+ id_ = row['id']
98
  result = {
99
+ 'id': row['id'],
100
+ 'title': row['title'],
101
+ 'url': row['url'],
102
+ 'year': row['year'],
103
+ 'update_date': row['update_date']
104
  }
105
 
106
  # as some court decisions have no summaries, may filter these out in future
107
  for prop in ['summary_document', 'judgement_document']:
108
+ if row[prop]:
109
+ result[prop] = row[prop]
110
  else:
111
  result[prop] = { 'filename': '', 'file_url': '', 'file_content': '' }
112