|
"""Medieval Latin.""" |
|
|
|
from typing import List |
|
from functools import partial |
|
|
|
import datasets |
|
|
|
import pandas |
|
|
|
|
|
VERSION = datasets.Version("1.0.0") |
|
_ORIGINAL_FEATURE_NAMES = [ |
|
"epistola", |
|
"author", |
|
"content" |
|
] |
|
_BASE_FEATURE_NAMES = [ |
|
"epistola", |
|
"author", |
|
"content" |
|
] |
|
|
|
DESCRIPTION = "MedievalLatin dataset from the Gungor thesis.\"." |
|
_HOMEPAGE = "https://openportal.isti.cnr.it/doc?id=people______::37b90c87470ef85c78e72b8a3c753293" |
|
_URLS = ("https://openportal.isti.cnr.it/doc?id=people______::37b90c87470ef85c78e72b8a3c753293") |
|
_CITATION = """ |
|
@techreport{oai:it.cnr:prodotti:438795, |
|
title = {MedLatin1 and MedLatin2: Two Datasets for the Computational Authorship Analysis of Medieval Latin Texts}, |
|
author = {Corbara S. and Moreo A. and Sebastiani F. and Tavoni M.}, |
|
institution = {Research report, 2020}, |
|
year = {2020} |
|
}""" |
|
|
|
|
|
urls_per_split = { |
|
"train": "https://huggingface.co/datasets/mstz/medieval_latin/raw/main/epistolas.json", |
|
} |
|
features_types_per_config = { |
|
"authorship": { |
|
"epistola": datasets.Value("string"), |
|
"author": datasets.Value("string"), |
|
"content": datasets.Value("string") |
|
} |
|
} |
|
features_per_config = {k: datasets.Features(features_types_per_config[k]) for k in features_types_per_config} |
|
|
|
|
|
class MedievalLatinConfig(datasets.BuilderConfig): |
|
def __init__(self, **kwargs): |
|
super(MedievalLatinConfig, self).__init__(version=VERSION, **kwargs) |
|
self.features = features_per_config[kwargs["name"]] |
|
|
|
|
|
class MedievalLatin(datasets.GeneratorBasedBuilder): |
|
|
|
DEFAULT_CONFIG = "authorship" |
|
BUILDER_CONFIGS = [ |
|
MedievalLatinConfig(name="authorship", |
|
description="authorship"), |
|
] |
|
|
|
|
|
def _info(self): |
|
info = datasets.DatasetInfo(description=DESCRIPTION, citation=_CITATION, homepage=_HOMEPAGE, |
|
features=features_per_config[self.config.name]) |
|
|
|
return info |
|
|
|
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: |
|
downloads = dl_manager.download_and_extract(urls_per_split) |
|
|
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloads["train"]}) |
|
] |
|
|
|
def _generate_examples(self, filepath: str): |
|
data = pandas.read_json(filepath) |
|
|
|
for row_id, row in data.iterrows(): |
|
data_row = dict(row) |
|
|
|
yield row_id, data_row |
|
|