File size: 2,768 Bytes
0ee61b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28d3113
0ee61b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f93a01
0ee61b4
 
 
 
 
 
18db68c
0ee61b4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""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=["LEFT", "LEAN_LEFT", "CENTER", "LEAN_RIGHT", "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": row[1],
                    "wing": wing_map[row[2]],
                }