Datasets:

Languages:
Japanese
Size:
n<1K
Tags:
legal
Not-For-All-Audiences
License:
p1atdev commited on
Commit
9e724af
·
1 Parent(s): bfa5334

Create JEDHRI.py

Browse files
Files changed (1) hide show
  1. JEDHRI.py +148 -0
JEDHRI.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """Japanese Expressions Dataset from Human Rights Infringement on Internet"""
15
+
16
+
17
+ import json
18
+
19
+ import datasets as ds
20
+
21
+
22
+ # Find for instance the citation on arxiv or on the dataset repo/website
23
+ _CITATION = """\
24
+ @dataset{hisada_shohei_2023_7960519,
25
+ author = {HISADA, Shohei},
26
+ title = {{Japanese Expressions Dataset from Human Rights
27
+ Infringement on Internet}},
28
+ month = jun,
29
+ year = 2023,
30
+ publisher = {Zenodo},
31
+ version = {0.2},
32
+ doi = {10.5281/zenodo.7960519},
33
+ url = {https://doi.org/10.5281/zenodo.7960519}
34
+ }
35
+ """
36
+
37
+ # You can copy an official description
38
+ _DESCRIPTION = """\
39
+ Japanese Expressions Dataset from Human Rights Infringement on Internet
40
+ """
41
+
42
+ _HOMEPAGE = "https://zenodo.org/record/7960519"
43
+
44
+ _LICENSE = "CC-BY-4.0"
45
+
46
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
47
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
48
+ _URLS = {
49
+ "v0.2": "https://zenodo.org/record/7960519/files/Expressions_Infringement_human_rights_v02.jsonl"
50
+ }
51
+
52
+ _FEATURE_MAP = {
53
+ "1: Text in Dispute": "text",
54
+ "2: Context Utilized in Adjudication": "context",
55
+ "3-1a: The types of Allegedly Infringed Right 1": "right_type_1",
56
+ "3-1b: Judgement on the Infringement Allegation 1": "judgement_1",
57
+ "3-2a: The types of Allegedly Infringed Right 1": "right_type_2",
58
+ "3-2b: Judgement on the Infringement Allegation 2": "judgement_2",
59
+ "5-3: Bibliography": "bibliography",
60
+ "5-1: Case Number": "case_number",
61
+ "5-2: Case Name": "case_name",
62
+ "5-4: Article Number": "article_number",
63
+ "5-5: Online Platform": "platform",
64
+ }
65
+
66
+
67
+ class JEDHRIDataset(ds.GeneratorBasedBuilder):
68
+ """Japanese Expressions Dataset from Human Rights Infringement on Internet."""
69
+
70
+ VERSION = ds.Version("v0.2")
71
+
72
+ BUILDER_CONFIGS = [
73
+ ds.BuilderConfig(
74
+ name="v0.2",
75
+ version=VERSION,
76
+ ),
77
+ ]
78
+
79
+ DEFAULT_CONFIG_NAME = "v0.2"
80
+
81
+ def _info(self):
82
+ features = ds.Features(
83
+ {
84
+ "text": ds.Value("string"),
85
+ "context": ds.Value("string"),
86
+ "platform": ds.Value("string"),
87
+ "right_type_1": ds.Value("string"),
88
+ "judgement_1": ds.Value("bool"),
89
+ "right_type_2": ds.Value("string"),
90
+ "judgement_2": ds.Value("bool"),
91
+ "bibliography": ds.Sequence(ds.Value("string")),
92
+ "case_number": ds.Value("string"),
93
+ "case_name": ds.Value("string"),
94
+ "article_number": ds.Value("string"),
95
+ }
96
+ )
97
+ return ds.DatasetInfo(
98
+ description=_DESCRIPTION,
99
+ features=features,
100
+ homepage=_HOMEPAGE,
101
+ license=_LICENSE,
102
+ citation=_CITATION,
103
+ )
104
+
105
+ def _split_generators(self, dl_manager):
106
+ url = _URLS[self.config.name]
107
+
108
+ if type(url) is not str:
109
+ raise ValueError("url must be a string")
110
+
111
+ data_dir = dl_manager.download(url)
112
+
113
+ return [
114
+ ds.SplitGenerator(
115
+ name=ds.Split.TRAIN,
116
+ # These kwargs will be passed to _generate_examples
117
+ gen_kwargs={
118
+ "filepath": data_dir,
119
+ "split": "train",
120
+ },
121
+ ),
122
+ ]
123
+
124
+ def _generate_examples(self, filepath, split):
125
+ # read json for each line
126
+ with open(filepath, encoding="utf-8") as f:
127
+ for id_, row in enumerate(f):
128
+ data = json.loads(row)
129
+ # rename keys
130
+ data = {v: data[k] for k, v in _FEATURE_MAP.items()}
131
+
132
+ for key in ["right_type_1", "right_type_2"]:
133
+ if data[key] == "":
134
+ data[key] = None
135
+
136
+ for key in ["judgement_1", "judgement_2"]:
137
+ if data[key] == "":
138
+ data[key] = None
139
+ elif data[key] == "0":
140
+ data[key] = False
141
+ elif data[key] == "1":
142
+ data[key] = True
143
+
144
+ data["bibliography"] = [
145
+ x for x in str(data["bibliography"]).split("\n") if x != ""
146
+ ]
147
+
148
+ yield id_, data