Upload malindo_morph.py with huggingface_hub
Browse files- malindo_morph.py +124 -0
malindo_morph.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from typing import Dict, List, Tuple
|
| 3 |
+
|
| 4 |
+
import datasets
|
| 5 |
+
|
| 6 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
| 7 |
+
from seacrowd.utils.constants import Licenses
|
| 8 |
+
|
| 9 |
+
_CITATION = """\
|
| 10 |
+
@InProceedings{NOMOTO18.8,
|
| 11 |
+
author = {Hiroki Nomoto ,Hannah Choi ,David Moeljadi and Francis Bond},
|
| 12 |
+
title = {MALINDO Morph: Morphological dictionary and analyser for Malay/Indonesian},
|
| 13 |
+
booktitle = {Proceedings of the Eleventh International Conference on Language Resources and Evaluation (LREC 2018)},
|
| 14 |
+
year = {2018},
|
| 15 |
+
month = {may},
|
| 16 |
+
date = {7-12},
|
| 17 |
+
location = {Miyazaki, Japan},
|
| 18 |
+
editor = {Kiyoaki Shirai},
|
| 19 |
+
publisher = {European Language Resources Association (ELRA)},
|
| 20 |
+
address = {Paris, France},
|
| 21 |
+
isbn = {979-10-95546-24-5},
|
| 22 |
+
language = {english}
|
| 23 |
+
}
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
_DATASETNAME = "malindo_morph"
|
| 28 |
+
|
| 29 |
+
_DESCRIPTION = """\
|
| 30 |
+
MALINDO Morph is a morphological dictionary for Malay (bahasa Melayu) and Indonesian (bahasa Indonesia) language.
|
| 31 |
+
It contains over 200,000 lines, with each containing an analysis for one (case-sensitive) token.
|
| 32 |
+
Each line is made up of the following six items, separated by tabs: root, surface form, prefix, suffix, circumfix, reduplication.
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
_HOMEPAGE = "https://github.com/matbahasa/MALINDO_Morph"
|
| 36 |
+
|
| 37 |
+
_LANGUAGES = ["zlm", "ind"] # We follow ISO639-3 language code (https://iso639-3.sil.org/code_tables/639/data)
|
| 38 |
+
|
| 39 |
+
_LICENSE = Licenses.CC_BY_4_0.value # example: Licenses.MIT.value, Licenses.CC_BY_NC_SA_4_0.value, Licenses.UNLICENSE.value, Licenses.UNKNOWN.value
|
| 40 |
+
|
| 41 |
+
_LOCAL = False
|
| 42 |
+
|
| 43 |
+
_URLS = {
|
| 44 |
+
_DATASETNAME: "https://raw.githubusercontent.com/matbahasa/MALINDO_Morph/master/malindo_dic_2023.tsv",
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
_SUPPORTED_TASKS = []
|
| 48 |
+
|
| 49 |
+
_SOURCE_VERSION = "2023.0.0"
|
| 50 |
+
|
| 51 |
+
_SEACROWD_VERSION = "2024.06.20"
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class MalindoMorph(datasets.GeneratorBasedBuilder):
|
| 55 |
+
"""MALINDO Morph is a morphological dictionary for Malay (bahasa Melayu) and Indonesian (bahasa Indonesia) language. It provides morphological information (root, prefix, suffix, circumfix, reduplication) for over 200,000 surface forms."""
|
| 56 |
+
|
| 57 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 58 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
| 59 |
+
|
| 60 |
+
BUILDER_CONFIGS = [
|
| 61 |
+
SEACrowdConfig(
|
| 62 |
+
name=f"{_DATASETNAME}_source",
|
| 63 |
+
version=SOURCE_VERSION,
|
| 64 |
+
description=f"{_DATASETNAME} source schema",
|
| 65 |
+
schema="source",
|
| 66 |
+
subset_id=f"{_DATASETNAME}",
|
| 67 |
+
),
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
| 71 |
+
|
| 72 |
+
def _info(self) -> datasets.DatasetInfo:
|
| 73 |
+
if self.config.schema == "source":
|
| 74 |
+
features = datasets.Features(
|
| 75 |
+
{
|
| 76 |
+
"id": datasets.Value("string"),
|
| 77 |
+
"root": datasets.Value("string"),
|
| 78 |
+
"bentuk_jadian": datasets.Value("string"),
|
| 79 |
+
"prefix": datasets.Value("string"),
|
| 80 |
+
"suffix": datasets.Value("string"),
|
| 81 |
+
"circumfix": datasets.Value("string"),
|
| 82 |
+
"reduplication": datasets.Value("string"),
|
| 83 |
+
"source": datasets.Value("string"),
|
| 84 |
+
"stem": datasets.Value("string"),
|
| 85 |
+
"lemma": datasets.Value("string"),
|
| 86 |
+
}
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
return datasets.DatasetInfo(
|
| 90 |
+
description=_DESCRIPTION,
|
| 91 |
+
features=features,
|
| 92 |
+
homepage=_HOMEPAGE,
|
| 93 |
+
license=_LICENSE,
|
| 94 |
+
citation=_CITATION,
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
| 98 |
+
"""Returns SplitGenerators."""
|
| 99 |
+
urls = _URLS[_DATASETNAME]
|
| 100 |
+
file = dl_manager.download_and_extract(urls)
|
| 101 |
+
|
| 102 |
+
return [
|
| 103 |
+
datasets.SplitGenerator(
|
| 104 |
+
name=datasets.Split.TRAIN,
|
| 105 |
+
gen_kwargs={
|
| 106 |
+
"filepath": file,
|
| 107 |
+
"split": "train",
|
| 108 |
+
},
|
| 109 |
+
)
|
| 110 |
+
]
|
| 111 |
+
|
| 112 |
+
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
|
| 113 |
+
"""Yields examples as (key, example) tuples."""
|
| 114 |
+
rows = []
|
| 115 |
+
with open(filepath, encoding="utf8") as file:
|
| 116 |
+
for line in file:
|
| 117 |
+
row = line.split("\t")
|
| 118 |
+
row[-1] = row[-1].split("\n")[0] # remove newlines from lemma feature
|
| 119 |
+
rows.append(row)
|
| 120 |
+
|
| 121 |
+
if self.config.schema == "source":
|
| 122 |
+
for key, row in enumerate(rows):
|
| 123 |
+
example = {"id": row[0], "root": row[1], "bentuk_jadian": row[2], "prefix": row[3], "suffix": row[4], "circumfix": row[5], "reduplication": row[6], "source": row[7], "stem": row[8], "lemma": row[9]}
|
| 124 |
+
yield key, example
|