Update bc7_litcovid based on git version 5e9947b
Browse files- bc7_litcovid.py +24 -18
bc7_litcovid.py
CHANGED
@@ -18,11 +18,9 @@ from typing import Dict, List, Tuple
|
|
18 |
import datasets
|
19 |
import pandas as pd
|
20 |
|
21 |
-
from .bigbiohub import text_features
|
22 |
-
from .bigbiohub import BigBioConfig
|
23 |
-
from .bigbiohub import Tasks
|
24 |
|
25 |
-
_LANGUAGES = [
|
26 |
_PUBMED = True
|
27 |
_LOCAL = False
|
28 |
_CITATION = """\
|
@@ -53,7 +51,7 @@ manually reviewed and articles annotated by in-house models.
|
|
53 |
|
54 |
_HOMEPAGE = "https://biocreative.bioinformatics.udel.edu/tasks/biocreative-vii/track-5/"
|
55 |
|
56 |
-
_LICENSE =
|
57 |
|
58 |
_BASE = "https://ftp.ncbi.nlm.nih.gov/pub/lu/LitCovid/biocreative/BC7-LitCovid-"
|
59 |
|
@@ -80,6 +78,8 @@ _CLASS_NAMES = [
|
|
80 |
"Diagnosis",
|
81 |
]
|
82 |
|
|
|
|
|
83 |
|
84 |
class BC7LitCovidDataset(datasets.GeneratorBasedBuilder):
|
85 |
"""
|
@@ -123,9 +123,7 @@ class BC7LitCovidDataset(datasets.GeneratorBasedBuilder):
|
|
123 |
"pub_type": datasets.Sequence(datasets.Value("string")),
|
124 |
"authors": datasets.Sequence(datasets.Value("string")),
|
125 |
"doi": datasets.Value("string"),
|
126 |
-
"labels": datasets.Sequence(
|
127 |
-
datasets.ClassLabel(names=_CLASS_NAMES)
|
128 |
-
),
|
129 |
}
|
130 |
)
|
131 |
|
@@ -173,6 +171,19 @@ class BC7LitCovidDataset(datasets.GeneratorBasedBuilder):
|
|
173 |
),
|
174 |
]
|
175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
def _generate_examples(self, filepath, split: str) -> Tuple[int, Dict]:
|
177 |
"""Yields examples as (key, example) tuples."""
|
178 |
|
@@ -182,7 +193,8 @@ class BC7LitCovidDataset(datasets.GeneratorBasedBuilder):
|
|
182 |
df = pd.read_csv(filepath, sep=",").astype(str).replace({"nan": None})
|
183 |
|
184 |
for index, e in df.iterrows():
|
185 |
-
|
|
|
186 |
if self.config.schema == "source":
|
187 |
|
188 |
yield idx, {
|
@@ -190,15 +202,9 @@ class BC7LitCovidDataset(datasets.GeneratorBasedBuilder):
|
|
190 |
"journal": e["journal"],
|
191 |
"title": e["title"],
|
192 |
"abstract": e["abstract"],
|
193 |
-
"keywords": e["keywords"].split(";")
|
194 |
-
if e["
|
195 |
-
else [],
|
196 |
-
"pub_type": e["pub_type"].split(";")
|
197 |
-
if e["pub_type"] is not None
|
198 |
-
else [],
|
199 |
-
"authors": e["authors"].split(";")
|
200 |
-
if e["authors"] is not None
|
201 |
-
else [],
|
202 |
"doi": e["doi"],
|
203 |
"labels": e["label"].split(";"),
|
204 |
}
|
|
|
18 |
import datasets
|
19 |
import pandas as pd
|
20 |
|
21 |
+
from .bigbiohub import BigBioConfig, Tasks, text_features
|
|
|
|
|
22 |
|
23 |
+
_LANGUAGES = ["English"]
|
24 |
_PUBMED = True
|
25 |
_LOCAL = False
|
26 |
_CITATION = """\
|
|
|
51 |
|
52 |
_HOMEPAGE = "https://biocreative.bioinformatics.udel.edu/tasks/biocreative-vii/track-5/"
|
53 |
|
54 |
+
_LICENSE = "UNKNOWN"
|
55 |
|
56 |
_BASE = "https://ftp.ncbi.nlm.nih.gov/pub/lu/LitCovid/biocreative/BC7-LitCovid-"
|
57 |
|
|
|
78 |
"Diagnosis",
|
79 |
]
|
80 |
|
81 |
+
logger = datasets.utils.logging.get_logger(__name__)
|
82 |
+
|
83 |
|
84 |
class BC7LitCovidDataset(datasets.GeneratorBasedBuilder):
|
85 |
"""
|
|
|
123 |
"pub_type": datasets.Sequence(datasets.Value("string")),
|
124 |
"authors": datasets.Sequence(datasets.Value("string")),
|
125 |
"doi": datasets.Value("string"),
|
126 |
+
"labels": datasets.Sequence(datasets.ClassLabel(names=_CLASS_NAMES)),
|
|
|
|
|
127 |
}
|
128 |
)
|
129 |
|
|
|
171 |
),
|
172 |
]
|
173 |
|
174 |
+
def _validate_entry(self, e, index) -> bool:
|
175 |
+
"""
|
176 |
+
Validates if an entry has all the required fields
|
177 |
+
"""
|
178 |
+
fields_to_validate = ["pmid", "abstract", "label"]
|
179 |
+
for key in fields_to_validate:
|
180 |
+
if e[key]:
|
181 |
+
continue
|
182 |
+
else:
|
183 |
+
logger.warning(f"Entry {index} missing {key}")
|
184 |
+
return False
|
185 |
+
return True
|
186 |
+
|
187 |
def _generate_examples(self, filepath, split: str) -> Tuple[int, Dict]:
|
188 |
"""Yields examples as (key, example) tuples."""
|
189 |
|
|
|
193 |
df = pd.read_csv(filepath, sep=",").astype(str).replace({"nan": None})
|
194 |
|
195 |
for index, e in df.iterrows():
|
196 |
+
if not self._validate_entry(e, index):
|
197 |
+
continue
|
198 |
if self.config.schema == "source":
|
199 |
|
200 |
yield idx, {
|
|
|
202 |
"journal": e["journal"],
|
203 |
"title": e["title"],
|
204 |
"abstract": e["abstract"],
|
205 |
+
"keywords": e["keywords"].split(";") if e["keywords"] is not None else [],
|
206 |
+
"pub_type": e["pub_type"].split(";") if e["pub_type"] is not None else [],
|
207 |
+
"authors": e["authors"].split(";") if e["authors"] is not None else [],
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
"doi": e["doi"],
|
209 |
"labels": e["label"].split(";"),
|
210 |
}
|