Datasets:

Languages:
English
ArXiv:
License:
gabrielaltay commited on
Commit
02004b5
1 Parent(s): 12a5412

upload hub_repos/tmvar_v3/tmvar_v3.py to hub from bigbio repo

Browse files
Files changed (1) hide show
  1. tmvar_v3.py +39 -11
tmvar_v3.py CHANGED
@@ -24,9 +24,7 @@ import itertools
24
  import datasets
25
  from bioc import pubtator
26
 
27
- from .bigbiohub import kb_features
28
- from .bigbiohub import BigBioConfig
29
- from .bigbiohub import Tasks
30
 
31
  _CITATION = """\
32
  @misc{https://doi.org/10.48550/arxiv.2204.03637,
@@ -47,7 +45,7 @@ _CITATION = """\
47
  }
48
 
49
  """
50
- _LANGUAGES = ['English']
51
  _PUBMED = True
52
  _LOCAL = False
53
 
@@ -64,7 +62,7 @@ NED tasks, This dataset does NOT have splits.
64
 
65
  _HOMEPAGE = "https://www.ncbi.nlm.nih.gov/research/bionlp/Tools/tmvar/"
66
 
67
- _LICENSE = 'License information unavailable'
68
 
69
  _URLS = {_DATASETNAME: "ftp://ftp.ncbi.nlm.nih.gov/pub/lu/tmVar3/tmVar3Corpus.txt"}
70
  _SUPPORTED_TASKS = [Tasks.NAMED_ENTITY_RECOGNITION, Tasks.NAMED_ENTITY_DISAMBIGUATION]
@@ -75,7 +73,8 @@ logger = datasets.utils.logging.get_logger(__name__)
75
 
76
  class TmvarV3Dataset(datasets.GeneratorBasedBuilder):
77
  """
78
- This dataset contains 500 PubMed articles manually annotated with mutation mentions of various kinds and various normalizations for each of them.
 
79
  """
80
 
81
  DEFAULT_CONFIG_NAME = "tmvar_v3_source"
@@ -124,9 +123,7 @@ class TmvarV3Dataset(datasets.GeneratorBasedBuilder):
124
  {
125
  "text": datasets.Sequence(datasets.Value("string")),
126
  "offsets": datasets.Sequence([datasets.Value("int32")]),
127
- "semantic_type_id": datasets.Sequence(
128
- datasets.Value("string")
129
- ),
130
  "normalized": {
131
  key: datasets.Sequence(datasets.Value("string"))
132
  for key in type_to_db_mapping.keys()
@@ -205,6 +202,31 @@ class TmvarV3Dataset(datasets.GeneratorBasedBuilder):
205
  continue
206
  return base_dict
207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  def pubtator_to_source(self, filepath):
209
  """
210
  Converts pubtator to source schema
@@ -227,7 +249,7 @@ class TmvarV3Dataset(datasets.GeneratorBasedBuilder):
227
  {
228
  "offsets": [[mention.start, mention.end]],
229
  "text": [mention.text],
230
- "semantic_type_id": [mention.type],
231
  "normalized": self.get_normalizations(
232
  mention.id,
233
  mention.type,
@@ -236,6 +258,9 @@ class TmvarV3Dataset(datasets.GeneratorBasedBuilder):
236
  }
237
  for mention in doc.annotations
238
  ]
 
 
 
239
  yield document
240
 
241
  def pubtator_to_bigbio_kb(self, filepath):
@@ -269,13 +294,16 @@ class TmvarV3Dataset(datasets.GeneratorBasedBuilder):
269
  "id": next(uid),
270
  "offsets": [[mention.start, mention.end]],
271
  "text": [mention.text],
272
- "type": [mention.type],
273
  "normalized": self.get_normalizations(
274
  mention.id, mention.type, doc.pmid
275
  ),
276
  }
277
  for mention in doc.annotations
278
  ]
 
 
 
