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, }