EThOS-PhD-metadata / EThOS-PhD-metadata.py
GJHistory's picture
Update EThOS-PhD-metadata.py
c51b050 verified
raw
history blame
5.22 kB
# coding=utf-8
"""British Library EThos dataset"""
import csv
from datetime import datetime
import datasets
from datasets.features import Features
from datasets.tasks import LanguageModeling
_CITATION = """\
@misc{british library_genre,
title={UK Doctoral Thesis Metadata from EThOS},
url={UK Doctoral Thesis Metadata from EThOS},
author={{British Library} and {Rosie, Heather}},
year={2021}}
"""
_DESCRIPTION = """\
The data in this collection comprises the bibliographic metadata for all UK doctoral theses listed in EThOS, the UK's national thesis service.
We estimate the data covers around 98% of all PhDs ever awarded by UK Higher Education institutions, dating back to 1787.
Thesis metadata from every PhD-awarding university in the UK is included.
"""
_HOMEPAGE = "https://doi.org/10.23636/rcm4-zk44"
_LICENSE = "CC BY 4.0 Attribution"
_URL = "https://bl.iro.bl.uk/downloads/05b31c0e-da22-4b9f-a17c-35880aa111f4?locale=en"
features = Features(
{
"Title": datasets.Value("string"),
"DOI": datasets.Value("string"),
"Author": datasets.Value("string"),
"Author ISNI": datasets.Value("string"),
"ORCID": datasets.Value("string"),
"Institution": datasets.Value("string"),
"Institution ISNI": datasets.Value("string"),
"Date": datasets.Value("timestamp[s]"),
"Qualification": datasets.Value("string"),
"Abstract": datasets.Value("string"),
"Subject Discipline": datasets.ClassLabel(
names=[
"Physical Sciences",
"Biological Sciences",
"Engineering & Technology",
"Mathematics & Statistics",
"Agriculture & Veterinary Sciences",
"Medicine & Health",
"Computer Science",
"Philosophy, Psychology & Religious Studies",
"Business & Administrative Studies",
"Education",
"Language & Literature",
"Social, Economic & Political Studies",
"Architecture, Building & Planning",
"History & Archaeology",
"Creative Arts & Design",
"Law",
"Sport & Recreation",
"Librarianship & Information Science",
"Music",
" ",
]
),
"Supervisor(s)": datasets.Value("string"),
"Funder(s)": datasets.Value("string"),
"EThOS URL": datasets.Value("string"),
"IR URL": datasets.Value("string"),
}
)
class Ethos(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.1.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="all",
version=VERSION,
description="",
),
datasets.BuilderConfig(
"skip_empty_abstracts",
version=VERSION,
description="EThOs skipping entires with no abstract",
),
]
DEFAULT_CONFIG_NAME = "all"
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
task_templates=[LanguageModeling(text_column="Abstract")],
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_file = dl_manager.download(_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": data_file,
},
),
]
def _generate_examples(self, filepath):
"""Yields examples as (key, example) tuples."""
if self.config.name == "skip_empty_abstracts":
skip = True
else:
skip = False
with open(filepath, encoding="latin-1") as f:
reader = csv.DictReader(f)
id_ = 0
for row in reader:
abstract = row["Abstract"]
if skip and len(abstract) < 2:
continue
try:
date = datetime.strptime(row["Date"], "%Y")
except ValueError:
date = None
id_ += 1
yield id_, {
"Title": row["Title"],
"DOI": row["DOI"],
"Author": row["Author"],
"Author ISNI": row["Author ISNI"],
"ORCID": row["ORCID"],
"Institution": row["Institution"],
"Institution ISNI": row["Institution ISNI"],
"Date": date,
"Qualification": row["Qualification"],
"Abstract": abstract,
"Subject Discipline": row["Subject Discipline"],
"Supervisor(s)": row["Supervisor(s)"],
"Funder(s)": row["Funder(s)"],
"EThOS URL": row["EThOS URL"],
"IR URL": row["IR URL"],
}