Datasets:

Languages:
Spanish
License:
gabrielaltay commited on
Commit
1071014
1 Parent(s): eabce90

upload hubscripts/ctebmsp_hub.py to hub from bigbio repo

Browse files
Files changed (1) hide show
  1. ctebmsp.py +274 -0
ctebmsp.py ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 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
+
16
+ """
17
+ The Clinical Trials for Evidence-Based Medicine in Spanish (CT-EBM-SP) Corpus
18
+ gathers 1200 texts about clinical trial studies for NER; this resource contains
19
+ 500 abstracts of journal articles about clinical trials and 700 announcements
20
+ of trial protocols (292 173 tokens), with 46 699 annotated entities.
21
+
22
+ Entities were annotated according to the Unified Medical Language System (UMLS)
23
+ semantic groups: anatomy (ANAT), pharmacological and chemical substances (CHEM),
24
+ pathologies (DISO), and lab tests, diagnostic or therapeutic procedures (PROC).
25
+ """
26
+
27
+ from pathlib import Path
28
+ from typing import Dict, List, Tuple
29
+
30
+ import datasets
31
+
32
+ from .bigbiohub import kb_features
33
+ from .bigbiohub import BigBioConfig
34
+ from .bigbiohub import Tasks
35
+
36
+ _LANGUAGES = ['Spanish']
37
+ _PUBMED = True
38
+ _LOCAL = False
39
+ _CITATION = """\
40
+ @article{CampillosLlanos2021,
41
+ author = {Leonardo Campillos-Llanos and
42
+ Ana Valverde-Mateos and
43
+ Adri{\'{a}}n Capllonch-Carri{\'{o}}n and
44
+ Antonio Moreno-Sandoval},
45
+ title = {A clinical trials corpus annotated with {UMLS}
46
+ entities to enhance the access to evidence-based medicine},
47
+ journal = {{BMC} Medical Informatics and Decision Making},
48
+ volume = {21},
49
+ year = {2021},
50
+ url = {https://doi.org/10.1186/s12911-021-01395-z},
51
+ doi = {10.1186/s12911-021-01395-z},
52
+ biburl = {},
53
+ bibsource = {}
54
+ }
55
+ """
56
+
57
+ _DATASETNAME = "ctebmsp"
58
+ _DISPLAYNAME = "CT-EBM-SP"
59
+
60
+ _ABSTRACTS_DESCRIPTION = """\
61
+ The "abstracts" subset of the Clinical Trials for Evidence-Based Medicine in Spanish
62
+ (CT-EBM-SP) corpus contains 500 abstracts of clinical trial studies in Spanish,
63
+ published in journals with a Creative Commons license. Most were downloaded from
64
+ the SciELO repository and free abstracts in PubMed.
65
+
66
+ Abstracts were retrieved with the query:
67
+ Clinical Trial[ptyp] AND “loattrfree full text”[sb] AND “spanish”[la].
68
+
69
+ (Information collected from 10.1186/s12911-021-01395-z)
70
+ """
71
+
72
+ _EUDRACT_DESCRIPTION = """\
73
+ The "abstracts" subset of the Clinical Trials for Evidence-Based Medicine in Spanish
74
+ (CT-EBM-SP) corpus contains 500 abstracts of clinical trial studies in Spanish,
75
+ published in journals with a Creative Commons license. Most were downloaded from
76
+ the SciELO repository and free abstracts in PubMed.
77
+
78
+ Abstracts were retrieved with the query:
79
+ Clinical Trial[ptyp] AND “loattrfree full text”[sb] AND “spanish”[la].
80
+
81
+ (Information collected from 10.1186/s12911-021-01395-z)
82
+ """
83
+
84
+ _DESCRIPTION = {
85
+ "ctebmsp_abstracts": _ABSTRACTS_DESCRIPTION,
86
+ "ctebmsp_eudract": _EUDRACT_DESCRIPTION,
87
+ }
88
+
89
+ _HOMEPAGE = "http://www.lllf.uam.es/ESP/nlpmedterm_en.html"
90
+
91
+ _LICENSE = 'Creative Commons Attribution Non Commercial 4.0 International'
92
+
93
+ _URLS = {
94
+ _DATASETNAME: "http://www.lllf.uam.es/ESP/nlpdata/wp2/CT-EBM-SP.zip",
95
+ }
96
+
97
+ _SUPPORTED_TASKS = [Tasks.NAMED_ENTITY_RECOGNITION]
98
+
99
+ _SOURCE_VERSION = "1.0.0"
100
+ _BIGBIO_VERSION = "1.0.0"
101
+
102
+
103
+ class CTEBMSpDataset(datasets.GeneratorBasedBuilder):
104
+ """A Spanish clinical trials corpus annotated with UMLS entities"""
105
+
106
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
107
+ BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
108
+
109
+ BUILDER_CONFIGS = []
110
+
111
+ for study in ["abstracts", "eudract"]:
112
+ BUILDER_CONFIGS.append(
113
+ BigBioConfig(
114
+ name=f"ctebmsp_{study}_source",
115
+ version=SOURCE_VERSION,
116
+ description=f"CT-EBM-SP {study.capitalize()} source schema",
117
+ schema="source",
118
+ subset_id=f"ctebmsp_{study}",
119
+ )
120
+ )
121
+
122
+ BUILDER_CONFIGS.append(
123
+ BigBioConfig(
124
+ name=f"ctebmsp_{study}_bigbio_kb",
125
+ version=BIGBIO_VERSION,
126
+ description=f"CT-EBM-SP {study.capitalize()} BigBio schema",
127
+ schema="bigbio_kb",
128
+ subset_id=f"ctebmsp_{study}",
129
+ ),
130
+ )
131
+
132
+ DEFAULT_CONFIG_NAME = "ctebmsp_abstracts_source"
133
+
134
+ # Entities from the Unified Medical Language System (UMLS) semantic groups
135
+
136
+ def _info(self) -> datasets.DatasetInfo:
137
+ """
138
+ Provide information about CT-EBM-SP
139
+ """
140
+
141
+ if self.config.schema == "source":
142
+ features = datasets.Features(
143
+ {
144
+ "id": datasets.Value("string"),
145
+ "document_id": datasets.Value("string"),
146
+ "text": datasets.Value("string"),
147
+ "text_bound_annotations": [ # T line in brat, e.g. type or event trigger
148
+ {
149
+ "offsets": datasets.Sequence([datasets.Value("int32")]),
150
+ "text": datasets.Sequence(datasets.Value("string")),
151
+ "type": datasets.Value("string"),
152
+ "id": datasets.Value("string"),
153
+ }
154
+ ],
155
+ "events": [ # E line in brat
156
+ {
157
+ "trigger": datasets.Value(
158
+ "string"
159
+ ), # refers to the text_bound_annotation of the trigger,
160
+ "id": datasets.Value("string"),
161
+ "type": datasets.Value("string"),
162
+ "arguments": datasets.Sequence(
163
+ {
164
+ "role": datasets.Value("string"),
165
+ "ref_id": datasets.Value("string"),
166
+ }
167
+ ),
168
+ }
169
+ ],
170
+ "relations": [ # R line in brat
171
+ {
172
+ "id": datasets.Value("string"),
173
+ "head": {
174
+ "ref_id": datasets.Value("string"),
175
+ "role": datasets.Value("string"),
176
+ },
177
+ "tail": {
178
+ "ref_id": datasets.Value("string"),
179
+ "role": datasets.Value("string"),
180
+ },
181
+ "type": datasets.Value("string"),
182
+ }
183
+ ],
184
+ "equivalences": [ # Equiv line in brat
185
+ {
186
+ "id": datasets.Value("string"),
187
+ "ref_ids": datasets.Sequence(datasets.Value("string")),
188
+ }
189
+ ],
190
+ "attributes": [ # M or A lines in brat
191
+ {
192
+ "id": datasets.Value("string"),
193
+ "type": datasets.Value("string"),
194
+ "ref_id": datasets.Value("string"),
195
+ "value": datasets.Value("string"),
196
+ }
197
+ ],
198
+ "normalizations": [ # N lines in brat
199
+ {
200
+ "id": datasets.Value("string"),
201
+ "type": datasets.Value("string"),
202
+ "ref_id": datasets.Value("string"),
203
+ "resource_name": datasets.Value(
204
+ "string"
205
+ ), # Name of the resource, e.g. "Wikipedia"
206
+ "cuid": datasets.Value(
207
+ "string"
208
+ ), # ID in the resource, e.g. 534366
209
+ "text": datasets.Value(
210
+ "string"
211
+ ), # Human readable description/name of the entity, e.g. "Barack Obama"
212
+ }
213
+ ],
214
+ },
215
+ )
216
+
217
+ elif self.config.schema == "bigbio_kb":
218
+ features = kb_features
219
+
220
+ return datasets.DatasetInfo(
221
+ description=_DESCRIPTION[self.config.subset_id],
222
+ features=features,
223
+ homepage=_HOMEPAGE,
224
+ license=str(_LICENSE),
225
+ citation=_CITATION,
226
+ )
227
+
228
+ def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
229
+ """Returns SplitGenerators."""
230
+
231
+ urls = _URLS[_DATASETNAME]
232
+ data_dir = Path(dl_manager.download_and_extract(urls))
233
+ studies_path = {
234
+ "ctebmsp_abstracts": "abstracts",
235
+ "ctebmsp_eudract": "eudract",
236
+ }
237
+
238
+ study_path = studies_path[self.config.subset_id]
239
+
240
+ return [
241
+ datasets.SplitGenerator(
242
+ name=datasets.Split.TRAIN,
243
+ gen_kwargs={"dir_files": data_dir / "train" / study_path},
244
+ ),
245
+ datasets.SplitGenerator(
246
+ name=datasets.Split.TEST,
247
+ gen_kwargs={"dir_files": data_dir / "test" / study_path},
248
+ ),
249
+ datasets.SplitGenerator(
250
+ name=datasets.Split.VALIDATION,
251
+ gen_kwargs={"dir_files": data_dir / "dev" / study_path},
252
+ ),
253
+ ]
254
+
255
+ def _generate_examples(self, dir_files) -> Tuple[int, Dict]:
256
+ """Yields examples as (key, example) tuples."""
257
+
258
+ txt_files = list(dir_files.glob("*txt"))
259
+
260
+ if self.config.schema == "source":
261
+ for guid, txt_file in enumerate(txt_files):
262
+ example = parsing.parse_brat_file(txt_file)
263
+ example["id"] = str(guid)
264
+ yield guid, example
265
+
266
+ elif self.config.schema == "bigbio_kb":
267
+ for guid, txt_file in enumerate(txt_files):
268
+ example = parsing.brat_parse_to_bigbio_kb(
269
+ parsing.parse_brat_file(txt_file)
270
+ )
271
+ example["id"] = str(guid)
272
+ yield guid, example
273
+ else:
274
+ raise ValueError(f"Invalid config: {self.config.name}")