albertvillanova HF staff commited on
Commit
379a84f
1 Parent(s): 937d852

Delete loading script

Browse files
Files changed (1) hide show
  1. europa_ecdc_tm.py +0 -206
europa_ecdc_tm.py DELETED
@@ -1,206 +0,0 @@
1
- # coding=utf-8
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
- """European Center for Disease Prevention and Control Translation Memory dataset"""
16
-
17
-
18
- import os
19
- from xml.etree import ElementTree
20
-
21
- import datasets
22
-
23
-
24
- logger = datasets.logging.get_logger(__name__)
25
-
26
-
27
- _CITATION = """\
28
- @Article{Steinberger2014,
29
- author={Steinberger, Ralf
30
- and Ebrahim, Mohamed
31
- and Poulis, Alexandros
32
- and Carrasco-Benitez, Manuel
33
- and Schl{\"u}ter, Patrick
34
- and Przybyszewski, Marek
35
- and Gilbro, Signe},
36
- title={An overview of the European Union's highly multilingual parallel corpora},
37
- journal={Language Resources and Evaluation},
38
- year={2014},
39
- month={Dec},
40
- day={01},
41
- volume={48},
42
- number={4},
43
- pages={679-707},
44
- issn={1574-0218},
45
- doi={10.1007/s10579-014-9277-0},
46
- url={https://doi.org/10.1007/s10579-014-9277-0}
47
- }
48
- """
49
-
50
- _DESCRIPTION = """\
51
- In October 2012, the European Union (EU) agency 'European Centre for Disease Prevention and Control' (ECDC) released \
52
- a translation memory (TM), i.e. a collection of sentences and their professionally produced translations, in \
53
- twenty-five languages. This resource bears the name EAC Translation Memory, short EAC-TM.
54
- ECDC-TM covers 25 languages: the 23 official languages of the EU plus Norwegian (Norsk) and Icelandic. ECDC-TM was \
55
- created by translating from English into the following 24 languages: Bulgarian, Czech, Danish, Dutch, English, \
56
- Estonian, Gaelige (Irish), German, Greek, Finnish, French, Hungarian, Icelandic, Italian, Latvian, Lithuanian, \
57
- Maltese, Norwegian (NOrsk), Polish, Portuguese, Romanian, Slovak, Slovenian, Spanish and Swedish.
58
- All documents and sentences were thus originally written in English. They were then translated into the other \
59
- languages by professional translators from the Translation Centre CdT in Luxembourg."""
60
-
61
- _HOMEPAGE = "https://ec.europa.eu/jrc/en/language-technologies/ecdc-translation-memory"
62
-
63
- _LICENSE = "\
64
- Creative Commons Attribution 4.0 International(CC BY 4.0) licence \
65
- Copyright © EU/ECDC, 1995-2020"
66
-
67
- _VERSION = "1.0.0"
68
-
69
- _DATA_URL = "http://optima.jrc.it/Resources/ECDC-TM/ECDC-TM.zip"
70
-
71
- _AVAILABLE_LANGUAGES = (
72
- "bg",
73
- "cs",
74
- "da",
75
- "de",
76
- "el",
77
- "es",
78
- "en",
79
- "et",
80
- "fi",
81
- "fr",
82
- "ga",
83
- "hu",
84
- "is",
85
- "it",
86
- "lt",
87
- "lv",
88
- "mt",
89
- "nl",
90
- "no",
91
- "pl",
92
- "pt",
93
- "ro",
94
- "sk",
95
- "sl",
96
- "sv",
97
- )
98
-
99
-
100
- def _find_sentence(translation, language):
101
- """Util that returns the sentence in the given language from translation, or None if it is not found
102
-
103
- Args:
104
- translation: `xml.etree.ElementTree.Element`, xml tree element extracted from the translation memory files.
105
- language: `str`, language of interest e.g. 'en'
106
-
107
- Returns: `str` or `None`, can be `None` if the language of interest is not found in the translation
108
- """
109
- # Retrieve the first <tuv> children of translation having xml:lang tag equal to language
110
- namespaces = {"xml": "http://www.w3.org/XML/1998/namespace"}
111
- seg_tag = translation.find(path=f".//tuv[@xml:lang='{language.upper()}']/seg", namespaces=namespaces)
112
- if seg_tag is not None:
113
- return seg_tag.text
114
- return None
115
-
116
-
117
- class EuropaEcdcTMConfig(datasets.BuilderConfig):
118
- """BuilderConfig for EuropaEcdcTM"""
119
-
120
- def __init__(self, *args, language_pair=(None, None), **kwargs):
121
- """BuilderConfig for EuropaEcdcTM
122
- Args:
123
- language_pair: pair of languages that will be used for translation. Should
124
- contain 2-letter coded strings. First will be used at source and second
125
- as target in supervised mode. For example: ("se", "en").
126
- **kwargs: keyword arguments forwarded to super.
127
- """
128
- name = f"{language_pair[0]}2{language_pair[1]}"
129
- description = f"Translation dataset from {language_pair[0]} to {language_pair[1]}"
130
- super(EuropaEcdcTMConfig, self).__init__(
131
- *args,
132
- name=name,
133
- description=description,
134
- **kwargs,
135
- )
136
- source, target = language_pair
137
- assert source != target, "Source and target languages must be different}"
138
- assert (source in _AVAILABLE_LANGUAGES) and (
139
- target in _AVAILABLE_LANGUAGES
140
- ), f"Either source language {source} or target language {target} is not supported. Both must be one of : {_AVAILABLE_LANGUAGES}"
141
- self.language_pair = language_pair
142
-
143
-
144
- # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
145
- class EuropaEcdcTM(datasets.GeneratorBasedBuilder):
146
- """European Center for Disease Control and Prevention Translation Memory"""
147
-
148
- BUILDER_CONFIGS = [
149
- EuropaEcdcTMConfig(language_pair=("en", target), version=_VERSION) for target in ["bg", "fr", "sl"]
150
- ]
151
- BUILDER_CONFIG_CLASS = EuropaEcdcTMConfig
152
-
153
- def _info(self):
154
- source, target = self.config.language_pair
155
- return datasets.DatasetInfo(
156
- description=_DESCRIPTION,
157
- features=datasets.Features(
158
- {
159
- "translation": datasets.features.Translation(languages=self.config.language_pair),
160
- }
161
- ),
162
- supervised_keys=(source, target),
163
- homepage=_HOMEPAGE,
164
- license=_LICENSE,
165
- citation=_CITATION,
166
- )
167
-
168
- def _split_generators(self, dl_manager):
169
- dl_dir = dl_manager.download_and_extract(_DATA_URL)
170
- filepath = os.path.join(dl_dir, "ECDC-TM", "ECDC.tmx")
171
- source, target = self.config.language_pair
172
- return [
173
- datasets.SplitGenerator(
174
- name=datasets.Split.TRAIN,
175
- gen_kwargs={
176
- "filepath": filepath,
177
- "source_language": source,
178
- "target_language": target,
179
- },
180
- ),
181
- ]
182
-
183
- def _generate_examples(
184
- self,
185
- filepath,
186
- source_language,
187
- target_language,
188
- ):
189
- logger.info(f"⏳ Generating examples from = {filepath}")
190
- xml_element_tree = ElementTree.parse(filepath)
191
- xml_body_tag = xml_element_tree.getroot().find("body")
192
- assert xml_body_tag is not None, f"Invalid data: <body></body> tag not found in {filepath}"
193
-
194
- # Translations are stored in <tu>...</tu> tags
195
- translation_units = xml_body_tag.iter("tu")
196
-
197
- # _ids may not be contiguous
198
- for _id, translation in enumerate(translation_units):
199
- source_sentence = _find_sentence(translation=translation, language=source_language)
200
- target_sentence = _find_sentence(translation=translation, language=target_language)
201
- if source_sentence is None or target_sentence is None:
202
- continue
203
-
204
- yield _id, {
205
- "translation": {source_language: source_sentence, target_language: target_sentence},
206
- }