Datasets:
rcds
/

Modalities:
Text
ArXiv:
Libraries:
Datasets
License:
Stern5497 commited on
Commit
cdef3c5
1 Parent(s): 316f9b7

Create swiss_criticality_prediction.py

Browse files
Files changed (1) hide show
  1. swiss_criticality_prediction.py +166 -0
swiss_criticality_prediction.py ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Dataset for the Legal Criticality Prediction task."""
15
+
16
+ import json
17
+ import lzma
18
+ import os
19
+
20
+ import datasets
21
+ try:
22
+ import lzma as xz
23
+ except ImportError:
24
+ import pylzma as xz
25
+
26
+
27
+ # TODO: Add BibTeX citation
28
+ # Find for instance the citation on arxiv or on the dataset repo/website
29
+ _CITATION = """\
30
+ @InProceedings{huggingface:dataset,
31
+ title = {A great new dataset},
32
+ author={huggingface, Inc.
33
+ },
34
+ year={2020}
35
+ }
36
+ """
37
+
38
+ # You can copy an official description
39
+ _DESCRIPTION = """\
40
+ This dataset contains Swiss federal court decisions for the legal criticality prediction task
41
+ """
42
+
43
+ _URLS = {
44
+ "full": "https://huggingface.co/datasets/rcds/swiss_criticality_prediction/resolve/main/data",
45
+ }
46
+
47
+
48
+ class SwissCriticalityPrediction(datasets.GeneratorBasedBuilder):
49
+ """This dataset contains court decision for court view generation task."""
50
+
51
+
52
+ BUILDER_CONFIGS = [
53
+ datasets.BuilderConfig(name="full", description="This part covers the whole dataset"),
54
+ ]
55
+
56
+ DEFAULT_CONFIG_NAME = "full" # It's not mandatory to have a default configuration. Just use one if it make sense.
57
+
58
+ def _info(self):
59
+ if self.config.name == "full": # This is the name of the configuration selected in BUILDER_CONFIGS above
60
+ features = datasets.Features(
61
+ {
62
+ # Todo check if these are all
63
+ "decision_id": datasets.Value("string"),
64
+ "language": datasets.Value("string"),
65
+ "year": datasets.Value("int32"),
66
+ "chamber": datasets.Value("string"),
67
+ "region": datasets.Value("string"),
68
+ "origin_chamber": datasets.Value("string"),
69
+ "origin_court": datasets.Value("string"),
70
+ "origin_canton": datasets.Value("string"),
71
+ "law_area": datasets.Value("string"),
72
+ "law_sub_area": datasets.Value("string"),
73
+ "bge_label": datasets.Value("string"),
74
+ "citation_label": datasets.Value("string"),
75
+ "facts": datasets.Value("string"),
76
+ "considerations": datasets.Value("string"),
77
+ "rulings": datasets.Value("string"),
78
+ # These are the features of your dataset like images, labels ...
79
+ }
80
+ )
81
+ return datasets.DatasetInfo(
82
+ # This is the description that will appear on the datasets page.
83
+ description=_DESCRIPTION,
84
+ # This defines the different columns of the dataset and their types
85
+ features=features, # Here we define them above because they are different between the two configurations
86
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
87
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
88
+ # supervised_keys=("sentence", "label"),
89
+ # Homepage of the dataset for documentation
90
+ # homepage=_HOMEPAGE,
91
+ # License for the dataset if available
92
+ # license=_LICENSE,
93
+ # Citation for the dataset
94
+ # citation=_CITATION,
95
+ )
96
+
97
+ def _split_generators(self, dl_manager):
98
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
99
+
100
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
101
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
102
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
103
+ urls = _URLS[self.config.name]
104
+ filepath_train = dl_manager.download(os.path.join(urls, "train.jsonl.xz"))
105
+ filepath_validation = dl_manager.download(os.path.join(urls, "validation.jsonl.xz"))
106
+ filepath_test = dl_manager.download(os.path.join(urls, "test.jsonl.xz"))
107
+
108
+ return [
109
+ datasets.SplitGenerator(
110
+ name=datasets.Split.TRAIN,
111
+ # These kwargs will be passed to _generate_examples
112
+ gen_kwargs={
113
+ "filepath": filepath_train,
114
+ "split": "train",
115
+ },
116
+ ),
117
+ datasets.SplitGenerator(
118
+ name=datasets.Split.VALIDATION,
119
+ # These kwargs will be passed to _generate_examples
120
+ gen_kwargs={
121
+ "filepath": filepath_validation,
122
+ "split": "validation",
123
+ },
124
+ ),
125
+ datasets.SplitGenerator(
126
+ name=datasets.Split.TEST,
127
+ # These kwargs will be passed to _generate_examples
128
+ gen_kwargs={
129
+ "filepath": filepath_test,
130
+ "split": "test"
131
+ },
132
+ )
133
+ ]
134
+
135
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
136
+ def _generate_examples(self, filepath, split):
137
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
138
+ line_counter = 0
139
+ try:
140
+ with xz.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
141
+ for id, line in enumerate(f):
142
+ line_counter += 1
143
+ if line:
144
+ data = json.loads(line)
145
+ if self.config.name == "full":
146
+ yield id, {
147
+ "decision_id": data["decision_id"],
148
+ "language": data["language"],
149
+ "year": data["year"],
150
+ "chamber": data["chamber"],
151
+ "region": data["region"],
152
+ "origin_chamber": data["origin_chamber"],
153
+ "origin_court": data["origin_court"],
154
+ "origin_canton": data["origin_canton"],
155
+ "law_area": data["law_area"],
156
+ "law_sub_area": data["law_sub_area"],
157
+ "citation_label": data["citation_label"],
158
+ "bge_label": data["bge_label"],
159
+ "facts": data["facts"],
160
+ "considerations": data["considerations"],
161
+ "rulings": data["rulings"],
162
+ }
163
+ except lzma.LZMAError as e:
164
+ print(split, e)
165
+ if line_counter == 0:
166
+ raise e