|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""On the Books Dataset""" |
|
|
|
import csv |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """TODO""" |
|
|
|
_DESCRIPTION = """\ |
|
This file is the training set that was used to train an algorithm to identify Jim Crow laws. |
|
It contains laws that are labeled as "Jim Crow" (jim_crow=1) or "Not Jim Crow" (jim_crow=0). |
|
The source of the determination is also provided. |
|
|
|
""" |
|
|
|
_HOMEPAGE = "https://onthebooks.lib.unc.edu/" |
|
|
|
_LICENSE = "CC BY 3.0" |
|
|
|
_URL = "https://cdr.lib.unc.edu/downloads/76537b20b?locale=en" |
|
|
|
|
|
class OnTheBooks(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("1.1.0") |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"source": datasets.Value("string"), |
|
"jim_crow": datasets.ClassLabel(names=["no_jim_crow", "jim_crow"]), |
|
"type": datasets.Value("string"), |
|
"chapter_num": datasets.Value("int32"), |
|
"section_num": datasets.Value("int32"), |
|
"chapter_text": datasets.Value("string"), |
|
"section_text": datasets.Value("string"), |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
data_file = dl_manager.download(_URL) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": data_file, |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""Yields examples as (key, example) tuples.""" |
|
with open(filepath, encoding="utf-8") as f: |
|
reader = csv.DictReader(f) |
|
yield from enumerate(reader) |
|
|