albertvillanova HF staff commited on
Commit
0608e87
1 Parent(s): d866c68

Delete loading script

Browse files
Files changed (1) hide show
  1. opus_gnome.py +0 -133
opus_gnome.py DELETED
@@ -1,133 +0,0 @@
1
- # coding=utf-8
2
- # Copyright 2020 HuggingFace Datasets Authors.
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
- # Lint as: python3
17
- import os
18
-
19
- import datasets
20
-
21
-
22
- _DESCRIPTION = """\
23
- A parallel corpus of GNOME localization files. Source: https://l10n.gnome.org
24
-
25
- 187 languages, 12,822 bitexts
26
- total number of files: 113,344
27
- total number of tokens: 267.27M
28
- total number of sentence fragments: 58.12M
29
- """
30
- _HOMEPAGE_URL = "http://opus.nlpl.eu/GNOME.php"
31
- _CITATION = """\
32
- @InProceedings{TIEDEMANN12.463,
33
- author = {J{\"o}rg Tiedemann},
34
- title = {Parallel Data, Tools and Interfaces in OPUS},
35
- booktitle = {Proceedings of the Eight International Conference on Language Resources and Evaluation (LREC'12)},
36
- year = {2012},
37
- month = {may},
38
- date = {23-25},
39
- address = {Istanbul, Turkey},
40
- 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},
41
- publisher = {European Language Resources Association (ELRA)},
42
- isbn = {978-2-9517408-7-7},
43
- language = {english}
44
- }
45
- """
46
-
47
- _VERSION = "1.0.0"
48
- _BASE_NAME = "GNOME.{}.{}"
49
- _BASE_URL = "https://object.pouta.csc.fi/OPUS-GNOME/v1/moses/{}-{}.txt.zip"
50
- # Please note that only few pairs are shown here. You can use config to generate data for all language pairs
51
- _LANGUAGE_PAIRS = [
52
- ("ar", "bal"),
53
- ("bg", "csb"),
54
- ("ca", "en_GB"),
55
- ("cs", "eo"),
56
- ("de", "ha"),
57
- ("cs", "tk"),
58
- ("da", "vi"),
59
- ("en_GB", "my"),
60
- ("el", "sk"),
61
- ("de", "tt"),
62
- ]
63
-
64
-
65
- class GnomeConfig(datasets.BuilderConfig):
66
- def __init__(self, *args, lang1=None, lang2=None, **kwargs):
67
- super().__init__(
68
- *args,
69
- name=f"{lang1}-{lang2}",
70
- **kwargs,
71
- )
72
- self.lang1 = lang1
73
- self.lang2 = lang2
74
-
75
-
76
- class OpusGnome(datasets.GeneratorBasedBuilder):
77
- BUILDER_CONFIGS = [
78
- GnomeConfig(
79
- lang1=lang1,
80
- lang2=lang2,
81
- description=f"Translating {lang1} to {lang2} or vice versa",
82
- version=datasets.Version(_VERSION),
83
- )
84
- for lang1, lang2 in _LANGUAGE_PAIRS
85
- ]
86
- BUILDER_CONFIG_CLASS = GnomeConfig
87
-
88
- def _info(self):
89
- return datasets.DatasetInfo(
90
- description=_DESCRIPTION,
91
- features=datasets.Features(
92
- {
93
- "id": datasets.Value("string"),
94
- "translation": datasets.Translation(languages=(self.config.lang1, self.config.lang2)),
95
- },
96
- ),
97
- supervised_keys=None,
98
- homepage=_HOMEPAGE_URL,
99
- citation=_CITATION,
100
- )
101
-
102
- def _split_generators(self, dl_manager):
103
- def _base_url(lang1, lang2):
104
- return _BASE_URL.format(lang1, lang2)
105
-
106
- download_url = _base_url(self.config.lang1, self.config.lang2)
107
- path = dl_manager.download_and_extract(download_url)
108
- return [
109
- datasets.SplitGenerator(
110
- name=datasets.Split.TRAIN,
111
- gen_kwargs={"datapath": path},
112
- )
113
- ]
114
-
115
- def _generate_examples(self, datapath):
116
- l1, l2 = self.config.lang1, self.config.lang2
117
- folder = l1 + "-" + l2
118
- l1_file = _BASE_NAME.format(folder, l1)
119
- l2_file = _BASE_NAME.format(folder, l2)
120
- l1_path = os.path.join(datapath, l1_file)
121
- l2_path = os.path.join(datapath, l2_file)
122
- with open(l1_path, encoding="utf-8") as f1, open(l2_path, encoding="utf-8") as f2:
123
- for sentence_counter, (x, y) in enumerate(zip(f1, f2)):
124
- x = x.strip()
125
- y = y.strip()
126
- result = (
127
- sentence_counter,
128
- {
129
- "id": str(sentence_counter),
130
- "translation": {l1: x, l2: y},
131
- },
132
- )
133
- yield result