File size: 3,353 Bytes
95b2b6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02b0218
 
95b2b6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02b0218
95b2b6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02b0218
95b2b6e
 
 
02b0218
95b2b6e
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import csv
import os
import datasets

_DESCRIPTION = """
This is a dataset for Marvel universe social network, which contains the relationships between Marvel heroes.
"""
_CITATION = """\
@article{alberich2002marvel,
  title={Marvel Universe looks almost like a real social network},
  author={Alberich, Ricardo and Miro-Julia, Joe and Rossell{\'o}, Francesc},
  journal={arXiv preprint cond-mat/0202174},
  year={2002}
}
"""

_HOMEPAGE = "https://huggingface.co/datasets/ShimizuYuki/Marvel_network"

_LICENSE = "afl-3.0"

_URLS = {
    "adjacency_list": "https://drive.google.com/uc?id=1wcINfLn25tMIVJcp6MtxSNR7QNF8GI_D",
    "hero_hero_comic": "https://drive.google.com/uc?id=1wel0zjoa8GvBo255dlX7cVOPF9XbvQrI",
}

class Marvel(datasets.GeneratorBasedBuilder):

    VERSION = datasets.Version("1.0.1")

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name="adjacency_list", version=VERSION, description="This is a adjacency list for this network"),
        datasets.BuilderConfig(name="hero_hero_comic", version=VERSION, description="This adds comic imformation to adjacency list"),
    ]

    DEFAULT_CONFIG_NAME = "adjacency_list"

    def _info(self):
        if self.config.name == "adjacency_list":  # This is the name of the configuration selected in BUILDER_CONFIGS above
            features = datasets.Features(
                {
                    "hero1": datasets.Value("string"),
                    "hero2": datasets.Value("string"),
                    "counts": datasets.Value("int64")
                    # These are the features of your dataset like images, labels ...
                }
            )
        else:  # This is an example to show how to have different features for "first_domain" and "second_domain"
            features = datasets.Features(
                {
                    "hero1": datasets.Value("string"),
                    "hero2": datasets.Value("string"),
                    "comic": datasets.Value("string")
                    # These are the features of your dataset like images, labels ...
                }
            )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )


    def _split_generators(self, dl_manager):
        urls = _URLS[self.config.name]
        data_file = dl_manager.download(urls)
        return [
            datasets.SplitGenerator(
                name = "train",
                gen_kwargs = {
                    "filepath": data_file,
                },
            )
        ]

    def _generate_examples(self, filepath):
        """Generates examples as dictionaries."""
        with open(filepath, encoding="utf-8") as csv_file:
            reader = csv.DictReader(csv_file)
            for id_, row in enumerate(reader):
                if self.config.name == "adjacency_list":
                    yield id_, {
                        "hero1": row["hero1"],
                        "hero2": row["hero2"],
                        "counts": int(row["counts"]),
                    }
                else:
                    yield id_, {
                        "hero1": row["hero1"],
                        "hero2": row["hero2"],
                        "comic": row["comic"],
                    }