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""British Library EThos dataset"""
|
| 3 |
+
|
| 4 |
+
import csv
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
import datasets
|
| 7 |
+
from datasets.features import Features
|
| 8 |
+
from datasets.tasks import LanguageModeling
|
| 9 |
+
|
| 10 |
+
_CITATION = """\
|
| 11 |
+
@misc{british library_genre,
|
| 12 |
+
title={UK Doctoral Thesis Metadata from EThOS},
|
| 13 |
+
url={UK Doctoral Thesis Metadata from EThOS},
|
| 14 |
+
author={{British Library} and {Rosie, Heather}},
|
| 15 |
+
year={2021}}
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
_DESCRIPTION = """\
|
| 20 |
+
The data in this collection comprises the bibliographic metadata for all UK doctoral theses listed in EThOS, the UK's national thesis service.
|
| 21 |
+
We estimate the data covers around 98% of all PhDs ever awarded by UK Higher Education institutions, dating back to 1787.
|
| 22 |
+
Thesis metadata from every PhD-awarding university in the UK is included.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
_HOMEPAGE = "https://doi.org/10.23636/ybpt-nh33"
|
| 27 |
+
_LICENSE = "CC BY 4.0 Attribution"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
_URL = "https://bl.iro.bl.uk/downloads/3043a513-72af-4fad-864d-1da5ee1e8ed1?locale=en"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
features = Features(
|
| 34 |
+
{
|
| 35 |
+
"Title": datasets.Value("string"),
|
| 36 |
+
"DOI": datasets.Value("string"),
|
| 37 |
+
"Author": datasets.Value("string"),
|
| 38 |
+
"Author ISNI": datasets.Value("string"),
|
| 39 |
+
"ORCID": datasets.Value("string"),
|
| 40 |
+
"Institution": datasets.Value("string"),
|
| 41 |
+
"Institution ISNI": datasets.Value("string"),
|
| 42 |
+
"Date": datasets.Value("timestamp[s]"),
|
| 43 |
+
"Qualification": datasets.Value("string"),
|
| 44 |
+
"Abstract": datasets.Value("string"),
|
| 45 |
+
"Subject Discipline": datasets.ClassLabel(
|
| 46 |
+
names=[
|
| 47 |
+
"Physical Sciences",
|
| 48 |
+
"Biological Sciences",
|
| 49 |
+
"Engineering & Technology",
|
| 50 |
+
"Mathematics & Statistics",
|
| 51 |
+
"Agriculture & Veterinary Sciences",
|
| 52 |
+
"Medicine & Health",
|
| 53 |
+
"Computer Science",
|
| 54 |
+
"Philosophy, Psychology & Religious Studies",
|
| 55 |
+
"Business & Administrative Studies",
|
| 56 |
+
"Education",
|
| 57 |
+
"Language & Literature",
|
| 58 |
+
"Social, Economic & Political Studies",
|
| 59 |
+
"Architecture, Building & Planning",
|
| 60 |
+
"History & Archaeology",
|
| 61 |
+
"Creative Arts & Design",
|
| 62 |
+
"Law",
|
| 63 |
+
"Sport & Recreation",
|
| 64 |
+
"Librarianship & Information Science",
|
| 65 |
+
"Music",
|
| 66 |
+
" ",
|
| 67 |
+
]
|
| 68 |
+
),
|
| 69 |
+
"Supervisor(s)": datasets.Value("string"),
|
| 70 |
+
"Funder(s)": datasets.Value("string"),
|
| 71 |
+
"EThOS URL": datasets.Value("string"),
|
| 72 |
+
"IR URL": datasets.Value("string"),
|
| 73 |
+
}
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class Ethos(datasets.GeneratorBasedBuilder):
|
| 78 |
+
|
| 79 |
+
VERSION = datasets.Version("1.1.0")
|
| 80 |
+
BUILDER_CONFIGS = [
|
| 81 |
+
datasets.BuilderConfig(
|
| 82 |
+
name="all",
|
| 83 |
+
version=VERSION,
|
| 84 |
+
description="",
|
| 85 |
+
),
|
| 86 |
+
datasets.BuilderConfig(
|
| 87 |
+
"skip_empty_abstracts",
|
| 88 |
+
version=VERSION,
|
| 89 |
+
description="EThOs skipping entires with no abstract",
|
| 90 |
+
),
|
| 91 |
+
]
|
| 92 |
+
|
| 93 |
+
DEFAULT_CONFIG_NAME = "all"
|
| 94 |
+
|
| 95 |
+
def _info(self):
|
| 96 |
+
return datasets.DatasetInfo(
|
| 97 |
+
description=_DESCRIPTION,
|
| 98 |
+
features=features,
|
| 99 |
+
supervised_keys=None,
|
| 100 |
+
homepage=_HOMEPAGE,
|
| 101 |
+
license=_LICENSE,
|
| 102 |
+
citation=_CITATION,
|
| 103 |
+
task_templates=[LanguageModeling(text_column="Abstract")],
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
def _split_generators(self, dl_manager):
|
| 107 |
+
"""Returns SplitGenerators."""
|
| 108 |
+
data_file = dl_manager.download(_URL)
|
| 109 |
+
return [
|
| 110 |
+
datasets.SplitGenerator(
|
| 111 |
+
name=datasets.Split.TRAIN,
|
| 112 |
+
# These kwargs will be passed to _generate_examples
|
| 113 |
+
gen_kwargs={
|
| 114 |
+
"filepath": data_file,
|
| 115 |
+
},
|
| 116 |
+
),
|
| 117 |
+
]
|
| 118 |
+
|
| 119 |
+
def _generate_examples(self, filepath):
|
| 120 |
+
"""Yields examples as (key, example) tuples."""
|
| 121 |
+
if self.config.name == "skip_empty_abstracts":
|
| 122 |
+
skip = True
|
| 123 |
+
else:
|
| 124 |
+
skip = False
|
| 125 |
+
with open(filepath, encoding="latin-1") as f:
|
| 126 |
+
reader = csv.DictReader(f)
|
| 127 |
+
id_ = 0
|
| 128 |
+
for row in reader:
|
| 129 |
+
abstract = row["Abstract"]
|
| 130 |
+
if skip and len(abstract) < 2:
|
| 131 |
+
continue
|
| 132 |
+
try:
|
| 133 |
+
date = datetime.strptime(row["Date"], "%Y")
|
| 134 |
+
except ValueError:
|
| 135 |
+
date = None
|
| 136 |
+
id_ += 1
|
| 137 |
+
yield id_, {
|
| 138 |
+
"Title": row["Title"],
|
| 139 |
+
"DOI": row["DOI"],
|
| 140 |
+
"Author": row["Author"],
|
| 141 |
+
"Author ISNI": row["Author ISNI"],
|
| 142 |
+
"ORCID": row["ORCID"],
|
| 143 |
+
"Institution": row["Institution"],
|
| 144 |
+
"Institution ISNI": row["Institution ISNI"],
|
| 145 |
+
"Date": date,
|
| 146 |
+
"Qualification": row["Qualification"],
|
| 147 |
+
"Abstract": abstract,
|
| 148 |
+
"Subject Discipline": row["Subject Discipline"],
|
| 149 |
+
"Supervisor(s)": row["Supervisor(s)"],
|
| 150 |
+
"Funder(s)": row["Funder(s)"],
|
| 151 |
+
"EThOS URL": row["EThOS URL"],
|
| 152 |
+
"IR URL": row["IR URL"],
|
| 153 |
+
}
|