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
from pathlib import Path
|
| 2 |
+
from typing import Dict, List, Tuple
|
| 3 |
+
|
| 4 |
+
import datasets
|
| 5 |
+
|
| 6 |
+
from seacrowd.utils import schemas
|
| 7 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 8 |
+
from seacrowd.utils.constants import (DEFAULT_SEACROWD_VIEW_NAME,
|
| 9 |
+
DEFAULT_SOURCE_VIEW_NAME, Licenses,
|
| 10 |
+
Tasks)
|
| 11 |
+
|
| 12 |
+
_DATASETNAME = "palito"
|
| 13 |
+
_SOURCE_VIEW_NAME = DEFAULT_SOURCE_VIEW_NAME
|
| 14 |
+
_UNIFIED_VIEW_NAME = DEFAULT_SEACROWD_VIEW_NAME
|
| 15 |
+
|
| 16 |
+
_CITATION = """
|
| 17 |
+
@inproceedings{dita-etal-2009-building,
|
| 18 |
+
title = "Building Online Corpora of {P}hilippine Languages",
|
| 19 |
+
author = "Dita, Shirley N. and
|
| 20 |
+
Roxas, Rachel Edita O. and
|
| 21 |
+
Inventado, Paul",
|
| 22 |
+
editor = "Kwong, Olivia",
|
| 23 |
+
booktitle = "Proceedings of the 23rd Pacific Asia Conference on Language, Information and Computation, Volume 2",
|
| 24 |
+
month = dec,
|
| 25 |
+
year = "2009",
|
| 26 |
+
address = "Hong Kong",
|
| 27 |
+
publisher = "City University of Hong Kong",
|
| 28 |
+
url = "https://aclanthology.org/Y09-2024",
|
| 29 |
+
pages = "646--653",
|
| 30 |
+
}
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
# We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
| 34 |
+
_LANGUAGES = ["bik", "ceb", "hil", "ilo", "tgl", "pam", "pag", "war"]
|
| 35 |
+
_LANG_CONFIG = {
|
| 36 |
+
"bik": "Bikol",
|
| 37 |
+
"ceb": "Cebuano",
|
| 38 |
+
"hil": "Hiligaynon",
|
| 39 |
+
"ilo": "Ilocano",
|
| 40 |
+
"tgl": "Tagalog",
|
| 41 |
+
"pam": "Kapampangan",
|
| 42 |
+
"pag": "Pangasinense",
|
| 43 |
+
"war": "Waray",
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
_LOCAL = False
|
| 47 |
+
|
| 48 |
+
_DESCRIPTION = """\
|
| 49 |
+
This paper aims at describing the building of the online corpora on Philippine
|
| 50 |
+
languages as part of the online repository system called Palito. There are five components
|
| 51 |
+
of the corpora: the top four major Philippine languages which are Tagalog, Cebuano,
|
| 52 |
+
Ilocano and Hiligaynon and the Filipino Sign Language (FSL). The four languages are
|
| 53 |
+
composed of 250,000-word written texts each, whereas the FSL is composed of seven
|
| 54 |
+
thousand signs in video format. Categories of the written texts include creative writing (such
|
| 55 |
+
as novels and stories) and religious texts (such as the Bible). Automated tools are provided
|
| 56 |
+
for language analysis such as word count, collocates, and others. This is part of a bigger
|
| 57 |
+
corpora building project for Philippine languages that would consider text, speech and
|
| 58 |
+
video forms, and the corresponding development of automated tools for language analysis
|
| 59 |
+
of these various forms.
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
_HOMEPAGE = "https://github.com/imperialite/Philippine-Languages-Online-Corpora/tree/master/PALITO%20Corpus"
|
| 63 |
+
|
| 64 |
+
_LICENSE = Licenses.LGPL.value
|
| 65 |
+
|
| 66 |
+
_SUPPORTED_TASKS = [Tasks.SELF_SUPERVISED_PRETRAINING]
|
| 67 |
+
|
| 68 |
+
_SOURCE_VERSION = "1.0.0"
|
| 69 |
+
|
| 70 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 71 |
+
|
| 72 |
+
_URLS = {
|
| 73 |
+
"literary": "https://raw.githubusercontent.com/imperialite/Philippine-Languages-Online-Corpora/master/PALITO%20Corpus/Data/{lang}_Literary_Text.txt",
|
| 74 |
+
"religious": "https://raw.githubusercontent.com/imperialite/Philippine-Languages-Online-Corpora/master/PALITO%20Corpus/Data/{lang}_Religious_Text.txt",
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class PalitoDataset(datasets.GeneratorBasedBuilder):
|
| 79 |
+
"""Palito corpus"""
|
| 80 |
+
|
| 81 |
+
subsets = [f"{_DATASETNAME}_{lang}" for lang in _LANGUAGES]
|
| 82 |
+
|
| 83 |
+
BUILDER_CONFIGS = [
|
| 84 |
+
SEACrowdConfig(
|
| 85 |
+
name="{sub}_source".format(sub=subset),
|
| 86 |
+
version=datasets.Version(_SOURCE_VERSION),
|
| 87 |
+
description="Palito {sub} source schema".format(sub=subset),
|
| 88 |
+
schema="source",
|
| 89 |
+
subset_id="{sub}".format(sub=subset),
|
| 90 |
+
)
|
| 91 |
+
for subset in subsets
|
| 92 |
+
] + [
|
| 93 |
+
SEACrowdConfig(
|
| 94 |
+
name="{sub}_seacrowd_ssp".format(sub=subset),
|
| 95 |
+
version=datasets.Version(_SEACROWD_VERSION),
|
| 96 |
+
description="Palito {sub} SEACrowd schema".format(sub=subset),
|
| 97 |
+
schema="seacrowd_ssp",
|
| 98 |
+
subset_id="{sub}".format(sub=subset),
|
| 99 |
+
)
|
| 100 |
+
for subset in subsets
|
| 101 |
+
]
|
| 102 |
+
|
| 103 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 104 |
+
if self.config.schema == "source":
|
| 105 |
+
features = datasets.Features(
|
| 106 |
+
{
|
| 107 |
+
"id": datasets.Value("string"),
|
| 108 |
+
"text": datasets.Value("string"),
|
| 109 |
+
}
|
| 110 |
+
)
|
| 111 |
+
elif self.config.schema == "seacrowd_ssp":
|
| 112 |
+
features = schemas.self_supervised_pretraining.features
|
| 113 |
+
else:
|
| 114 |
+
raise ValueError(f"Invalid config schema: {self.config.schema}")
|
| 115 |
+
|
| 116 |
+
return datasets.DatasetInfo(
|
| 117 |
+
description=_DESCRIPTION,
|
| 118 |
+
features=features,
|
| 119 |
+
homepage=_HOMEPAGE,
|
| 120 |
+
license=_LICENSE,
|
| 121 |
+
citation=_CITATION,
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 125 |
+
lang = self.config.name.split("_")[1]
|
| 126 |
+
filepaths = [Path(dl_manager.download(_URLS["literary"].format(lang=_LANG_CONFIG[lang]))), Path(dl_manager.download(_URLS["religious"].format(lang=_LANG_CONFIG[lang])))]
|
| 127 |
+
|
| 128 |
+
return [
|
| 129 |
+
datasets.SplitGenerator(
|
| 130 |
+
name=datasets.Split.TRAIN,
|
| 131 |
+
gen_kwargs={"filepaths": filepaths},
|
| 132 |
+
),
|
| 133 |
+
]
|
| 134 |
+
|
| 135 |
+
def _generate_examples(self, filepaths: list[Path]) -> Tuple[int, Dict]:
|
| 136 |
+
counter = 0
|
| 137 |
+
for path in filepaths:
|
| 138 |
+
with open(path, encoding="utf-8") as f:
|
| 139 |
+
for line in f.readlines():
|
| 140 |
+
if line.strip() == "":
|
| 141 |
+
continue
|
| 142 |
+
|
| 143 |
+
if self.config.schema == "source":
|
| 144 |
+
yield (
|
| 145 |
+
counter,
|
| 146 |
+
{
|
| 147 |
+
"id": str(counter),
|
| 148 |
+
"text": line.strip(),
|
| 149 |
+
},
|
| 150 |
+
)
|
| 151 |
+
elif self.config.schema == "seacrowd_ssp":
|
| 152 |
+
yield (
|
| 153 |
+
counter,
|
| 154 |
+
{
|
| 155 |
+
"id": str(counter),
|
| 156 |
+
"text": line.strip(),
|
| 157 |
+
},
|
| 158 |
+
)
|
| 159 |
+
|
| 160 |
+
counter += 1
|