Rodekool commited on
Commit
7a02a00
1 Parent(s): 2ea6d06

Create ornl.py

Browse files
Files changed (1) hide show
  1. ornl.py +80 -0
ornl.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace NLP Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """Open Data Rechtspraak dutch topic classification dataset."""
18
+
19
+ from __future__ import absolute_import, division, print_function
20
+
21
+ import csv
22
+ import os
23
+
24
+ import nlp
25
+
26
+
27
+ _DESCRIPTION = """\
28
+ still a WIP, Dataset originally comes from Open Data van de Rechtspraak"
29
+ """
30
+
31
+ _TRAIN_DOWNLOAD_URL = "https://huggingface.co/datasets/Rodekool/ornl/resolve/main/train.csv"
32
+ _TEST_DOWNLOAD_URL = "https://huggingface.co/datasets/Rodekool/ornl/resolve/main/test.csv"
33
+
34
+
35
+ class ORnl(nlp.GeneratorBasedBuilder):
36
+ """Open Data van de Rechtspraak dutch topic classification dataset."""
37
+
38
+ def _info(self):
39
+ return nlp.DatasetInfo(
40
+ description=_DESCRIPTION,
41
+ features=nlp.Features(
42
+ {
43
+ "text": nlp.Value("string"),
44
+ "label": nlp.features.ClassLabel(names=['Ambtenarenrecht', 'Arbeidsrecht', 'Belastingrecht', 'Omgevingsrecht', 'Personen- en familierecht', 'Socialezekerheidsrecht', 'Verbintenissenrecht', 'Vreemdelingenrecht']),
45
+ }
46
+ ),
47
+ homepage="https://www.rechtspraak.nl/Uitspraken/paginas/open-data.aspx",
48
+ )
49
+
50
+ def _split_generators(self, dl_manager):
51
+ train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL)
52
+ test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
53
+ return [
54
+ nlp.SplitGenerator(name=nlp.Split.TRAIN, gen_kwargs={"filepath": train_path}),
55
+ nlp.SplitGenerator(name=nlp.Split.TEST, gen_kwargs={"filepath": test_path}),
56
+ ]
57
+
58
+ def _generate_examples(self, filepath):
59
+ """Generate Rechtspraak examples."""
60
+ with open(filepath, encoding="utf-8") as csv_file:
61
+ csv_reader = csv.reader(
62
+ csv_file, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True
63
+ )
64
+ for id_, row in enumerate(csv_reader):
65
+ label, title, description = row
66
+
67
+ # Original labels are [1, 2, 3, 4, 5, 6, 7, 8] ->
68
+ # ['Ambtenarenrecht',
69
+ # 'Arbeidsrecht',
70
+ # 'Belastingrecht',
71
+ # 'Omgevingsrecht',
72
+ # 'Personen- en familierecht',
73
+ # 'Socialezekerheidsrecht',
74
+ # 'Verbintenissenrecht',
75
+ # 'Vreemdelingenrecht']
76
+ # Re-map to [0, 1, 2, 3, 4, 5, 6, 7].
77
+
78
+ label = int(label) - 1
79
+ text = " ".join((title, description))
80
+ yield id_, {"text": text, "label": label}