gabrielaltay commited on
Commit
79fcf80
1 Parent(s): fc44e8b

upload hubscripts/quaero_hub.py to hub from bigbio repo

Browse files
Files changed (1) hide show
  1. quaero.py +218 -0
quaero.py ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from pathlib import Path
3
+
4
+ import datasets
5
+
6
+ from .bigbiohub import kb_features
7
+ from .bigbiohub import BigBioConfig
8
+ from .bigbiohub import Tasks
9
+
10
+ _LANGUAGES = ['French']
11
+ _PUBMED = True
12
+ _LOCAL = False
13
+ _CITATION = """\
14
+ @InProceedings{neveol14quaero,
15
+ author = {Névéol, Aurélie and Grouin, Cyril and Leixa, Jeremy
16
+ and Rosset, Sophie and Zweigenbaum, Pierre},
17
+ title = {The {QUAERO} {French} Medical Corpus: A Ressource for
18
+ Medical Entity Recognition and Normalization},
19
+ OPTbooktitle = {Proceedings of the Fourth Workshop on Building
20
+ and Evaluating Ressources for Health and Biomedical
21
+ Text Processing},
22
+ booktitle = {Proc of BioTextMining Work},
23
+ OPTseries = {BioTxtM 2014},
24
+ year = {2014},
25
+ pages = {24--30},
26
+ }
27
+ """
28
+
29
+ _DESCRIPTION = """\
30
+ The QUAERO French Medical Corpus has been initially developed as a resource for named entity recognition and normalization [1]. It was then improved with the purpose of creating a gold standard set of normalized entities for French biomedical text, that was used in the CLEF eHealth evaluation lab [2][3].
31
+
32
+ A selection of MEDLINE titles and EMEA documents were manually annotated. The annotation process was guided by concepts in the Unified Medical Language System (UMLS):
33
+
34
+ 1. Ten types of clinical entities, as defined by the following UMLS Semantic Groups (Bodenreider and McCray 2003) were annotated: Anatomy, Chemical and Drugs, Devices, Disorders, Geographic Areas, Living Beings, Objects, Phenomena, Physiology, Procedures.
35
+
36
+ 2. The annotations were made in a comprehensive fashion, so that nested entities were marked, and entities could be mapped to more than one UMLS concept. In particular: (a) If a mention can refer to more than one Semantic Group, all the relevant Semantic Groups should be annotated. For instance, the mention “récidive” (recurrence) in the phrase “prévention des récidives” (recurrence prevention) should be annotated with the category “DISORDER” (CUI C2825055) and the category “PHENOMENON” (CUI C0034897); (b) If a mention can refer to more than one UMLS concept within the same Semantic Group, all the relevant concepts should be annotated. For instance, the mention “maniaques” (obsessive) in the phrase “patients maniaques” (obsessive patients) should be annotated with CUIs C0564408 and C0338831 (category “DISORDER”); (c) Entities which span overlaps with that of another entity should still be annotated. For instance, in the phrase “infarctus du myocarde” (myocardial infarction), the mention “myocarde” (myocardium) should be annotated with category “ANATOMY” (CUI C0027061) and the mention “infarctus du myocarde” should be annotated with category “DISORDER” (CUI C0027051)
37
+
38
+ The QUAERO French Medical Corpus BioC release comprises a subset of the QUAERO French Medical corpus, as follows:
39
+
40
+ Training data (BRAT version used in CLEF eHealth 2015 task 1b as training data):
41
+ - MEDLINE_train_bioc file: 833 MEDLINE titles, annotated with normalized entities in the BioC format
42
+ - EMEA_train_bioc file: 3 EMEA documents, segmented into 11 sub-documents, annotated with normalized entities in the BioC format
43
+
44
+ Development data (BRAT version used in CLEF eHealth 2015 task 1b as test data and in CLEF eHealth 2016 task 2 as development data):
45
+ - MEDLINE_dev_bioc file: 832 MEDLINE titles, annotated with normalized entities in the BioC format
46
+ - EMEA_dev_bioc file: 3 EMEA documents, segmented into 12 sub-documents, annotated with normalized entities in the BioC format
47
+
48
+ Test data (BRAT version used in CLEF eHealth 2016 task 2 as test data):
49
+ - MEDLINE_test_bioc folder: 833 MEDLINE titles, annotated with normalized entities in the BioC format
50
+ - EMEA folder_test_bioc: 4 EMEA documents, segmented into 15 sub-documents, annotated with normalized entities in the BioC format
51
+
52
+
53
+
54
+ This release of the QUAERO French medical corpus, BioC version, comes in the BioC format, through automatic conversion from the original BRAT format obtained with the Brat2BioC tool https://bitbucket.org/nicta_biomed/brat2bioc developped by Jimeno Yepes et al.
55
+
56
+ Antonio Jimeno Yepes, Mariana Neves, Karin Verspoor
57
+ Brat2BioC: conversion tool between brat and BioC
58
+ BioCreative IV track 1 - BioC: The BioCreative Interoperability Initiative, 2013
59
+
60
+
61
+ Please note that the original version of the QUAERO corpus distributed in the CLEF eHealth challenge 2015 and 2016 came in the BRAT stand alone format. It was distributed with the CLEF eHealth evaluation tool. This original distribution of the QUAERO French Medical corpus is available separately from https://quaerofrenchmed.limsi.fr
62
+
63
+ All questions regarding the task or data should be addressed to aurelie.neveol@limsi.fr
64
+ """
65
+
66
+ _HOMEPAGE = "https://quaerofrenchmed.limsi.fr/"
67
+
68
+ _LICENSE = 'GNU Free Documentation License v1.3'
69
+
70
+ _URL = "https://quaerofrenchmed.limsi.fr/QUAERO_FrenchMed_brat.zip"
71
+
72
+ _DATASET_NAME = "quaero"
73
+ _DISPLAYNAME = "QUAERO"
74
+
75
+ _SUPPORTED_TASKS = [Tasks.NAMED_ENTITY_RECOGNITION, Tasks.NAMED_ENTITY_DISAMBIGUATION]
76
+ _SOURCE_VERSION = "1.0.0"
77
+ _BIGBIO_VERSION = "1.0.0"
78
+
79
+
80
+ class QUAERO(datasets.GeneratorBasedBuilder):
81
+
82
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
83
+ BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
84
+
85
+ BUILDER_CONFIGS = [
86
+ BigBioConfig(
87
+ name="quaero_emea_source",
88
+ version=SOURCE_VERSION,
89
+ description="QUAERO source schema on the EMEA subset",
90
+ schema="source",
91
+ subset_id="quaero_emea",
92
+ ),
93
+ BigBioConfig(
94
+ name="quaero_medline_source",
95
+ version=SOURCE_VERSION,
96
+ description="QUAERO source schema on the MEDLINE subset",
97
+ schema="source",
98
+ subset_id="quaero_medline",
99
+ ),
100
+ BigBioConfig(
101
+ name="quaero_emea_bigbio_kb",
102
+ version=BIGBIO_VERSION,
103
+ description="QUAERO simplified BigBio schema on the EMEA subset",
104
+ schema="bigbio_kb",
105
+ subset_id="quaero_emea",
106
+ ),
107
+ BigBioConfig(
108
+ name="quaero_medline_bigbio_kb",
109
+ version=BIGBIO_VERSION,
110
+ description="QUAERO simplified BigBio schema on the MEDLINE subset",
111
+ schema="bigbio_kb",
112
+ subset_id="quaero_medline",
113
+ ),
114
+ ]
115
+
116
+ def _info(self):
117
+ if self.config.schema == "source":
118
+ features = datasets.Features(
119
+ {
120
+ "id": datasets.Value("string"),
121
+ "document_id": datasets.Value("string"),
122
+ "text": datasets.Value("string"),
123
+ "text_bound_annotations": [ # T line in brat, e.g. type or event trigger
124
+ {
125
+ "offsets": datasets.Sequence([datasets.Value("int32")]),
126
+ "text": datasets.Sequence(datasets.Value("string")),
127
+ "type": datasets.Value("string"),
128
+ "id": datasets.Value("string"),
129
+ }
130
+ ],
131
+ "notes": [ # # lines in brat
132
+ {
133
+ "id": datasets.Value("string"),
134
+ "type": datasets.Value("string"),
135
+ "ref_id": datasets.Value("string"),
136
+ "text": datasets.Value("string"),
137
+ }
138
+ ],
139
+ }
140
+ )
141
+ elif self.config.schema == "bigbio_kb":
142
+ features = kb_features
143
+
144
+ return datasets.DatasetInfo(
145
+ description=_DESCRIPTION,
146
+ features=features,
147
+ supervised_keys=None,
148
+ homepage=_HOMEPAGE,
149
+ license=str(_LICENSE),
150
+ citation=_CITATION,
151
+ )
152
+
153
+ def _split_generators(self, dl_manager):
154
+ urls = _URL
155
+ data_dir = dl_manager.download_and_extract(urls)
156
+ return [
157
+ datasets.SplitGenerator(
158
+ name=datasets.Split.TRAIN,
159
+ # These kwargs will be passed to _generate_examples
160
+ gen_kwargs={
161
+ "filepath": data_dir,
162
+ "split": "train",
163
+ },
164
+ ),
165
+ datasets.SplitGenerator(
166
+ name=datasets.Split.TEST,
167
+ # These kwargs will be passed to _generate_examples
168
+ gen_kwargs={"filepath": data_dir, "split": "test"},
169
+ ),
170
+ datasets.SplitGenerator(
171
+ name=datasets.Split.VALIDATION,
172
+ # These kwargs will be passed to _generate_examples
173
+ gen_kwargs={
174
+ "filepath": data_dir,
175
+ "split": "dev",
176
+ },
177
+ ),
178
+ ]
179
+
180
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
181
+ def _generate_examples(self, filepath, split):
182
+ if self.config.subset_id == "quaero_emea":
183
+ subset = "EMEA"
184
+ elif self.config.subset_id == "quaero_medline":
185
+ subset = "MEDLINE"
186
+
187
+ folder = Path(filepath) / "QUAERO_FrenchMed" / "corpus" / split / subset
188
+
189
+ if self.config.schema == "source":
190
+ for guid, txt_file in enumerate(sorted(folder.glob("*.txt"))):
191
+ example = parse_brat_file(txt_file, parse_notes=True)
192
+ example["id"] = guid
193
+ # Remove unused items from BRAT
194
+ del example["events"]
195
+ del example["relations"]
196
+ del example["equivalences"]
197
+ del example["attributes"]
198
+ del example["normalizations"]
199
+ yield guid, example
200
+ elif self.config.schema == "bigbio_kb":
201
+ for guid, txt_file in enumerate(sorted(folder.glob("*.txt"))):
202
+ example = parse_brat_file(txt_file, parse_notes=True)
203
+ annotator_notes = example["notes"]
204
+ document_id = example["document_id"]
205
+
206
+ example = brat_parse_to_bigbio_kb(example)
207
+ example["id"] = guid
208
+
209
+ for note in annotator_notes:
210
+ entity_id = f'{document_id}_{note["ref_id"]}'
211
+ for e in example["entities"]:
212
+ if e["id"] == entity_id:
213
+ for cui in re.split("[\s\+,]", note["text"].strip()):
214
+ if cui:
215
+ e["normalized"].append({"db_id": cui, "db_name": "UMLS"})
216
+ yield guid, example
217
+ else:
218
+ raise ValueError(f"Invalid config: {self.config.name}")