holylovenia
commited on
Commit
•
a5859f0
1
Parent(s):
bc653c1
Upload id_frog_story.py with huggingface_hub
Browse files- id_frog_story.py +130 -0
id_frog_story.py
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from pathlib import Path
|
3 |
+
from typing import List
|
4 |
+
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
from nusacrowd.utils import schemas
|
8 |
+
from nusacrowd.utils.configs import NusantaraConfig
|
9 |
+
from nusacrowd.utils.constants import Tasks
|
10 |
+
|
11 |
+
_CITATION = """\
|
12 |
+
@article{FrogStorytelling,
|
13 |
+
author="Moeljadi, David",
|
14 |
+
title="Usage of Indonesian Possessive Verbal Predicates : A Statistical Analysis Based on Storytelling Survey",
|
15 |
+
journal="Tokyo University Linguistic Papers",
|
16 |
+
ISSN="1345-8663",
|
17 |
+
publisher="東京大学大学院人文社会系研究科・文学部言語学研究室",
|
18 |
+
year="2014",
|
19 |
+
month="sep",
|
20 |
+
volume="35",
|
21 |
+
number="",
|
22 |
+
pages="155-176",
|
23 |
+
URL="https://ci.nii.ac.jp/naid/120005525793/en/",
|
24 |
+
DOI="info:doi/10.15083/00027472",
|
25 |
+
}
|
26 |
+
"""
|
27 |
+
_DATASETNAME = "id_frog_story"
|
28 |
+
_DESCRIPTION = """\
|
29 |
+
Indonesian Frog Storytelling Corpus
|
30 |
+
Indonesian written and spoken corpus, based on the twenty-eight pictures. (http://compling.hss.ntu.edu.sg/who/david/corpus/pictures.pdf)
|
31 |
+
"""
|
32 |
+
_HOMEPAGE = "https://github.com/matbahasa/corpus-frog-storytelling"
|
33 |
+
_LANGUAGES = ["ind"]
|
34 |
+
_LICENSE = "Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)"
|
35 |
+
_LOCAL = False
|
36 |
+
_URLS = {
|
37 |
+
_DATASETNAME: "https://github.com/matbahasa/corpus-frog-storytelling/archive/refs/heads/master.zip",
|
38 |
+
}
|
39 |
+
_SUPPORTED_TASKS = [Tasks.SELF_SUPERVISED_PRETRAINING]
|
40 |
+
_SOURCE_VERSION = "1.0.0"
|
41 |
+
_NUSANTARA_VERSION = "1.0.0"
|
42 |
+
|
43 |
+
|
44 |
+
class IdFrogStory(datasets.GeneratorBasedBuilder):
|
45 |
+
"""IdFrogStory contains 13 spoken datasets and 11 written datasets"""
|
46 |
+
|
47 |
+
BUILDER_CONFIGS = [
|
48 |
+
NusantaraConfig(
|
49 |
+
name="id_frog_story_source",
|
50 |
+
version=datasets.Version(_SOURCE_VERSION),
|
51 |
+
description="IdFrogStory source schema",
|
52 |
+
schema="source",
|
53 |
+
subset_id="id_frog_story",
|
54 |
+
),
|
55 |
+
NusantaraConfig(
|
56 |
+
name="id_frog_story_nusantara_ssp",
|
57 |
+
version=datasets.Version(_NUSANTARA_VERSION),
|
58 |
+
description="IdFrogStory Nusantara schema",
|
59 |
+
schema="nusantara_ssp",
|
60 |
+
subset_id="id_frog_story",
|
61 |
+
),
|
62 |
+
]
|
63 |
+
|
64 |
+
DEFAULT_CONFIG_NAME = "id_frog_story_source"
|
65 |
+
|
66 |
+
def _info(self):
|
67 |
+
if self.config.schema == "source":
|
68 |
+
features = datasets.Features(
|
69 |
+
{
|
70 |
+
"id": datasets.Value("string"),
|
71 |
+
"text": datasets.Value("string"),
|
72 |
+
}
|
73 |
+
)
|
74 |
+
elif self.config.schema == "nusantara_ssp":
|
75 |
+
features = schemas.self_supervised_pretraining.features
|
76 |
+
|
77 |
+
return datasets.DatasetInfo(
|
78 |
+
description=_DESCRIPTION,
|
79 |
+
features=features,
|
80 |
+
homepage=_HOMEPAGE,
|
81 |
+
license=_LICENSE,
|
82 |
+
citation=_CITATION,
|
83 |
+
)
|
84 |
+
|
85 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
86 |
+
urls = _URLS[_DATASETNAME]
|
87 |
+
base_path = Path(dl_manager.download_and_extract(urls)) / "corpus-frog-storytelling-master" / "data"
|
88 |
+
spoken_path = base_path / "spoken"
|
89 |
+
written_path = base_path / "written"
|
90 |
+
|
91 |
+
data = []
|
92 |
+
for spoken_file_name in sorted(os.listdir(spoken_path)):
|
93 |
+
spoken_file_path = spoken_path / spoken_file_name
|
94 |
+
if os.path.isfile(spoken_file_path):
|
95 |
+
with open(spoken_file_path, "r") as fspoken:
|
96 |
+
data.extend(fspoken.read().strip("\n").split("\n\n"))
|
97 |
+
|
98 |
+
for written_file_name in sorted(os.listdir(written_path)):
|
99 |
+
written_file_path = written_path / written_file_name
|
100 |
+
if os.path.isfile(written_file_path):
|
101 |
+
with open(written_file_path, "r") as fwritten:
|
102 |
+
data.extend(fwritten.read().strip("\n").split("\n\n"))
|
103 |
+
|
104 |
+
return [
|
105 |
+
datasets.SplitGenerator(
|
106 |
+
name=datasets.Split.TRAIN,
|
107 |
+
gen_kwargs={
|
108 |
+
"data": data,
|
109 |
+
"split": "train",
|
110 |
+
},
|
111 |
+
),
|
112 |
+
]
|
113 |
+
|
114 |
+
def _generate_examples(self, data: List, split: str):
|
115 |
+
if self.config.schema == "source":
|
116 |
+
for index, row in enumerate(data):
|
117 |
+
ex = {
|
118 |
+
"id": index,
|
119 |
+
"text": row
|
120 |
+
}
|
121 |
+
yield index, ex
|
122 |
+
elif self.config.schema == "nusantara_ssp":
|
123 |
+
for index, row in enumerate(data):
|
124 |
+
ex = {
|
125 |
+
"id": index,
|
126 |
+
"text": row
|
127 |
+
}
|
128 |
+
yield index, ex
|
129 |
+
else:
|
130 |
+
raise ValueError(f"Invalid config: {self.config.name}")
|