| 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": |
| features = datasets.Features( |
| { |
| "hero1": datasets.Value("string"), |
| "hero2": datasets.Value("string"), |
| "counts": datasets.Value("int64") |
| |
| } |
| ) |
| else: |
| features = datasets.Features( |
| { |
| "hero1": datasets.Value("string"), |
| "hero2": datasets.Value("string"), |
| "comic": datasets.Value("string") |
| |
| } |
| ) |
| 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"], |
| } |