qanastek commited on
Commit
41a857c
·
1 Parent(s): f35684a

Upload DiaMed.py

Browse files
Files changed (1) hide show
  1. DiaMed.py +164 -0
DiaMed.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
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
+ """DIAMED"""
16
+
17
+ import os
18
+ import json
19
+ import math
20
+
21
+ import datasets
22
+
23
+ _DESCRIPTION = """\
24
+ DIAMED
25
+ """
26
+
27
+ _HOMEPAGE = ""
28
+
29
+ _LICENSE = "Apache License 2.0"
30
+
31
+ _URL = "https://huggingface.co/datasets/DiaMED/DiaMED/resolve/main/data.zip"
32
+
33
+ _CITATION = """\
34
+
35
+ """
36
+
37
+ class DiaMed(datasets.GeneratorBasedBuilder):
38
+ """DIAMED"""
39
+
40
+ VERSION = datasets.Version("1.0.0")
41
+
42
+ def _info(self):
43
+
44
+ features = datasets.Features(
45
+ {
46
+ "identifier": datasets.Value("string"),
47
+ "title": datasets.Value("string"),
48
+ "clinical_case": datasets.Value("string"),
49
+ "topic": datasets.Value("string"),
50
+ "keywords": datasets.Sequence(
51
+ datasets.Value("string"),
52
+ ),
53
+ "domains": datasets.Sequence(
54
+ datasets.Value("string"),
55
+ ),
56
+ "collected_at": datasets.Value("string"),
57
+ "published_at": datasets.Value("string"),
58
+ "source_url": datasets.Value("string"),
59
+ "source_name": datasets.Value("string"),
60
+ "license": datasets.Value("string"),
61
+ "figures_urls": datasets.Sequence(
62
+ datasets.Value("string"),
63
+ ),
64
+ "figures_paths": datasets.Sequence(
65
+ datasets.Value("string"),
66
+ ),
67
+ "figures": datasets.Sequence(
68
+ datasets.Image(),
69
+ ),
70
+ "icd-10": datasets.features.ClassLabel(names=[
71
+ 'A00-B99 Certain infectious and parasitic diseases',
72
+ 'C00-D49 Neoplasms',
73
+ 'D50-D89 Diseases of the blood and blood-forming organs and certain disorders involving the immune mechanism',
74
+ 'E00-E89 Endocrine, nutritional and metabolic diseases',
75
+ 'F01-F99 Mental, Behavioral and Neurodevelopmental disorders',
76
+ 'G00-G99 Diseases of the nervous system',
77
+ 'H00-H59 Diseases of the eye and adnexa',
78
+ 'H60-H95 Diseases of the ear and mastoid process',
79
+ 'I00-I99 Diseases of the circulatory system',
80
+ 'J00-J99 Diseases of the respiratory system',
81
+ 'K00-K95 Diseases of the digestive system',
82
+ 'L00-L99 Diseases of the skin and subcutaneous tissue',
83
+ 'M00-M99 Diseases of the musculoskeletal system and connective tissue',
84
+ 'N00-N99 Diseases of the genitourinary system',
85
+ 'O00-O9A Pregnancy, childbirth and the puerperium',
86
+ 'P00-P96 Certain conditions originating in the perinatal period',
87
+ 'Q00-Q99 Congenital malformations, deformations and chromosomal abnormalities',
88
+ 'R00-R99 Symptoms, signs and abnormal clinical and laboratory findings, not elsewhere classified',
89
+ 'S00-T88 Injury, poisoning and certain other consequences of external causes',
90
+ 'U00-U85 Codes for special purposes',
91
+ 'V00-Y99 External causes of morbidity',
92
+ 'Z00-Z99 Factors influencing health status and contact with health services',
93
+ ]),
94
+ }
95
+ )
96
+
97
+ return datasets.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
+ """Returns SplitGenerators."""
107
+
108
+ data_dir = dl_manager.download_and_extract(_URL)
109
+ print("#"*50)
110
+ print(data_dir)
111
+ # data_dir = "./splits/"
112
+
113
+ return [
114
+ datasets.SplitGenerator(
115
+ name=datasets.Split.TRAIN,
116
+ gen_kwargs={
117
+ "base_path": data_dir,
118
+ "filepath": data_dir + "/splits/train.json",
119
+ },
120
+ ),
121
+ datasets.SplitGenerator(
122
+ name=datasets.Split.VALIDATION,
123
+ gen_kwargs={
124
+ "base_path": data_dir,
125
+ "filepath": data_dir + "/splits/validation.json",
126
+ },
127
+ ),
128
+ datasets.SplitGenerator(
129
+ name=datasets.Split.TEST,
130
+ gen_kwargs={
131
+ "base_path": data_dir,
132
+ "filepath": data_dir + "/splits/test.json",
133
+ },
134
+ ),
135
+ ]
136
+
137
+ def _generate_examples(self, base_path, filepath):
138
+
139
+ with open(filepath, encoding="utf-8") as f:
140
+
141
+ data = json.load(f)
142
+
143
+ for key, d in enumerate(data):
144
+
145
+ if str(d["icd-10"]) == "nan" or d["icd-10"].find("Plusieurs cas cliniques") != -1 or d["icd-10"].find("Aucune annotation") != -1:
146
+ continue
147
+
148
+ yield key, {
149
+ "identifier": d["identifier"],
150
+ "title": d["title"],
151
+ "clinical_case": d["clinical_case"],
152
+ "topic": d["topic"],
153
+ "keywords": d["keywords"],
154
+ "domains": d["domain"],
155
+ "collected_at": d["collected_at"],
156
+ "published_at": d["published_at"],
157
+ "source_url": d["source_url"],
158
+ "source_name": d["source_name"],
159
+ "license": d["license"],
160
+ "figures_urls": d["figures"],
161
+ "figures": [base_path + fg.lstrip(".") for fg in d["local_figures"]],
162
+ "figures_paths": [base_path + fg.lstrip(".") for fg in d["local_figures"]],
163
+ "icd-10": d["icd-10"],
164
+ }