Upload e3c.py
Browse files
e3c.py
CHANGED
|
@@ -1,18 +1,19 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
|
| 3 |
import datasets
|
| 4 |
-
from bs4 import
|
| 5 |
from datasets import DownloadManager
|
| 6 |
|
| 7 |
_CITATION = """\
|
| 8 |
@report{Magnini2021,
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
}
|
| 17 |
|
| 18 |
"""
|
|
@@ -29,14 +30,13 @@ _URL = "https://github.com/hltfbk/E3C-Corpus/archive/refs/tags/v2.0.0.zip"
|
|
| 29 |
|
| 30 |
|
| 31 |
class E3CConfig(datasets.BuilderConfig):
|
| 32 |
-
"""BuilderConfig for
|
| 33 |
|
| 34 |
def __init__(self, **kwargs):
|
| 35 |
-
"""BuilderConfig for
|
| 36 |
Args:
|
| 37 |
**kwargs: keyword arguments forwarded to super.
|
| 38 |
"""
|
| 39 |
-
self.layer = kwargs.pop("layer")
|
| 40 |
super(E3CConfig, self).__init__(**kwargs)
|
| 41 |
|
| 42 |
|
|
@@ -44,34 +44,9 @@ class E3C(datasets.GeneratorBasedBuilder):
|
|
| 44 |
VERSION = datasets.Version("1.1.0")
|
| 45 |
BUILDER_CONFIGS = [
|
| 46 |
E3CConfig(
|
| 47 |
-
name="
|
| 48 |
version=VERSION,
|
| 49 |
description="this is the split of the layer 1 for English of E3C dataset",
|
| 50 |
-
layer="1",
|
| 51 |
-
),
|
| 52 |
-
E3CConfig(
|
| 53 |
-
name="es",
|
| 54 |
-
version=VERSION,
|
| 55 |
-
description="this is the split of the layer 1 for Spanish of E3C dataset",
|
| 56 |
-
layer="1",
|
| 57 |
-
),
|
| 58 |
-
E3CConfig(
|
| 59 |
-
name="eu",
|
| 60 |
-
version=VERSION,
|
| 61 |
-
description="this is the split of the layer 1 for Basque of E3C dataset",
|
| 62 |
-
layer="1",
|
| 63 |
-
),
|
| 64 |
-
E3CConfig(
|
| 65 |
-
name="fr",
|
| 66 |
-
version=VERSION,
|
| 67 |
-
description="this is the split of the layer 1 for French of E3C dataset",
|
| 68 |
-
layer="1",
|
| 69 |
-
),
|
| 70 |
-
E3CConfig(
|
| 71 |
-
name="it",
|
| 72 |
-
version=VERSION,
|
| 73 |
-
description="this is the split of the layer 1 for Italian of E3C dataset",
|
| 74 |
-
layer="1",
|
| 75 |
),
|
| 76 |
]
|
| 77 |
|
|
@@ -118,22 +93,115 @@ class E3C(datasets.GeneratorBasedBuilder):
|
|
| 118 |
"""
|
| 119 |
url = _URL
|
| 120 |
data_dir = dl_manager.download_and_extract(url)
|
| 121 |
-
|
| 122 |
-
"en": "English",
|
| 123 |
-
"es": "Spanish",
|
| 124 |
-
"eu": "Basque",
|
| 125 |
-
"fr": "French",
|
| 126 |
-
"it": "Italian",
|
| 127 |
-
}[self.config.name]
|
| 128 |
return [
|
| 129 |
datasets.SplitGenerator(
|
| 130 |
-
name=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
gen_kwargs={
|
| 132 |
"filepath": os.path.join(
|
| 133 |
data_dir,
|
| 134 |
"E3C-Corpus-2.0.0/data_annotation",
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
),
|
| 138 |
},
|
| 139 |
),
|
|
@@ -190,7 +258,7 @@ class E3C(datasets.GeneratorBasedBuilder):
|
|
| 190 |
"TOKENS": self.get_annotations(soup.find_all("type4:Token"), text),
|
| 191 |
}
|
| 192 |
|
| 193 |
-
def _generate_examples(self, filepath) ->
|
| 194 |
"""Yields examples as (key, example) tuples.
|
| 195 |
Args:
|
| 196 |
filepath: The path to the folder containing the files to parse.
|
|
@@ -233,8 +301,8 @@ class E3C(datasets.GeneratorBasedBuilder):
|
|
| 233 |
labels[idx_token] = f"{entity_type}"
|
| 234 |
else:
|
| 235 |
labels[idx_token] = f"{entity_type}"
|
| 236 |
-
guid += 1
|
| 237 |
yield guid, {
|
| 238 |
"tokens": list(map(lambda tokens: tokens[2], filtered_tokens)),
|
| 239 |
"ner_tags": labels,
|
| 240 |
}
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
from typing import Iterator
|
| 3 |
|
| 4 |
import datasets
|
| 5 |
+
from bs4 import BeautifulSoup, ResultSet
|
| 6 |
from datasets import DownloadManager
|
| 7 |
|
| 8 |
_CITATION = """\
|
| 9 |
@report{Magnini2021,
|
| 10 |
+
author = {Bernardo Magnini and Begoña Altuna and Alberto Lavelli and Manuela Speranza
|
| 11 |
+
and Roberto Zanoli and Fondazione Bruno Kessler},
|
| 12 |
+
keywords = {Clinical data,clinical enti-ties,corpus,multilingual,temporal information},
|
| 13 |
+
title = {The E3C Project:
|
| 14 |
+
European Clinical Case Corpus El proyecto E3C: European Clinical Case Corpus},
|
| 15 |
+
url = {https://uts.nlm.nih.gov/uts/umls/home},
|
| 16 |
+
year = {2021},
|
| 17 |
}
|
| 18 |
|
| 19 |
"""
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
class E3CConfig(datasets.BuilderConfig):
|
| 33 |
+
"""BuilderConfig for NCBIDisease"""
|
| 34 |
|
| 35 |
def __init__(self, **kwargs):
|
| 36 |
+
"""BuilderConfig for NCBIDisease.
|
| 37 |
Args:
|
| 38 |
**kwargs: keyword arguments forwarded to super.
|
| 39 |
"""
|
|
|
|
| 40 |
super(E3CConfig, self).__init__(**kwargs)
|
| 41 |
|
| 42 |
|
|
|
|
| 44 |
VERSION = datasets.Version("1.1.0")
|
| 45 |
BUILDER_CONFIGS = [
|
| 46 |
E3CConfig(
|
| 47 |
+
name="e3c",
|
| 48 |
version=VERSION,
|
| 49 |
description="this is the split of the layer 1 for English of E3C dataset",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
),
|
| 51 |
]
|
| 52 |
|
|
|
|
| 93 |
"""
|
| 94 |
url = _URL
|
| 95 |
data_dir = dl_manager.download_and_extract(url)
|
| 96 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
return [
|
| 98 |
datasets.SplitGenerator(
|
| 99 |
+
name="en.layer1",
|
| 100 |
+
gen_kwargs={
|
| 101 |
+
"filepath": os.path.join(
|
| 102 |
+
data_dir,
|
| 103 |
+
"E3C-Corpus-2.0.0/data_annotation",
|
| 104 |
+
"English",
|
| 105 |
+
"layer1",
|
| 106 |
+
),
|
| 107 |
+
},
|
| 108 |
+
),
|
| 109 |
+
datasets.SplitGenerator(
|
| 110 |
+
name="en.layer2",
|
| 111 |
+
gen_kwargs={
|
| 112 |
+
"filepath": os.path.join(
|
| 113 |
+
data_dir,
|
| 114 |
+
"E3C-Corpus-2.0.0/data_annotation",
|
| 115 |
+
"English",
|
| 116 |
+
"layer2",
|
| 117 |
+
),
|
| 118 |
+
},
|
| 119 |
+
),
|
| 120 |
+
datasets.SplitGenerator(
|
| 121 |
+
name="es.layer1",
|
| 122 |
+
gen_kwargs={
|
| 123 |
+
"filepath": os.path.join(
|
| 124 |
+
data_dir,
|
| 125 |
+
"E3C-Corpus-2.0.0/data_annotation",
|
| 126 |
+
"Spanish",
|
| 127 |
+
"layer1",
|
| 128 |
+
),
|
| 129 |
+
},
|
| 130 |
+
),
|
| 131 |
+
datasets.SplitGenerator(
|
| 132 |
+
name="es.layer2",
|
| 133 |
gen_kwargs={
|
| 134 |
"filepath": os.path.join(
|
| 135 |
data_dir,
|
| 136 |
"E3C-Corpus-2.0.0/data_annotation",
|
| 137 |
+
"Spanish",
|
| 138 |
+
"layer2",
|
| 139 |
+
),
|
| 140 |
+
},
|
| 141 |
+
),
|
| 142 |
+
datasets.SplitGenerator(
|
| 143 |
+
name="eu.layer1",
|
| 144 |
+
gen_kwargs={
|
| 145 |
+
"filepath": os.path.join(
|
| 146 |
+
data_dir,
|
| 147 |
+
"E3C-Corpus-2.0.0/data_annotation",
|
| 148 |
+
"Basque",
|
| 149 |
+
"layer1",
|
| 150 |
+
),
|
| 151 |
+
},
|
| 152 |
+
),
|
| 153 |
+
datasets.SplitGenerator(
|
| 154 |
+
name="eu.layer2",
|
| 155 |
+
gen_kwargs={
|
| 156 |
+
"filepath": os.path.join(
|
| 157 |
+
data_dir,
|
| 158 |
+
"E3C-Corpus-2.0.0/data_annotation",
|
| 159 |
+
"Basque",
|
| 160 |
+
"layer2",
|
| 161 |
+
),
|
| 162 |
+
},
|
| 163 |
+
),
|
| 164 |
+
datasets.SplitGenerator(
|
| 165 |
+
name="fr.layer1",
|
| 166 |
+
gen_kwargs={
|
| 167 |
+
"filepath": os.path.join(
|
| 168 |
+
data_dir,
|
| 169 |
+
"E3C-Corpus-2.0.0/data_annotation",
|
| 170 |
+
"French",
|
| 171 |
+
"layer1",
|
| 172 |
+
),
|
| 173 |
+
},
|
| 174 |
+
),
|
| 175 |
+
datasets.SplitGenerator(
|
| 176 |
+
name="fr.layer2",
|
| 177 |
+
gen_kwargs={
|
| 178 |
+
"filepath": os.path.join(
|
| 179 |
+
data_dir,
|
| 180 |
+
"E3C-Corpus-2.0.0/data_annotation",
|
| 181 |
+
"French",
|
| 182 |
+
"layer2",
|
| 183 |
+
),
|
| 184 |
+
},
|
| 185 |
+
),
|
| 186 |
+
datasets.SplitGenerator(
|
| 187 |
+
name="it.layer1",
|
| 188 |
+
gen_kwargs={
|
| 189 |
+
"filepath": os.path.join(
|
| 190 |
+
data_dir,
|
| 191 |
+
"E3C-Corpus-2.0.0/data_annotation",
|
| 192 |
+
"Italian",
|
| 193 |
+
"layer1",
|
| 194 |
+
),
|
| 195 |
+
},
|
| 196 |
+
),
|
| 197 |
+
datasets.SplitGenerator(
|
| 198 |
+
name="it.layer2",
|
| 199 |
+
gen_kwargs={
|
| 200 |
+
"filepath": os.path.join(
|
| 201 |
+
data_dir,
|
| 202 |
+
"E3C-Corpus-2.0.0/data_annotation",
|
| 203 |
+
"Italian",
|
| 204 |
+
"layer2",
|
| 205 |
),
|
| 206 |
},
|
| 207 |
),
|
|
|
|
| 258 |
"TOKENS": self.get_annotations(soup.find_all("type4:Token"), text),
|
| 259 |
}
|
| 260 |
|
| 261 |
+
def _generate_examples(self, filepath) -> Iterator:
|
| 262 |
"""Yields examples as (key, example) tuples.
|
| 263 |
Args:
|
| 264 |
filepath: The path to the folder containing the files to parse.
|
|
|
|
| 301 |
labels[idx_token] = f"{entity_type}"
|
| 302 |
else:
|
| 303 |
labels[idx_token] = f"{entity_type}"
|
|
|
|
| 304 |
yield guid, {
|
| 305 |
"tokens": list(map(lambda tokens: tokens[2], filtered_tokens)),
|
| 306 |
"ner_tags": labels,
|
| 307 |
}
|
| 308 |
+
guid += 1
|