File size: 3,521 Bytes
c5005c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
94
95
96
97
98
99
100
101
102
103
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/file/d/1wcINfLn25tMIVJcp6MtxSNR7QNF8GI_D/view?usp=sharing",
    "hero_hero_comic": "https://drive.google.com/file/d/1wel0zjoa8GvBo255dlX7cVOPF9XbvQrI/view?usp=sharing",
}

class NCEducationDataset(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("int64")
                  # 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):
        data = {}
        with open(filepath, "r", encoding="utf-8") as file:
          csv_reader = csv.DictReader(file)
          for row in csv_reader:
            if self.config.name == "adjacency_list":
              hero1 = row["hero1"]
              hero2 = row["hero2"]
              counts = int(row["counts"])
            else:
              hero1 = row["hero1"]
              hero2 = row["hero2"]
              comic = row["comic"]

        for idx, (area_name, area_data) in enumerate(data.items()):
          if self.config.name == "adjacency_list":
            yield idx, {
                "hero1": hero1,
                "hero2": hero2,
                "counts": counts,
            }
          else:
            yield idx, {
                "hero1": hero1,
                "hero2": hero2,
                "comic": comic,
            }