File size: 3,084 Bytes
8adda2c |
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 |
""" rsdo4_en_sl is a parallel corpus of English-Slovene and Slovene-English translation pairs."""
import xml.etree.ElementTree as ET
import os
import datasets
_CITATION = """\
@misc{rsdo4_en_sl,
title = {Parallel corpus {EN}-{SL} {RSDO4} 1.0},
author = {Repar, Andra{\v z} and Lebar Bajec, Iztok},
url = {http://hdl.handle.net/11356/1457},
year = {2021}
}
"""
_DESCRIPTION = """\
The RSDO4 parallel corpus of English-Slovene and Slovene-English translation pairs was collected as part of work
package 4 of the Slovene in the Digital Environment project. It contains texts collected from public institutions
and texts submitted by individual donors through the text collection portal created within the project. The corpus
consists of 964433 translation pairs (extracted from standard translation formats (TMX, XLIFF) or manually aligned)
in randomized order which can be used for machine translation training.
"""
_HOMEPAGE = "http://hdl.handle.net/11356/1457"
_LICENSE = "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)"
_URLS = {
"rsdo4_en_sl": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1457/rsdo4-parallel-corpus-1-0.tmx.zip"
}
XML_NAMESPACE = "{http://www.w3.org/XML/1998/namespace}"
class RSDO4EnSl(datasets.GeneratorBasedBuilder):
"""rsdo4_en_sl is a parallel corpus of English-Slovene and Slovene-English translation pairs."""
VERSION = datasets.Version("1.0.0")
def _info(self):
features = datasets.Features(
{
"en_seq": datasets.Value("string"),
"sl_seq": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
urls = _URLS["rsdo4_en_sl"]
data_dir = dl_manager.download_and_extract(urls)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"file_path": os.path.join(data_dir, "rsdo4-parallel-corpus-1-0.tmx")
}
)
]
def _generate_examples(self, file_path):
doc = ET.parse(file_path)
root = doc.getroot()
for i, curr_unit in enumerate(root.iterfind(".//tu")):
translation_pair = curr_unit.findall("tuv")
formatted_pair = {}
for curr_seq in translation_pair:
# Not sure whether the languages are erroneously swapped or whether xml:lang represents the "language direction"
seq_lang = "sl" if curr_seq.attrib[f"{XML_NAMESPACE}lang"] == "en" else "en"
curr_text = curr_seq.find("seg").text
curr_text = "" if curr_text is None else curr_text.strip()
formatted_pair[f"{seq_lang}_seq"] = curr_text
yield i, formatted_pair
|