Datasets:

Modalities:
Text
Languages:
English
Size:
< 1K
Libraries:
Datasets
License:
gabrielaltay commited on
Commit
6b2d457
1 Parent(s): c4415f6

upload hubscripts/genia_ptm_event_corpus_hub.py to hub from bigbio repo

Browse files
Files changed (1) hide show
  1. genia_ptm_event_corpus.py +209 -0
genia_ptm_event_corpus.py ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Post-translational-modifications (PTM), amino acid modifications of proteins after translation, are one of the posterior
18
+ processes of protein biosynthesis for many proteins, and they are critical for determining protein function such as its
19
+ activity state, localization, turnover and interactions with other biomolecules. While there have been many studies of
20
+ information extraction targeting individual PTM types, there was until recently little effort to address extraction of
21
+ multiple PTM types at once in a unified framework.
22
+ """
23
+
24
+ import os
25
+ from pathlib import Path
26
+ from typing import Dict, List, Tuple
27
+
28
+ import datasets
29
+
30
+ from .bigbiohub import kb_features
31
+ from .bigbiohub import BigBioConfig
32
+ from .bigbiohub import Tasks
33
+
34
+ _LANGUAGES = ['English']
35
+ _PUBMED = True
36
+ _LOCAL = False
37
+ _CITATION = """\
38
+ @inproceedings{ohta-etal-2010-event,
39
+ title = "Event Extraction for Post-Translational Modifications",
40
+ author = "Ohta, Tomoko and
41
+ Pyysalo, Sampo and
42
+ Miwa, Makoto and
43
+ Kim, Jin-Dong and
44
+ Tsujii, Jun{'}ichi",
45
+ booktitle = "Proceedings of the 2010 Workshop on Biomedical Natural Language Processing",
46
+ month = jul,
47
+ year = "2010",
48
+ address = "Uppsala, Sweden",
49
+ publisher = "Association for Computational Linguistics",
50
+ url = "https://aclanthology.org/W10-1903",
51
+ pages = "19--27",
52
+ }
53
+ """
54
+
55
+ _DATASETNAME = "genia_ptm_event_corpus"
56
+ _DISPLAYNAME = "PTM Events"
57
+
58
+ _DESCRIPTION = """\
59
+ Post-translational-modifications (PTM), amino acid modifications of proteins \
60
+ after translation, are one of the posterior processes of protein biosynthesis \
61
+ for many proteins, and they are critical for determining protein function such \
62
+ as its activity state, localization, turnover and interactions with other \
63
+ biomolecules. While there have been many studies of information extraction \
64
+ targeting individual PTM types, there was until recently little effort to \
65
+ address extraction of multiple PTM types at once in a unified framework.
66
+ """
67
+
68
+ _HOMEPAGE = "http://www.geniaproject.org/other-corpora/ptm-event-corpus"
69
+
70
+ _LICENSE = 'GENIA Project License for Annotated Corpora'
71
+
72
+
73
+ _URLS = {
74
+ _DATASETNAME: "http://www.geniaproject.org/other-corpora/ptm-event-corpus/post-translational_modifications_training_data.tar.gz?attredirects=0&d=1",
75
+ }
76
+
77
+ _SUPPORTED_TASKS = [
78
+ Tasks.NAMED_ENTITY_RECOGNITION,
79
+ Tasks.COREFERENCE_RESOLUTION,
80
+ Tasks.EVENT_EXTRACTION,
81
+ ]
82
+
83
+ _SOURCE_VERSION = "1.0.0"
84
+
85
+ _BIGBIO_VERSION = "1.0.0"
86
+
87
+
88
+ class GeniaPtmEventCorpusDataset(datasets.GeneratorBasedBuilder):
89
+ """GENIA PTM event corpus."""
90
+
91
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
92
+ BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
93
+
94
+ BUILDER_CONFIGS = [
95
+ BigBioConfig(
96
+ name="genia_ptm_event_corpus_source",
97
+ version=SOURCE_VERSION,
98
+ description="genia_ptm_event_corpus source schema",
99
+ schema="source",
100
+ subset_id="genia_ptm_event_corpus",
101
+ ),
102
+ BigBioConfig(
103
+ name="genia_ptm_event_corpus_bigbio_kb",
104
+ version=BIGBIO_VERSION,
105
+ description="genia_ptm_event_corpus BigBio schema",
106
+ schema="bigbio_kb",
107
+ subset_id="genia_ptm_event_corpus",
108
+ ),
109
+ ]
110
+
111
+ DEFAULT_CONFIG_NAME = "genia_ptm_event_corpus_source"
112
+
113
+ def _info(self) -> datasets.DatasetInfo:
114
+ if self.config.schema == "source":
115
+ features = datasets.Features(
116
+ {
117
+ "id": datasets.Value("string"),
118
+ "document_id": datasets.Value("string"),
119
+ "text": datasets.Value("string"),
120
+ "text_bound_annotations": [ # T line in brat, e.g. type or event trigger
121
+ {
122
+ "offsets": datasets.Sequence([datasets.Value("int32")]),
123
+ "text": datasets.Sequence(datasets.Value("string")),
124
+ "type": datasets.Value("string"),
125
+ "id": datasets.Value("string"),
126
+ }
127
+ ],
128
+ "events": [ # E line in brat
129
+ {
130
+ "id": datasets.Value("string"),
131
+ "type": datasets.Value(
132
+ "string"
133
+ ), # refers to the text_bound_annotation of the trigger
134
+ "trigger": datasets.Value("string"),
135
+ "arguments": [
136
+ {
137
+ "role": datasets.Value("string"),
138
+ "ref_id": datasets.Value("string"),
139
+ }
140
+ ],
141
+ }
142
+ ],
143
+ "relations": [ # R line in brat
144
+ {
145
+ "id": datasets.Value("string"),
146
+ "head": {
147
+ "ref_id": datasets.Value("string"),
148
+ "role": datasets.Value("string"),
149
+ },
150
+ "tail": {
151
+ "ref_id": datasets.Value("string"),
152
+ "role": datasets.Value("string"),
153
+ },
154
+ "type": datasets.Value("string"),
155
+ }
156
+ ],
157
+ "equivalences": [ # Equiv line in brat
158
+ {
159
+ "id": datasets.Value("string"),
160
+ "ref_ids": datasets.Sequence(datasets.Value("string")),
161
+ }
162
+ ],
163
+ },
164
+ )
165
+
166
+ elif self.config.schema == "bigbio_kb":
167
+ features = kb_features
168
+
169
+ return datasets.DatasetInfo(
170
+ description=_DESCRIPTION,
171
+ features=features,
172
+ homepage=_HOMEPAGE,
173
+ license=str(_LICENSE),
174
+ citation=_CITATION,
175
+ )
176
+
177
+ def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
178
+ """Returns SplitGenerators."""
179
+ urls = _URLS[_DATASETNAME]
180
+ data_dir = dl_manager.download_and_extract(urls)
181
+ return [
182
+ datasets.SplitGenerator(
183
+ name=datasets.Split.TRAIN,
184
+ gen_kwargs={
185
+ "data_dir": data_dir,
186
+ },
187
+ ),
188
+ ]
189
+
190
+ def _generate_examples(self, data_dir) -> Tuple[int, Dict]:
191
+ """Yields examples as (key, example) tuples."""
192
+ for dirpath, _, filenames in os.walk(data_dir):
193
+ for guid, filename in enumerate(filenames):
194
+ if filename.endswith(".txt"):
195
+ txt_file_path = Path(dirpath, filename)
196
+ if self.config.schema == "source":
197
+ example = parsing.parse_brat_file(
198
+ txt_file_path, annotation_file_suffixes=[".a1", ".a2"]
199
+ )
200
+ example["id"] = str(guid)
201
+ for key in ["attributes", "normalizations"]:
202
+ del example[key]
203
+ yield guid, example
204
+ elif self.config.schema == "bigbio_kb":
205
+ example = parsing.brat_parse_to_bigbio_kb(
206
+ parsing.parse_brat_file(txt_file_path)
207
+ )
208
+ example["id"] = str(guid)
209
+ yield guid, example