Matej Klemen commited on
Commit ·
8adda2c
1
Parent(s): 386ed04
Add first version of RSDO4 en-sl corpus
Browse files- rsdo4_en_sl.py +85 -0
rsdo4_en_sl.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" rsdo4_en_sl is a parallel corpus of English-Slovene and Slovene-English translation pairs."""
|
| 2 |
+
import xml.etree.ElementTree as ET
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
import datasets
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
_CITATION = """\
|
| 9 |
+
@misc{rsdo4_en_sl,
|
| 10 |
+
title = {Parallel corpus {EN}-{SL} {RSDO4} 1.0},
|
| 11 |
+
author = {Repar, Andra{\v z} and Lebar Bajec, Iztok},
|
| 12 |
+
url = {http://hdl.handle.net/11356/1457},
|
| 13 |
+
year = {2021}
|
| 14 |
+
}
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
_DESCRIPTION = """\
|
| 18 |
+
The RSDO4 parallel corpus of English-Slovene and Slovene-English translation pairs was collected as part of work
|
| 19 |
+
package 4 of the Slovene in the Digital Environment project. It contains texts collected from public institutions
|
| 20 |
+
and texts submitted by individual donors through the text collection portal created within the project. The corpus
|
| 21 |
+
consists of 964433 translation pairs (extracted from standard translation formats (TMX, XLIFF) or manually aligned)
|
| 22 |
+
in randomized order which can be used for machine translation training.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
_HOMEPAGE = "http://hdl.handle.net/11356/1457"
|
| 26 |
+
|
| 27 |
+
_LICENSE = "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)"
|
| 28 |
+
|
| 29 |
+
_URLS = {
|
| 30 |
+
"rsdo4_en_sl": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1457/rsdo4-parallel-corpus-1-0.tmx.zip"
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
XML_NAMESPACE = "{http://www.w3.org/XML/1998/namespace}"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class RSDO4EnSl(datasets.GeneratorBasedBuilder):
|
| 37 |
+
"""rsdo4_en_sl is a parallel corpus of English-Slovene and Slovene-English translation pairs."""
|
| 38 |
+
|
| 39 |
+
VERSION = datasets.Version("1.0.0")
|
| 40 |
+
|
| 41 |
+
def _info(self):
|
| 42 |
+
features = datasets.Features(
|
| 43 |
+
{
|
| 44 |
+
"en_seq": datasets.Value("string"),
|
| 45 |
+
"sl_seq": datasets.Value("string"),
|
| 46 |
+
}
|
| 47 |
+
)
|
| 48 |
+
return datasets.DatasetInfo(
|
| 49 |
+
description=_DESCRIPTION,
|
| 50 |
+
features=features,
|
| 51 |
+
homepage=_HOMEPAGE,
|
| 52 |
+
license=_LICENSE,
|
| 53 |
+
citation=_CITATION,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
def _split_generators(self, dl_manager):
|
| 57 |
+
urls = _URLS["rsdo4_en_sl"]
|
| 58 |
+
data_dir = dl_manager.download_and_extract(urls)
|
| 59 |
+
return [
|
| 60 |
+
datasets.SplitGenerator(
|
| 61 |
+
name=datasets.Split.TRAIN,
|
| 62 |
+
# These kwargs will be passed to _generate_examples
|
| 63 |
+
gen_kwargs={
|
| 64 |
+
"file_path": os.path.join(data_dir, "rsdo4-parallel-corpus-1-0.tmx")
|
| 65 |
+
}
|
| 66 |
+
)
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
def _generate_examples(self, file_path):
|
| 70 |
+
doc = ET.parse(file_path)
|
| 71 |
+
root = doc.getroot()
|
| 72 |
+
|
| 73 |
+
for i, curr_unit in enumerate(root.iterfind(".//tu")):
|
| 74 |
+
translation_pair = curr_unit.findall("tuv")
|
| 75 |
+
|
| 76 |
+
formatted_pair = {}
|
| 77 |
+
for curr_seq in translation_pair:
|
| 78 |
+
# Not sure whether the languages are erroneously swapped or whether xml:lang represents the "language direction"
|
| 79 |
+
seq_lang = "sl" if curr_seq.attrib[f"{XML_NAMESPACE}lang"] == "en" else "en"
|
| 80 |
+
|
| 81 |
+
curr_text = curr_seq.find("seg").text
|
| 82 |
+
curr_text = "" if curr_text is None else curr_text.strip()
|
| 83 |
+
formatted_pair[f"{seq_lang}_seq"] = curr_text
|
| 84 |
+
|
| 85 |
+
yield i, formatted_pair
|