vr commited on
Commit
adbb6b9
1 Parent(s): 9c8b91d

loading script and two subsets

Browse files
swiss_citation_extraction.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """Dataset for the Citation Extraction task."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import lzma
21
+ import os
22
+
23
+ import datasets
24
+ try:
25
+ import lzma as xz
26
+ except ImportError:
27
+ import pylzma as xz
28
+
29
+
30
+ # TODO: Add BibTeX citation
31
+ # Find for instance the citation on arxiv or on the dataset repo/website
32
+ _CITATION = """\
33
+ @InProceedings{huggingface:dataset,
34
+ title = {A great new dataset},
35
+ author={huggingface, Inc.
36
+ },
37
+ year={2020}
38
+ }
39
+ """
40
+
41
+ # You can copy an official description
42
+ _DESCRIPTION = """\
43
+ This dataset contains court decision for cit ex task.
44
+ """
45
+
46
+ # TODO: Add a link to an official homepage for the dataset here
47
+ _HOMEPAGE = ""
48
+
49
+ # TODO: Add the licence for the dataset here if you can find it
50
+ _LICENSE = ""
51
+
52
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
53
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
54
+ _URLS = {
55
+ "original": "https://huggingface.co/datasets/rcds/swiss_citation_extraction/resolve/main/original/huggingface",
56
+ "with_rules": "https://huggingface.co/datasets/rcds/swiss_citation_extraction/resolve/main/with_rules/huggingface"
57
+ }
58
+
59
+
60
+ class SwissCourtViewGeneration(datasets.GeneratorBasedBuilder):
61
+ """This dataset contains court decision for court view generation task."""
62
+
63
+ VERSION = datasets.Version("1.1.0")
64
+
65
+ # This is an example of a dataset with multiple configurations.
66
+ # If you don't want/need to define several sub-sets in your dataset,
67
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
68
+
69
+ # If you need to make complex sub-parts in the datasets with configurable options
70
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
71
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
72
+
73
+ # You will be able to load one or the other configurations in the following list with
74
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
75
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
76
+ BUILDER_CONFIGS = [
77
+ datasets.BuilderConfig(name="full", version=VERSION, description="This part of my dataset covers the whole dataset"),
78
+ datasets.BuilderConfig(name="origin", version=VERSION, description="This part of my dataset covers a subset containing only cases with origin data")
79
+ ]
80
+
81
+ DEFAULT_CONFIG_NAME = "full" # It's not mandatory to have a default configuration. Just use one if it make sense.
82
+
83
+ def _info(self):
84
+ if self.config.name == "original" or self.config.name == "with_rules": # This is the name of the configuration selected in BUILDER_CONFIGS above
85
+ features = datasets.Features(
86
+ {
87
+ "decision_id": datasets.Value("string"),
88
+ "considerations": datasets.Value("sequence"),
89
+ "NER_labels": datasets.Value("sequence"),
90
+ "law_area": datasets.Value("string"),
91
+ "language": datasets.Value("string"),
92
+ "year": datasets.Value("int64"),
93
+ "chamber": datasets.Value("string"),
94
+ "region": datasets.Value("string")
95
+
96
+ # These are the features of your dataset like images, labels ...
97
+ }
98
+ )
99
+ return datasets.DatasetInfo(
100
+ # This is the description that will appear on the datasets page.
101
+ description=_DESCRIPTION,
102
+ # This defines the different columns of the dataset and their types
103
+ features=features, # Here we define them above because they are different between the two configurations
104
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
105
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
106
+ # supervised_keys=("sentence", "label"),
107
+ # Homepage of the dataset for documentation
108
+ # homepage=_HOMEPAGE,
109
+ # License for the dataset if available
110
+ # license=_LICENSE,
111
+ # Citation for the dataset
112
+ # citation=_CITATION,
113
+ )
114
+
115
+ def _split_generators(self, dl_manager):
116
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
117
+
118
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
119
+ # 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.
120
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
121
+ urls = _URLS[self.config.name]
122
+ filepath_train = dl_manager.download(os.path.join(urls, "train.jsonl.xz"))
123
+ filepath_validation = dl_manager.download(os.path.join(urls, "validation.jsonl.xz"))
124
+ filepath_test = dl_manager.download(os.path.join(urls, "test.jsonl.xz"))
125
+
126
+ return [
127
+ datasets.SplitGenerator(
128
+ name=datasets.Split.TRAIN,
129
+ # These kwargs will be passed to _generate_examples
130
+ gen_kwargs={
131
+ "filepath": filepath_train,
132
+ "split": "train",
133
+ },
134
+ ),
135
+ datasets.SplitGenerator(
136
+ name=datasets.Split.VALIDATION,
137
+ # These kwargs will be passed to _generate_examples
138
+ gen_kwargs={
139
+ "filepath": filepath_validation,
140
+ "split": "validation",
141
+ },
142
+ ),
143
+ datasets.SplitGenerator(
144
+ name=datasets.Split.TEST,
145
+ # These kwargs will be passed to _generate_examples
146
+ gen_kwargs={
147
+ "filepath": filepath_test,
148
+ "split": "test"
149
+ },
150
+ )
151
+ ]
152
+
153
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
154
+ def _generate_examples(self, filepath, split):
155
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
156
+ line_counter = 0
157
+ try:
158
+ with xz.open(open(filepath, "rb"), "rt", encoding="utf-8") as f:
159
+ for id, line in enumerate(f):
160
+ line_counter += 1
161
+ if line:
162
+ data = json.loads(line)
163
+ if self.config.name == "original" or self.config.name == "with_rules":
164
+ yield id, {
165
+ "decision_id": data["decision_id"],
166
+ "considerations": data["considerations"],
167
+ "NER_labels": data["NER_labels"],
168
+ "law_area": data["law_area"],
169
+ "language": data["language"],
170
+ "year": data["year"],
171
+ "chamber": data["chamber"],
172
+ "region": data["region"]
173
+ }
174
+ except lzma.LZMAError as e:
175
+ print(split, e)
176
+ if line_counter == 0:
177
+ raise e
test.jsonl.xz → with_rules/test.jsonl.xz RENAMED
File without changes
train.jsonl.xz → with_rules/train.jsonl.xz RENAMED
File without changes
validation.jsonl.xz → with_rules/validation.jsonl.xz RENAMED
File without changes