File size: 1,334 Bytes
42f9bb7
 
 
 
 
b143817
 
42f9bb7
 
 
a822dfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7ff2dd7
a822dfa
 
 
72d2faf
 
a822dfa
72d2faf
a822dfa
ef6579a
 
 
9f57957
a822dfa
 
 
fad69cc
ef6579a
fad69cc
a822dfa
 
 
9f57957
7ff2dd7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Huggingface datasets script for Zenodo dataset.
"""

import os
import shutil
import json

import datasets

_DESCRIPTION = """\
This dataset is for downloading a Zenodo dataset without extra packages.
"""


class NewDataset(datasets.GeneratorBasedBuilder):
    """This dataset downloads a zenodo dataset and returns its path."""

    VERSION = datasets.Version("1.1.0")

    def _info(self):
        features = datasets.Features(
            {
                "path": datasets.Value("string"),
            }
        )

        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
        )

    def _split_generators(self, dl_manager):
        self.zenodo_id = self.config.name.split("_")[0]
        self.filename = self.config.name.split("_")[1]

        url = f"https://zenodo.org/record/{self.zenodo_id}/files/{self.filename}"

        filepath = dl_manager.download([url])[0]        
        shutil.copy(filepath, os.getcwd())
        os.rename(os.path.basename(filepath), self.filename)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "filepath": filepath,
                },
            ),
        ]

    def _generate_examples(self, filepath):
        yield 0, {"path": filepath}