File size: 4,824 Bytes
fe4a01a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# coding=utf-8
# Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import csv
from pathlib import Path
from typing import Dict, List, Tuple
import datasets
from seacrowd.utils.configs import SEACrowdConfig
from seacrowd.utils.constants import Licenses
_CITATION = """\
@article{article,
author = {Borra, Allan and Pease, Adam and Edita, Rachel and Roxas, and Dita, Shirley},
year = {2010},
month = {01},
pages = {},
title = {Introducing Filipino WordNet}
}
"""
_DATASETNAME = "filwordnet"
_DESCRIPTION = """\
Filipino WordNet (FilWordNet) is a lexical database of Filipino language.
It was derived from the Princeton WordNet and translated by humans to Filipino.
It documents 13,539 unique words and 9,519 synsets. Each synset includes the definition,
part-of-speech, word senses, and Suggested Upper Merged Ontology terms (SUMO terms).
"""
_HOMEPAGE = "https://github.com/danjohnvelasco/Filipino-WordNet"
_LANGUAGES = ["fil"]
_LICENSE = Licenses.UNKNOWN.value
_LOCAL = False
_URLS = {
_DATASETNAME: "https://raw.githubusercontent.com/danjohnvelasco/Filipino-WordNet/main/filwordnet.csv",
}
_SUPPORTED_TASKS = []
_SOURCE_VERSION = "1.0.0"
_SEACROWD_VERSION = "2024.06.20"
class FilWordNetDataset(datasets.GeneratorBasedBuilder):
"""The Filipino WordNet (FilWordNet) is a lexical database of Filipino language containing 13,539 unique words and 9,519 synsets."""
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
BUILDER_CONFIGS = [
SEACrowdConfig(
name=f"{_DATASETNAME}_source",
version=SOURCE_VERSION,
description=f"{_DATASETNAME} source schema",
schema="source",
subset_id=f"{_DATASETNAME}",
)
]
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
def _info(self) -> datasets.DatasetInfo:
if self.config.schema == "source":
features = datasets.Features(
{
"word_id": datasets.Value("int32"),
"lemma": datasets.Value("string"),
"synset_id": datasets.Value("int32"),
"sense_id": datasets.Value("int32"),
"pos": datasets.Value("string"),
"lexdomain_id": datasets.Value("int32"),
"definition": datasets.Value("string"),
"last_modifier": datasets.Value("int32"),
"sumo": datasets.Value("string"),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
"""Returns SplitGenerators."""
urls = _URLS[_DATASETNAME]
file = dl_manager.download_and_extract(urls)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"filepath": file,
"split": "train",
},
)
]
def _generate_examples(self, filepath: Path, split: str) -> Tuple[int, Dict]:
"""Yields examples as (key, example) tuples."""
rows = []
is_first_row = True
with open(filepath, "r") as file:
csv_reader = csv.reader(file, delimiter=",")
for row in csv_reader:
if is_first_row: # skip first row, they are column names
is_first_row = False
continue
rows.append(row)
if self.config.schema == "source":
for key, row in enumerate(rows):
example = {
"word_id": row[0],
"lemma": row[1],
"synset_id": row[2],
"sense_id": row[3],
"pos": row[4],
"lexdomain_id": row[5],
"definition": row[6],
"last_modifier": row[7],
"sumo": row[8],
}
yield key, example
|