Matej Klemen
commited on
Commit
•
aab5879
1
Parent(s):
fc2cf60
Modify script to enable loading all languages supported by Parlamint3
Browse files- parlaMintSI.py → ParlaMint3.py +47 -33
parlaMintSI.py → ParlaMint3.py
RENAMED
@@ -14,7 +14,6 @@
|
|
14 |
# limitations under the License.
|
15 |
|
16 |
import csv
|
17 |
-
import json
|
18 |
import os
|
19 |
|
20 |
import datasets
|
@@ -41,8 +40,7 @@ The corpora are also marked to the subcorpus they belong to ("reference", until
|
|
41 |
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,
|
42 |
but much stricter ParlaMint encoding guidelines (https://clarin-eric.github.io/ParlaMint/) and schemas (included in this distribution).
|
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 |
-
This dataset contains only Slovenian parliamentary debates.
|
46 |
"""
|
47 |
|
48 |
|
@@ -50,15 +48,22 @@ _HOMEPAGE = "http://hdl.handle.net/11356/1486"
|
|
50 |
|
51 |
_LICENSE = "Creative Commons - Attribution 4.0 International (CC BY 4.0)"
|
52 |
|
|
|
|
|
|
|
53 |
_URLS = {
|
54 |
-
|
|
|
55 |
}
|
56 |
|
57 |
|
58 |
-
class
|
59 |
"""This dataset contains transcriptions of Slovenian parliamentary debates and relevant metadata."""
|
60 |
|
61 |
-
|
|
|
|
|
|
|
62 |
|
63 |
def _info(self):
|
64 |
features = datasets.Features(
|
@@ -69,7 +74,7 @@ class ParlaMintSI(datasets.GeneratorBasedBuilder):
|
|
69 |
"Body": datasets.Value("string"),
|
70 |
"Term": datasets.Value("string"),
|
71 |
"Session": datasets.Value("string"),
|
72 |
-
"Meeting": datasets.Value("
|
73 |
"Sitting": datasets.Value("string"),
|
74 |
"Agenda": datasets.Value("string"),
|
75 |
"Subcorpus": datasets.Value("string"),
|
@@ -95,35 +100,44 @@ class ParlaMintSI(datasets.GeneratorBasedBuilder):
|
|
95 |
)
|
96 |
|
97 |
def _split_generators(self, dl_manager):
|
98 |
-
urls = _URLS[
|
|
|
99 |
download_path = dl_manager.download_and_extract(urls)
|
100 |
return [
|
101 |
datasets.SplitGenerator(
|
102 |
name=datasets.Split.TRAIN,
|
103 |
-
gen_kwargs={
|
104 |
-
|
105 |
-
},
|
106 |
-
),
|
107 |
]
|
108 |
|
109 |
-
def _generate_examples(self,
|
110 |
-
|
111 |
-
|
112 |
-
for
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# limitations under the License.
|
15 |
|
16 |
import csv
|
|
|
17 |
import os
|
18 |
|
19 |
import datasets
|
|
|
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 |
This entry contains the ParlaMint TEI-encoded corpora with the derived plain text versions of the corpora along with TSV metadata of the speeches.
|
43 |
+
Also included is the 3.0 release of the data and scripts available at the GitHub repository of the ParlaMint project.
|
|
|
44 |
"""
|
45 |
|
46 |
|
|
|
48 |
|
49 |
_LICENSE = "Creative Commons - Attribution 4.0 International (CC BY 4.0)"
|
50 |
|
51 |
+
SUPPORTED_LANGS = ["at", "ba", "be", "bg", "cz", "dk", "ee", "es-ct", "es-ga", "fr", "gb", "gr", "hr", "hu", "is",
|
52 |
+
"it", "lv", "nl", "no", "pl", "pt", "rs", "se", "si", "tr", "ua"]
|
53 |
+
|
54 |
_URLS = {
|
55 |
+
lang: f"https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1486/ParlaMint-{lang.upper()}.tgz"
|
56 |
+
for lang in SUPPORTED_LANGS
|
57 |
}
|
58 |
|
59 |
|
60 |
+
class ParlaMint3(datasets.GeneratorBasedBuilder):
|
61 |
"""This dataset contains transcriptions of Slovenian parliamentary debates and relevant metadata."""
|
62 |
|
63 |
+
BUILDER_CONFIGS = [
|
64 |
+
datasets.BuilderConfig(name=lang, version=datasets.Version("1.2.0"), description=f"{lang} parliamentary corpus")
|
65 |
+
for lang in SUPPORTED_LANGS
|
66 |
+
]
|
67 |
|
68 |
def _info(self):
|
69 |
features = datasets.Features(
|
|
|
74 |
"Body": datasets.Value("string"),
|
75 |
"Term": datasets.Value("string"),
|
76 |
"Session": datasets.Value("string"),
|
77 |
+
"Meeting": datasets.Value("string"),
|
78 |
"Sitting": datasets.Value("string"),
|
79 |
"Agenda": datasets.Value("string"),
|
80 |
"Subcorpus": datasets.Value("string"),
|
|
|
100 |
)
|
101 |
|
102 |
def _split_generators(self, dl_manager):
|
103 |
+
urls = _URLS[self.config.name]
|
104 |
+
|
105 |
download_path = dl_manager.download_and_extract(urls)
|
106 |
return [
|
107 |
datasets.SplitGenerator(
|
108 |
name=datasets.Split.TRAIN,
|
109 |
+
gen_kwargs={"data_dir": download_path}
|
110 |
+
)
|
|
|
|
|
111 |
]
|
112 |
|
113 |
+
def _generate_examples(self, data_dir):
|
114 |
+
data_dir = os.path.join(data_dir, f"ParlaMint-{self.config.name.upper()}.txt")
|
115 |
+
|
116 |
+
years = [curr_dir for curr_dir in os.listdir(data_dir) if os.path.isdir(os.path.join(data_dir, curr_dir))]
|
117 |
+
years = sorted(years, key=lambda _yr: int(_yr))
|
118 |
+
|
119 |
+
for year_dir in years:
|
120 |
+
# Metadata inside tab-separated files
|
121 |
+
tsv_files = sorted([f for f in os.listdir(os.path.join(data_dir, year_dir)) if f.endswith(".tsv")])
|
122 |
+
|
123 |
+
for fname in tsv_files:
|
124 |
+
tsv_path = os.path.join(data_dir, year_dir, fname)
|
125 |
+
# Text data inside txt files
|
126 |
+
txt_path = os.path.join(data_dir, year_dir, fname.replace("-meta.tsv", ".txt"))
|
127 |
+
|
128 |
+
with open(tsv_path, "r", encoding="utf-8") as f_tsv, \
|
129 |
+
open(txt_path, "r", encoding="utf-8") as f_txt:
|
130 |
+
tsv_reader = csv.DictReader(f_tsv, delimiter="\t")
|
131 |
+
|
132 |
+
txt_content = {} # ID of utterance -> text of utterance
|
133 |
+
for _line in f_txt:
|
134 |
+
_parts = _line.strip().split("\t")
|
135 |
+
txt_content[_parts[0]] = _parts[1]
|
136 |
+
|
137 |
+
for row in tsv_reader:
|
138 |
+
_id = row["ID"]
|
139 |
+
text = txt_content[_id]
|
140 |
+
example = {key: row.get(key, "") for key in row}
|
141 |
+
example["text"] = text
|
142 |
+
|
143 |
+
yield _id, example
|