hanaskitek
commited on
Commit
•
4bd8d10
1
Parent(s):
0eff606
commit 1
Browse files- README.md +0 -0
- parlaMintSI.py +129 -0
README.md
ADDED
File without changes
|
parlaMintSI.py
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
import csv
|
17 |
+
import json
|
18 |
+
import os
|
19 |
+
|
20 |
+
import datasets
|
21 |
+
|
22 |
+
_CITATION = """\
|
23 |
+
@InProceedings{huggingface:dataset,
|
24 |
+
title = {A great new dataset},
|
25 |
+
author={huggingface, Inc.
|
26 |
+
},
|
27 |
+
year={2020}
|
28 |
+
}
|
29 |
+
"""
|
30 |
+
|
31 |
+
_DESCRIPTION = """\
|
32 |
+
ParlaMint 3.0 is a multilingual set of 26 comparable corpora containing parliamentary debates mostly starting in 2015 and extending to mid-2022.
|
33 |
+
|
34 |
+
The corpora have extensive metadata, including aspects of the parliament; the speakers (name, gender, MP status, party affiliation, party coalition/opposition);
|
35 |
+
are structured into time-stamped terms, sessions and meetings; and with speeches being marked by the speaker and their role (e.g. chair, regular speaker).
|
36 |
+
The speeches also contain marked-up transcriber comments, such as gaps in the transcription, interruptions, applause, etc.
|
37 |
+
Note that some corpora have further information, e.g. the year of birth of the speakers, links to their Wikipedia articles, their membership in various committees, etc.
|
38 |
+
The corpora are also marked to the subcorpus they belong to ("reference", until 2020-01-30, "covid", from 2020-01-31, and "war", from 2022-02-24).
|
39 |
+
|
40 |
+
The corpora are encoded according to the Parla-CLARIN TEI recommendation (https://clarin-eric.github.io/parla-clarin/), but have been encoded against the compatible,
|
41 |
+
but much stricter ParlaMint encoding guidelines (https://clarin-eric.github.io/ParlaMint/) and schemas (included in this distribution.
|
42 |
+
|
43 |
+
This entry contains the ParlaMint TEI-encoded corpora with the derived plain text versions of the corpora along with TSV metadata of the speeches.
|
44 |
+
Also included is the 3.0 release of the data and scripts available at the GitHub repository of the ParlaMint project.
|
45 |
+
|
46 |
+
This dataset contains only Slovenian parliamentary debates.
|
47 |
+
"""
|
48 |
+
|
49 |
+
_HOMEPAGE = "http://hdl.handle.net/11356/1486"
|
50 |
+
|
51 |
+
_LICENSE = "Creative Commons - Attribution 4.0 International (CC BY 4.0)"
|
52 |
+
|
53 |
+
_URLS = {
|
54 |
+
"parlamint": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1486/ParlaMint-SI.tgz?sequence=24&isAllowed=y",
|
55 |
+
}
|
56 |
+
|
57 |
+
|
58 |
+
class ParlaMintSI(datasets.GeneratorBasedBuilder):
|
59 |
+
"""This dataset contains transcriptions of Slovenian parliamentary debates and relevant metadata."""
|
60 |
+
|
61 |
+
VERSION = datasets.Version("1.1.0")
|
62 |
+
|
63 |
+
def _info(self):
|
64 |
+
features = datasets.Features(
|
65 |
+
{
|
66 |
+
"ID": datasets.Value("string"),
|
67 |
+
"Title": datasets.Value("string"),
|
68 |
+
"Date": datasets.Value("string"),
|
69 |
+
"Body": datasets.Value("string"),
|
70 |
+
"Term": datasets.Value("string"),
|
71 |
+
"Session": datasets.Value("string"),
|
72 |
+
"Meeting": datasets.Value("int32"),
|
73 |
+
"Sitting": datasets.Value("string"),
|
74 |
+
"Agenda": datasets.Value("string"),
|
75 |
+
"Subcorpus": datasets.Value("string"),
|
76 |
+
"Speaker_role": datasets.Value("string"),
|
77 |
+
"Speaker_MP": datasets.Value("string"),
|
78 |
+
"Speaker_Minister": datasets.Value("string"),
|
79 |
+
"Speaker_party": datasets.Value("string"),
|
80 |
+
"Speaker_party_name": datasets.Value("string"),
|
81 |
+
"Party_status": datasets.Value("string"),
|
82 |
+
"Speaker_name": datasets.Value("string"),
|
83 |
+
"Speaker_gender": datasets.Value("string"),
|
84 |
+
"Speaker_birth": datasets.Value("string"),
|
85 |
+
"text": datasets.Value("string")
|
86 |
+
}
|
87 |
+
)
|
88 |
+
|
89 |
+
return datasets.DatasetInfo(
|
90 |
+
description=_DESCRIPTION,
|
91 |
+
features=features,
|
92 |
+
homepage=_HOMEPAGE,
|
93 |
+
license=_LICENSE,
|
94 |
+
citation=_CITATION,
|
95 |
+
)
|
96 |
+
|
97 |
+
def _split_generators(self, dl_manager):
|
98 |
+
urls = _URLS["parlamint"]
|
99 |
+
download_path = dl_manager.download_and_extract(urls)
|
100 |
+
return [
|
101 |
+
datasets.SplitGenerator(
|
102 |
+
name=datasets.Split.TRAIN,
|
103 |
+
gen_kwargs={
|
104 |
+
"filepath": download_path,
|
105 |
+
},
|
106 |
+
),
|
107 |
+
]
|
108 |
+
|
109 |
+
def _generate_examples(self, filepath):
|
110 |
+
filepath = os.path.join(filepath, "ParlaMint-SI.txt")
|
111 |
+
|
112 |
+
for year_dir in os.listdir(filepath):
|
113 |
+
year_path = os.path.join(filepath, year_dir)
|
114 |
+
if os.path.isdir(year_path):
|
115 |
+
tsv_files = [f for f in os.listdir(year_path) if f.endswith(".tsv")]
|
116 |
+
for tsv_file in tsv_files:
|
117 |
+
tsv_path = os.path.join(year_path, tsv_file)
|
118 |
+
txt_path = os.path.join(year_path, tsv_file.replace("-meta.tsv", ".txt"))
|
119 |
+
|
120 |
+
with open(tsv_path, "r", encoding="utf-8") as tsv, open(txt_path, "r", encoding="utf-8") as txt:
|
121 |
+
tsv_reader = csv.DictReader(tsv, delimiter="\t")
|
122 |
+
txt_content = txt.readlines()
|
123 |
+
|
124 |
+
for row in tsv_reader:
|
125 |
+
id_ = row.get("ID", "")
|
126 |
+
text = next((line.split("\t")[1] for line in txt_content if line.startswith(id_)), "")
|
127 |
+
example = {key: row.get(key, "") for key in row}
|
128 |
+
example["text"] = text
|
129 |
+
yield id_, example
|