|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Fictions littéraires de Gallica / Literary fictions of Gallica dataset.""" |
|
|
|
|
|
import csv |
|
import time |
|
|
|
import requests |
|
|
|
import datasets |
|
|
|
|
|
_HOMEPAGE = "https://zenodo.org/record/4751204" |
|
|
|
_DESCRIPTION = """\ |
|
The collection "Fiction littéraire de Gallica" includes 19,240 public domain documents from the digital platform of the French National Library that were originally classified as novels or, more broadly, as literary fiction in prose. It consists of 372 tables of data in tsv format for each year of publication from 1600 to 1996 (all the missing years are in the 17th and 20th centuries). Each table is structured at the page-level of each novel (5,723,986 pages in all). It contains the complete text with the addition of some metadata. It can be opened in Excel or, preferably, with the new data analysis environments in R or Python (tidyverse, pandas…) |
|
|
|
This corpus can be used for large-scale quantitative analyses in computational humanities. The OCR text is presented in a raw format without any correction or enrichment in order to be directly processed for text mining purposes. |
|
|
|
The extraction is based on a historical categorization of the novels: the Y2 or Ybis classification. This classification, invented in 1730, is the only one that has been continuously applied to the BNF collections now available in the public domain (mainly before 1950). Consequently, the dataset is based on a definition of "novel" that is generally contemporary of the publication. |
|
|
|
A French data paper (in PDF and HTML) presents the construction process of the Y2 category and describes the structuring of the corpus. It also gives several examples of possible uses for computational humanities projects. |
|
""" |
|
|
|
_LICENSE = "Creative Commons Zero v1.0 Universal" |
|
|
|
_CITATION = """\ |
|
@dataset{langlais_pierre_carl_2021_4751204, |
|
author = {Langlais, Pierre-Carl}, |
|
title = {{Fictions littéraires de Gallica / Literary |
|
fictions of Gallica}}, |
|
month = apr, |
|
year = 2021, |
|
publisher = {Zenodo}, |
|
version = 1, |
|
doi = {10.5281/zenodo.4751204}, |
|
url = {https://doi.org/10.5281/zenodo.4751204} |
|
} |
|
""" |
|
|
|
ZENODO_API_URL = "https://zenodo.org/api/records/4751204" |
|
|
|
|
|
class GallicaLiteraryFictions(datasets.GeneratorBasedBuilder): |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"main_id": datasets.Value("string"), |
|
"catalogue_id": datasets.Value("string"), |
|
"titre": datasets.Value("string"), |
|
"nom_auteur": datasets.Value("string"), |
|
"prenom_auteur": datasets.Value("string"), |
|
"date": datasets.Value("uint16"), |
|
"document_ocr": datasets.Value("uint8"), |
|
"date_enligne": datasets.Value("string"), |
|
"gallica": datasets.Value("string"), |
|
"page": datasets.Value("uint16"), |
|
"texte": datasets.Value("string"), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
zenodo_record = requests.get(ZENODO_API_URL).json() |
|
urls = sorted([file["links"]["self"] for file in zenodo_record["files"] if file["type"] == "zip"]) |
|
data_dirs = [] |
|
for url in datasets.logging.tqdm(urls): |
|
data_dirs.append(dl_manager.download_and_extract(url)) |
|
time.sleep(1) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"data_paths": dl_manager.iter_files(data_dirs), |
|
}, |
|
) |
|
] |
|
|
|
def _generate_examples(self, data_paths): |
|
key = 0 |
|
for path in data_paths: |
|
with open(path, encoding="utf-8", newline="") as tsv_file: |
|
reader = csv.DictReader(tsv_file, delimiter="\t") |
|
for row in reader: |
|
yield key, row |
|
key += 1 |
|
break |
|
|