| import os | |
| import datasets | |
| logger = datasets.logging.get_logger(__name__) | |
| ID_POOL = ("default", "origin") | |
| URL = "https://huggingface.co/datasets/thewall/Aptani2Param/resolve/main" | |
| class Aptani2ParamConfig(datasets.BuilderConfig): | |
| pass | |
| class Aptani2Param(datasets.GeneratorBasedBuilder): | |
| BUILDER_CONFIGS = [ | |
| Aptani2ParamConfig(name=key) for key in ID_POOL | |
| ] | |
| DEFAULT_CONFIG_NAME = "default" | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| features=datasets.Features( | |
| { | |
| "config": datasets.Value("string"), | |
| "existed": datasets.Value("bool"), | |
| "file_num": datasets.Value("int32"), | |
| } | |
| ), | |
| homepage="http://aptani.unimore.it/", | |
| ) | |
| def _split_generators(self, dl_manager): | |
| aptani2_url = f"{URL}/{self.config.name}.tar.gz" | |
| downloaded_files = [os.path.join(f"{dl_manager.download_and_extract(aptani2_url)}", self.config.name)] | |
| return [ | |
| datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files}), | |
| ] | |
| def _generate_examples(self, filepath): | |
| """This function returns the examples in the raw (text) form.""" | |
| logger.info("generating examples from = %s", filepath) | |
| flag = True | |
| for file in filepath: | |
| flag = flag and os.path.exists(file) | |
| file_num = len(os.listdir(filepath[0])) | |
| yield 0, {"config": filepath[0], | |
| "existed": flag, | |
| "file_num": file_num, | |
| } | |
| if __name__=="__main__": | |
| from datasets import load_dataset | |
| dataset = load_dataset("aptani2param.py", split="all") | |