279
  db_id_mapping = {
280
  "dbSNP": "dbSNP",
281
  "CorrespondingGene": "NCBI Gene",
 
24
  import datasets
25
  from bioc import pubtator
26
 
27
+ from .bigbiohub import BigBioConfig, Tasks, kb_features
 
 
28
 
29
  _CITATION = """\
30
  @misc{https://doi.org/10.48550/arxiv.2204.03637,
 
45
  }
46
 
47
  """
48
+ _LANGUAGES = ["English"]
49
  _PUBMED = True
50
  _LOCAL = False
51
 
 
62
 
63
  _HOMEPAGE = "https://www.ncbi.nlm.nih.gov/research/bionlp/Tools/tmvar/"
64
 
65
+ _LICENSE = "License information unavailable"
66
 
67
  _URLS = {_DATASETNAME: "ftp://ftp.ncbi.nlm.nih.gov/pub/lu/tmVar3/tmVar3Corpus.txt"}
68
  _SUPPORTED_TASKS = [Tasks.NAMED_ENTITY_RECOGNITION, Tasks.NAMED_ENTITY_DISAMBIGUATION]
 
73
 
74
  class TmvarV3Dataset(datasets.GeneratorBasedBuilder):
75
  """
76
+ This dataset contains 500 PubMed articles manually annotated with mutation
77
+ mentions of various kinds and various normalizations for each of them.
78
  """
79
 
80
  DEFAULT_CONFIG_NAME = "tmvar_v3_source"
 
123
  {
124
  "text": datasets.Sequence(datasets.Value("string")),
125
  "offsets": datasets.Sequence([datasets.Value("int32")]),
126
+ "semantic_type_id": datasets.Value("string"),
 
 
127
  "normalized": {
128
  key: datasets.Sequence(datasets.Value("string"))
129
  for key in type_to_db_mapping.keys()
 
202
  continue
203
  return base_dict
204
 
205
+ def _correct_wrong_offsets(self, entities, pmid):
206
+ """
207
+ Offsets in the document 21904390 is wrong. Correct them manually.
208
+ """
209
+ wrong_offsets = {
210
+ "21904390": {
211
+ (343, 347): [342, 346],
212
+ (753, 757): [751, 755],
213
+ (1156, 1160): [1153, 1157],
214
+ (1487, 1491): [1483, 1487],
215
+ (1631, 1635): [1627, 1631],
216
+ (1645, 1659): [1640, 1654],
217
+ (2043, 2047): [2037, 2041],
218
+ }
219
+ }
220
+ if pmid in wrong_offsets:
221
+ for entity in entities:
222
+ if (entity["offsets"][0][0], entity["offsets"][0][1]) in wrong_offsets[
223
+ pmid
224
+ ]:
225
+ entity["offsets"][0] = wrong_offsets[pmid][
226
+ (entity["offsets"][0][0], entity["offsets"][0][1])
227
+ ]
228
+ return entities
229
+
230
  def pubtator_to_source(self, filepath):
231
  """
232
  Converts pubtator to source schema
 
249
  {
250
  "offsets": [[mention.start, mention.end]],
251
  "text": [mention.text],
252
+ "semantic_type_id": mention.type,
253
  "normalized": self.get_normalizations(
254
  mention.id,
255
  mention.type,
 
258
  }
259
  for mention in doc.annotations
260
  ]
261
+ document["entities"] = self._correct_wrong_offsets(
262
+ document["entities"], doc.pmid
263
+ )
264
  yield document
265
 
266
  def pubtator_to_bigbio_kb(self, filepath):
 
294
  "id": next(uid),
295
  "offsets": [[mention.start, mention.end]],
296
  "text": [mention.text],
297
+ "type": mention.type,
298
  "normalized": self.get_normalizations(
299
  mention.id, mention.type, doc.pmid
300
  ),
301
  }
302
  for mention in doc.annotations
303
  ]
304
+ document["entities"] = self._correct_wrong_offsets(
305
+ document["entities"], doc.pmid
306
+ )
307
  db_id_mapping = {
308
  "dbSNP": "dbSNP",
309
  "CorrespondingGene": "NCBI Gene",