Matīss commited on
Commit
faec406
1 Parent(s): 43c2f86

Upload liv4ever.py

Browse files
Files changed (1) hide show
  1. liv4ever.py +2 -83
liv4ever.py CHANGED
@@ -80,24 +80,6 @@ class liv4ever(datasets.GeneratorBasedBuilder):
80
 
81
  VERSION = datasets.Version("1.0.0")
82
 
83
- # This is an example of a dataset with multiple configurations.
84
- # If you don't want/need to define several sub-sets in your dataset,
85
- # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
86
-
87
- # If you need to make complex sub-parts in the datasets with configurable options
88
- # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
89
- # BUILDER_CONFIG_CLASS = MyBuilderConfig
90
-
91
- # You will be able to load one or the other configurations in the following list with
92
- # data = datasets.load_dataset('my_dataset', 'train')
93
- # data = datasets.load_dataset('my_dataset', 'dev')
94
- # BUILDER_CONFIGS = [
95
- # datasets.BuilderConfig(name="train", version=VERSION, description="This part of my dataset covers a first domain"),
96
- # datasets.BuilderConfig(name="dev", version=VERSION, description="This part of my dataset covers a second domain"),
97
- # ]
98
-
99
- # DEFAULT_CONFIG_NAME = "train" # It's not mandatory to have a default configuration. Just use one if it make sense.
100
-
101
  def _info(self):
102
  # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
103
  features = datasets.Features(
@@ -125,40 +107,6 @@ class liv4ever(datasets.GeneratorBasedBuilder):
125
  )
126
 
127
  def _split_generators(self, dl_manager):
128
- # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
129
- # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
130
-
131
- # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
132
- # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
133
- # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
134
- # urls = _URLS[self.config.name]
135
- # data_dir = dl_manager.download_and_extract(urls)
136
- # return [
137
- # datasets.SplitGenerator(
138
- # name=datasets.Split.TRAIN,
139
- # # These kwargs will be passed to _generate_examples
140
- # gen_kwargs={
141
- # "filepath": os.path.join(data_dir),
142
- # "split": "train",
143
- # },
144
- # ),
145
- # datasets.SplitGenerator(
146
- # name=datasets.Split.TEST,
147
- # # These kwargs will be passed to _generate_examples
148
- # gen_kwargs={
149
- # "filepath": os.path.join(data_dir),
150
- # "split": "test"
151
- # },
152
- # ),
153
- # datasets.SplitGenerator(
154
- # name=datasets.Split.VALIDATION,
155
- # # These kwargs will be passed to _generate_examples
156
- # gen_kwargs={
157
- # "filepath": os.path.join(data_dir),
158
- # "split": "dev",
159
- # },
160
- # ),
161
- # ]
162
  urls_to_download = _URLS
163
  downloaded_files = dl_manager.download_and_extract(urls_to_download)
164
 
@@ -168,10 +116,7 @@ class liv4ever(datasets.GeneratorBasedBuilder):
168
  datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
169
  ]
170
 
171
- # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
172
  def _generate_examples(self, filepath):
173
- # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
174
- # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
175
  with open(filepath, encoding="utf-8") as f:
176
  jsondata = json.load(f)
177
  n = 0
@@ -179,44 +124,18 @@ class liv4ever(datasets.GeneratorBasedBuilder):
179
  for sentence in source["sentences"]:
180
  # Yields examples as (key, example) tuples
181
  n=n+1
182
- if source["source"] == "facebook" or source["source"] == "satversme":
183
- yield n, {
184
- "source": source["source"],
185
- "liv": sentence["liv"],
186
- "lv": sentence["lv"],
187
- "fr": sentence["fr"],
188
- "en": sentence["en"],
189
- }
190
- if source["source"] == "songs":
191
  yield n, {
192
  "source": source["source"],
193
  "liv": sentence["liv"],
194
  "lv": sentence["lv"],
195
  "et": sentence["et"],
196
- "en": sentence["en"],
197
  }
198
- if source["source"] == "trilium" or source["source"] == "dictionary" or source["source"] == "stalte":
199
  yield n, {
200
  "source": source["source"],
201
  "liv": sentence["liv"],
202
  "lv": sentence["lv"],
203
  "et": sentence["et"],
204
- }
205
- if source["source"] == "vaari" or source["source"] == "luule":
206
- yield n, {
207
- "source": source["source"],
208
- "liv": sentence["liv"],
209
- "et": sentence["et"],
210
- }
211
- if source["source"] == "jeful" and "et" in sentence:
212
- yield n, {
213
- "source": source["source"],
214
- "liv": sentence["liv"],
215
- "et": sentence["et"],
216
- }
217
- if source["source"] == "jeful" and "en" in sentence:
218
- yield n, {
219
- "source": source["source"],
220
- "liv": sentence["liv"],
221
  "en": sentence["en"],
222
  }
 
80
 
81
  VERSION = datasets.Version("1.0.0")
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  def _info(self):
84
  # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
85
  features = datasets.Features(
 
107
  )
108
 
109
  def _split_generators(self, dl_manager):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  urls_to_download = _URLS
111
  downloaded_files = dl_manager.download_and_extract(urls_to_download)
112
 
 
116
  datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
117
  ]
118
 
 
119
  def _generate_examples(self, filepath):
 
 
120
  with open(filepath, encoding="utf-8") as f:
121
  jsondata = json.load(f)
122
  n = 0
 
124
  for sentence in source["sentences"]:
125
  # Yields examples as (key, example) tuples
126
  n=n+1
127
+ if source["source"] in ["trilium", "dictionary", "stalte"]:
 
 
 
 
 
 
 
 
128
  yield n, {
129
  "source": source["source"],
130
  "liv": sentence["liv"],
131
  "lv": sentence["lv"],
132
  "et": sentence["et"],
 
133
  }
134
+ elif source["source"] in ["facebook", "satversme"]:
135
  yield n, {
136
  "source": source["source"],
137
  "liv": sentence["liv"],
138
  "lv": sentence["lv"],
139
  "et": sentence["et"],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  "en": sentence["en"],
141
  }