Datasets:

Modalities:
Text
Formats:
parquet
Libraries:
Datasets
Dask
License:
albertvillanova HF staff commited on
Commit
ca84aae
1 Parent(s): d0b1e93

Generate all language pairs

Browse files
Files changed (1) hide show
  1. europarl_bilingual.py +7 -8
europarl_bilingual.py CHANGED
@@ -13,7 +13,7 @@
13
  # See the License for the specific language governing permissions and
14
  # limitations under the License.
15
 
16
-
17
  import os
18
  import xml.etree.ElementTree as ET
19
 
@@ -96,10 +96,7 @@ LANGUAGES = [
96
  "sv",
97
  ]
98
 
99
- ALL_PAIRS = []
100
- for i in range(len(LANGUAGES)):
101
- for j in range(i + 1, len(LANGUAGES)):
102
- ALL_PAIRS.append((LANGUAGES[i], LANGUAGES[j]))
103
 
104
  _VERSION = "8.0.0"
105
  _BASE_URL_DATASET = "https://object.pouta.csc.fi/OPUS-Europarl/v8/raw/{}.zip"
@@ -122,7 +119,7 @@ class EuroparlBilingualConfig(datasets.BuilderConfig):
122
  return (self.lang1, self.lang2)
123
 
124
  def _is_valid(self):
125
- return self._lang_pair() in ALL_PAIRS
126
 
127
 
128
  class EuroparlBilingual(datasets.GeneratorBasedBuilder):
@@ -133,7 +130,7 @@ class EuroparlBilingual(datasets.GeneratorBasedBuilder):
133
  BUILDER_CONFIG_CLASS = EuroparlBilingualConfig
134
  BUILDER_CONFIGS = [
135
  EuroparlBilingualConfig(lang1=lang1, lang2=lang2, version=datasets.Version(_VERSION))
136
- for lang1, lang2 in ALL_PAIRS[:5]
137
  ]
138
 
139
  def _info(self):
@@ -157,7 +154,9 @@ class EuroparlBilingual(datasets.GeneratorBasedBuilder):
157
  """Returns SplitGenerators."""
158
 
159
  if not self.config._is_valid():
160
- raise ValueError(f"{self.config._lang_pair()} is not a supported language pair. Choose among: {ALL_PAIRS}")
 
 
161
 
162
  # download data files
163
  path_datafile_1 = dl_manager.download_and_extract(_BASE_URL_DATASET.format(self.config.lang1))
 
13
  # See the License for the specific language governing permissions and
14
  # limitations under the License.
15
 
16
+ import itertools
17
  import os
18
  import xml.etree.ElementTree as ET
19
 
 
96
  "sv",
97
  ]
98
 
99
+ LANGUAGE_PAIRS = itertools.combinations(LANGUAGES, 2)
 
 
 
100
 
101
  _VERSION = "8.0.0"
102
  _BASE_URL_DATASET = "https://object.pouta.csc.fi/OPUS-Europarl/v8/raw/{}.zip"
 
119
  return (self.lang1, self.lang2)
120
 
121
  def _is_valid(self):
122
+ return self._lang_pair() in LANGUAGE_PAIRS
123
 
124
 
125
  class EuroparlBilingual(datasets.GeneratorBasedBuilder):
 
130
  BUILDER_CONFIG_CLASS = EuroparlBilingualConfig
131
  BUILDER_CONFIGS = [
132
  EuroparlBilingualConfig(lang1=lang1, lang2=lang2, version=datasets.Version(_VERSION))
133
+ for lang1, lang2 in LANGUAGE_PAIRS
134
  ]
135
 
136
  def _info(self):
 
154
  """Returns SplitGenerators."""
155
 
156
  if not self.config._is_valid():
157
+ raise ValueError(
158
+ f"{self.config._lang_pair()} is not a supported language pair. Choose among: {LANGUAGE_PAIRS}"
159
+ )
160
 
161
  # download data files
162
  path_datafile_1 = dl_manager.download_and_extract(_BASE_URL_DATASET.format(self.config.lang1))