qanastek commited on
Commit
c2c77b0
·
1 Parent(s): a28d09a

Update MANTRAGSC.py

Browse files
Files changed (1) hide show
  1. MANTRAGSC.py +19 -8
MANTRAGSC.py CHANGED
@@ -93,7 +93,7 @@ class DrBenchmarkConfig(datasets.BuilderConfig):
93
  schema: str = None
94
  subset_id: str = None
95
 
96
- class MANTRAGSC(datasets.GeneratorBasedBuilder):
97
 
98
  SOURCE_VERSION = datasets.Version("1.0.0")
99
 
@@ -116,14 +116,25 @@ class MANTRAGSC(datasets.GeneratorBasedBuilder):
116
 
117
  DEFAULT_CONFIG_NAME = "fr_medline"
118
 
119
- def _info(self) -> datasets.DatasetInfo:
120
 
 
 
 
 
 
 
 
121
  features = datasets.Features(
122
  {
123
  "id": datasets.Value("string"),
124
  "document_id": datasets.Value("string"),
125
  "tokens": [datasets.Value("string")],
126
- "ner_tags": [datasets.Value("string")],
 
 
 
 
127
  }
128
  )
129
 
@@ -135,7 +146,7 @@ class MANTRAGSC(datasets.GeneratorBasedBuilder):
135
  citation=_CITATION,
136
  )
137
 
138
- def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
139
 
140
  data_dir = dl_manager.download_and_extract(_URL)
141
 
@@ -301,8 +312,8 @@ class MANTRAGSC(datasets.GeneratorBasedBuilder):
301
  if a.startswith(prefix):
302
  a = a[len(prefix) :]
303
  return a
304
-
305
- def parse_brat_file(self, txt_file: Path, annotation_file_suffixes: List[str] = None, parse_notes: bool = False) -> Dict:
306
 
307
  example = {}
308
  example["document_id"] = txt_file.with_suffix("").name
@@ -457,7 +468,7 @@ class MANTRAGSC(datasets.GeneratorBasedBuilder):
457
 
458
  return example
459
 
460
- def _generate_examples(self, data_dir: Path, language: str, dataset_type: str, split: str):
461
  """Yields examples as (key, example) tuples."""
462
 
463
  data_dir = data_dir / f"{_LANGUAGES_2[language]}"
@@ -516,7 +527,7 @@ class MANTRAGSC(datasets.GeneratorBasedBuilder):
516
  if identifier in allowed_ids:
517
  yield identifier, r
518
 
519
- def _to_source_example(self, brat_example: Dict) -> Dict:
520
 
521
  source_example = {
522
  "document_id": brat_example["document_id"],
 
93
  schema: str = None
94
  subset_id: str = None
95
 
96
+ class MantraGSC(datasets.GeneratorBasedBuilder):
97
 
98
  SOURCE_VERSION = datasets.Version("1.0.0")
99
 
 
116
 
117
  DEFAULT_CONFIG_NAME = "fr_medline"
118
 
119
+ def _info(self):
120
 
121
+ if self.config.name.find("emea") != 1:
122
+ names = ['O', 'DISO', 'CHEM|PHEN', 'DEVI', 'PHEN', 'PROC', 'OBJC', 'ANAT', 'LIVB', 'CHEM', 'PHYS']
123
+ elif self.config.name.find("medline") != 1:
124
+ names = ['O', 'DISO', 'GEOG', 'DEVI', 'Manufactured Object', 'PHEN', 'PROC', 'Research Device', 'OBJC', 'Mental or Behavioral Dysfunction', 'Research Activity', 'ANAT', 'LIVB', 'CHEM', 'PHYS']
125
+ elif self.config.name.find("patents") != 1:
126
+ names = ['O', 'PROC', 'DISO', 'LIVB', 'PHYS', 'PHEN', 'ANAT', 'OBJC', 'Amino Acid, Peptide, or Protein|Enzyme|Receptor', 'DEVI', 'CHEM']
127
+
128
  features = datasets.Features(
129
  {
130
  "id": datasets.Value("string"),
131
  "document_id": datasets.Value("string"),
132
  "tokens": [datasets.Value("string")],
133
+ "ner_tags": datasets.Sequence(
134
+ datasets.features.ClassLabel(
135
+ names = names,
136
+ )
137
+ ),
138
  }
139
  )
140
 
 
146
  citation=_CITATION,
147
  )
148
 
149
+ def _split_generators(self, dl_manager):
150
 
151
  data_dir = dl_manager.download_and_extract(_URL)
152
 
 
312
  if a.startswith(prefix):
313
  a = a[len(prefix) :]
314
  return a
315
+
316
+ def parse_brat_file(self, txt_file: Path, annotation_file_suffixes: List[str] = None, parse_notes: bool = False):
317
 
318
  example = {}
319
  example["document_id"] = txt_file.with_suffix("").name
 
468
 
469
  return example
470
 
471
+ def _generate_examples(self, data_dir, language, dataset_type, split):
472
  """Yields examples as (key, example) tuples."""
473
 
474
  data_dir = data_dir / f"{_LANGUAGES_2[language]}"
 
527
  if identifier in allowed_ids:
528
  yield identifier, r
529
 
530
+ def _to_source_example(self, brat_example):
531
 
532
  source_example = {
533
  "document_id": brat_example["document_id"],