albertvillanova HF staff commited on
Commit
a37dff0
1 Parent(s): 9941bfc

Delete loading script

Browse files
Files changed (1) hide show
  1. opus_rf.py +0 -139
opus_rf.py DELETED
@@ -1,139 +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
- """
16
- RF is a tiny parallel corpus of the Declarations of the Swedish Government and its translations.
17
-
18
- 5 languages, 10 bitexts
19
- total number of files: 11
20
- total number of tokens: 19.74k
21
- total number of sentence fragments: 0.86k
22
- """
23
-
24
-
25
- import os
26
-
27
- import datasets
28
-
29
-
30
- _CITATION = """\
31
- @InProceedings{TIEDEMANN12.463,
32
- author = {J{\"o}rg Tiedemann},
33
- title = {Parallel Data, Tools and Interfaces in OPUS},
34
- booktitle = {Proceedings of the Eight International Conference on Language Resources and Evaluation (LREC'12)},
35
- year = {2012},
36
- month = {may},
37
- date = {23-25},
38
- address = {Istanbul, Turkey},
39
- editor = {Nicoletta Calzolari (Conference Chair) and Khalid Choukri and Thierry Declerck and Mehmet Ugur Dogan and Bente Maegaard and Joseph Mariani and Jan Odijk and Stelios Piperidis},
40
- publisher = {European Language Resources Association (ELRA)},
41
- isbn = {978-2-9517408-7-7},
42
- language = {english}
43
- }
44
- """
45
-
46
- _DESCRIPTION = """\
47
- RF is a tiny parallel corpus of the Declarations of the Swedish Government and its translations.
48
- """
49
-
50
- _HOMEPAGE = "http://opus.nlpl.eu/RF.php"
51
-
52
- _VERSION = "1.0.0"
53
- _BASE_NAME = "RF.{}.{}"
54
- _BASE_URL = "https://object.pouta.csc.fi/OPUS-RF/v1/moses/{}-{}.txt.zip"
55
-
56
- _LANGUAGE_PAIRS = [
57
- ("de", "en"),
58
- ("de", "es"),
59
- ("de", "fr"),
60
- ("de", "sv"),
61
- ("en", "es"),
62
- ("en", "fr"),
63
- ("en", "sv"),
64
- ("es", "fr"),
65
- ("es", "sv"),
66
- ("fr", "sv"),
67
- ]
68
-
69
-
70
- class OpusRFTranslationsConfig(datasets.BuilderConfig):
71
- def __init__(self, *args, lang1=None, lang2=None, **kwargs):
72
- super().__init__(
73
- *args,
74
- name=f"{lang1}-{lang2}",
75
- **kwargs,
76
- )
77
- self.lang1 = lang1
78
- self.lang2 = lang2
79
-
80
-
81
- class OpusRF(datasets.GeneratorBasedBuilder):
82
- """RF is a tiny parallel corpus of the Declarations of the Swedish Government and its translations."""
83
-
84
- BUILDER_CONFIGS = [
85
- OpusRFTranslationsConfig(
86
- lang1=lang1,
87
- lang2=lang2,
88
- description=f"Translating {lang1} to {lang2} or vice versa",
89
- version=datasets.Version(_VERSION),
90
- )
91
- for lang1, lang2 in _LANGUAGE_PAIRS
92
- ]
93
- BUILDER_CONFIG_CLASS = OpusRFTranslationsConfig
94
-
95
- def _info(self):
96
- return datasets.DatasetInfo(
97
- description=_DESCRIPTION,
98
- features=datasets.Features(
99
- {
100
- "id": datasets.Value("string"),
101
- "translation": datasets.Translation(languages=(self.config.lang1, self.config.lang2)),
102
- }
103
- ),
104
- supervised_keys=None,
105
- homepage=_HOMEPAGE,
106
- citation=_CITATION,
107
- )
108
-
109
- def _split_generators(self, dl_manager):
110
- """Returns SplitGenerators."""
111
- download_url = _BASE_URL.format(self.config.lang1, self.config.lang2)
112
- path = dl_manager.download_and_extract(download_url)
113
- return [
114
- datasets.SplitGenerator(
115
- name=datasets.Split.TRAIN,
116
- gen_kwargs={"datapath": path},
117
- )
118
- ]
119
-
120
- def _generate_examples(self, datapath):
121
- """Yields examples."""
122
- l1, l2 = self.config.lang1, self.config.lang2
123
- folder = l1 + "-" + l2
124
- l1_file = _BASE_NAME.format(folder, l1)
125
- l2_file = _BASE_NAME.format(folder, l2)
126
- l1_path = os.path.join(datapath, l1_file)
127
- l2_path = os.path.join(datapath, l2_file)
128
- with open(l1_path, encoding="utf-8") as f1, open(l2_path, encoding="utf-8") as f2:
129
- for sentence_counter, (x, y) in enumerate(zip(f1, f2)):
130
- x = x.strip()
131
- y = y.strip()
132
- result = (
133
- sentence_counter,
134
- {
135
- "id": str(sentence_counter),
136
- "translation": {l1: x, l2: y},
137
- },
138
- )
139
- yield result