| import csv |
| import os |
|
|
| import datasets |
|
|
| _CITATION = """\ |
| @Dataset{wisdomify:storyteller, |
| title = {Korean proverb definitions and examples}, |
| author={Jongyoon Kim, Yubin Kim, Yongtaek Im |
| }, |
| year={2021} |
| } |
| """ |
|
|
| _DESCRIPTION = """\ |
| This dataset is designed to provide forward and reverse dictionary of Korean proverbs. |
| """ |
|
|
| |
| _HOMEPAGE = "" |
|
|
| |
| _LICENSE = "" |
|
|
| |
| |
| _URLs = { |
| 'definition': "https://www.dropbox.com/s/4uh564afaimtob3/definition.zip?dl=1", |
| 'example': "https://www.dropbox.com/s/adlt9n6x5gjs0a6/example.zip?dl=1", |
| } |
|
|
|
|
| class Story(datasets.GeneratorBasedBuilder): |
| |
| VERSION = datasets.Version("0.0.0") |
|
|
| BUILDER_CONFIGS = [ |
| datasets.BuilderConfig(name="definition", version=VERSION, description="definition"), |
| datasets.BuilderConfig(name="example", version=VERSION, description="example"), |
| ] |
|
|
| |
| DEFAULT_CONFIG_NAME = "definition" |
|
|
| def _info(self): |
| |
| |
|
|
| if self.config.name == "definition": |
| |
| features = datasets.Features( |
| { |
| "wisdom": datasets.Value("string"), |
| "def": datasets.Value("string"), |
|
|
| } |
| ) |
| elif self.config.name == "example": |
| features = datasets.Features( |
| { |
| "wisdom": datasets.Value("string"), |
| "eg": datasets.Value("string"), |
| } |
| ) |
| else: |
| raise NotImplementedError(f"Wrong name: {self.config.name}") |
|
|
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| supervised_keys=None, |
| homepage=_HOMEPAGE, |
| license=_LICENSE, |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| """Returns SplitGenerators.""" |
| |
| |
| |
|
|
| |
| downloaded_files = dl_manager.download_and_extract(_URLs[self.config.name]) |
|
|
| dtp = 'def' if self.config.name == "definition" else 'eg' |
|
|
| train_path = os.path.join(downloaded_files, f'train_wisdom2{dtp}.tsv') |
| val_path = os.path.join(downloaded_files, f'val_wisdom2{dtp}.tsv') |
| test_path = os.path.join(downloaded_files, f'test_wisdom2{dtp}.tsv') |
|
|
| return [ |
| |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={"filepath": train_path, "split": "train"}, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.VALIDATION, |
| gen_kwargs={"filepath": val_path, "split": "validation"}, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| gen_kwargs={"filepath": test_path, "split": "test"}, |
| ), |
| ] |
|
|
| def _generate_examples(self, filepath, split): |
| |
| """ Yields examples as (key, example) tuples. """ |
| |
| |
|
|
| with open(filepath, encoding="utf-8") as f: |
| tsv_reader = csv.reader(f, delimiter="\t") |
| for id_, row in enumerate(tsv_reader): |
| if id_ == 0: |
| continue |
|
|
| if self.config.name == "definition": |
| yield id_, { |
| "wisdom": row[0], |
| "def": row[1], |
| } |
| elif self.config.name == "example": |
| yield id_, { |
| "wisdom": row[0], |
| "eg": row[1], |
| } |
| else: |
| raise NotImplementedError(f"Wrong name: {self.config.name}") |
|
|