ptparl / ptparl.py
luist18's picture
Update ptparl.py
0f93a01
raw
history blame
2.78 kB
"""ptparl dataset."""
import xml.etree.ElementTree as ET
import datasets
import csv
_DESCRIPTION = """
The PTPARL dataset is a dataset containing 5713 interventions in the Portuguese parliament.
"""
_HOMEPAGE = "MIT"
_LICENSE = ""
_URL = "https://gist.githubusercontent.com/luist18/e3730636962a117ef0eb9e0659f1cba8/raw/5e55a95aaec8261c7690c7132037121d99c39279/pt_parl.csv"
group_map = {
"PS": 0,
"CDS-PP": 1,
"PCP": 2,
"BE": 3,
"PSD": 4,
"PEV": 5,
"PAN": 6,
"CH": 7,
"IL": 8,
"L": 9,
}
wing_map = {
"LEFT": 0,
"LEAN_LEFT": 1,
"CENTER": 2,
"LEAN_RIGHT": 3,
"RIGHT": 4,
}
class PTPARL(datasets.GeneratorBasedBuilder):
"""PTPARL dataset."""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="full",
version=VERSION,
description="Full dataset",
),
]
DEFAULT_CONFIG_NAME = "full"
def _info(self):
features = datasets.Features(
{
"text": datasets.Value("string"),
"group": datasets.features.ClassLabel(
names=[
"PS",
"CDS-PP",
"PCP",
"BE",
"PSD",
"PEV",
"PAN",
"CH",
"IL",
"L",
]
),
"wing": datasets.features.ClassLabel(
names=[["CENTER", "LEAN_RIGHT", "LEFT", "LEAN_LEFT", "RIGHT"]]
),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=None,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_file = dl_manager.download_and_extract(_URL)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": data_file,
},
),
]
def _generate_examples(self, filepath):
"""Yields examples."""
id_ = 0
with open(filepath, encoding="utf-8") as tsv_file:
reader = csv.reader(tsv_file, delimiter=",")
for id_, row in enumerate(reader):
if id_ == 0:
continue
yield id_, {
"text": row[0],
"group": group_map[row[1]],
"wing": wing_map[row[2]],
}