Datasets:
File size: 5,649 Bytes
00cf3cb 87d13fc 00cf3cb f83c122 00cf3cb 1b91f37 00cf3cb 1b91f37 00cf3cb 1b91f37 00cf3cb |
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# coding=utf-8
# Copyright 2020 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.
"""Sentiment lexicons for 81 languages generated via graph propagation based on a knowledge graph--a graphical representation of real-world entities and the links between them"""
import os
import datasets
_CITATION = """\
@inproceedings{inproceedings,
author = {Chen, Yanqing and Skiena, Steven},
year = {2014},
month = {06},
pages = {383-389},
title = {Building Sentiment Lexicons for All Major Languages},
volume = {2},
journal = {52nd Annual Meeting of the Association for Computational Linguistics, ACL 2014 - Proceedings of the Conference},
doi = {10.3115/v1/P14-2063}
}
"""
_DESCRIPTION = """\
This dataset add sentiment lexicons for 81 languages generated via graph propagation based on a knowledge graph--a graphical representation of real-world entities and the links between them.
"""
_HOMEPAGE = "https://sites.google.com/site/datascienceslab/projects/multilingualsentiment"
_LICENSE = "GNU General Public License v3"
_URLs = "https://www.kaggle.com/rtatman/sentiment-lexicons-for-81-languages"
LANGS = [
"af",
"an",
"ar",
"az",
"be",
"bg",
"bn",
"br",
"bs",
"ca",
"cs",
"cy",
"da",
"de",
"el",
"eo",
"es",
"et",
"eu",
"fa",
"fi",
"fo",
"fr",
"fy",
"ga",
"gd",
"gl",
"gu",
"he",
"hi",
"hr",
"ht",
"hu",
"hy",
"ia",
"id",
"io",
"is",
"it",
"ja",
"ka",
"km",
"kn",
"ko",
"ku",
"ky",
"la",
"lb",
"lt",
"lv",
"mk",
"mr",
"ms",
"mt",
"nl",
"nn",
"no",
"pl",
"pt",
"rm",
"ro",
"ru",
"sk",
"sl",
"sq",
"sr",
"sv",
"sw",
"ta",
"te",
"th",
"tk",
"tl",
"tr",
"uk",
"ur",
"uz",
"vi",
"vo",
"wa",
"yi",
"zh",
"zhw",
]
class SentiLex(datasets.GeneratorBasedBuilder):
"""Sentiment lexicons for 81 different languages"""
VERSION = datasets.Version("1.1.0")
@property
def manual_download_instructions(self):
return """\
You should download the dataset from https://www.kaggle.com/rtatman/sentiment-lexicons-for-81-languages
The webpage requires registration.
After downloading, please put the files in a dir of your choice,
which will be used as a manual_dir, e.g. `~/.manual_dirs/senti_lex`
SentiLex can then be loaded via:
`datasets.load_dataset("newsroom", data_dir="~/.manual_dirs/senti_lex")`.
"""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name=i,
version=datasets.Version("1.1.0"),
description=("Lexicon of positive and negative words for the " + i + " language"),
)
for i in LANGS
]
def _info(self):
features = datasets.Features(
{
"word": datasets.Value("string"),
"sentiment": datasets.ClassLabel(
names=[
"negative",
"positive",
]
),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_dir = os.path.abspath(os.path.expanduser(dl_manager.manual_dir))
if not os.path.exists(data_dir):
raise FileNotFoundError(
f"{data_dir} does not exist. Make sure you insert a manual dir via `datasets.load_dataset('newsroom', data_dir=...)` that includes files unzipped from the reclor zip. Manual download instructions: {self.manual_download_instructions}"
)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"data_dir": data_dir,
},
),
]
def _generate_examples(self, data_dir):
"""Yields examples."""
filepaths = [
os.path.join(data_dir, "sentiment-lexicons", "negative_words_" + self.config.name + ".txt"),
os.path.join(data_dir, "sentiment-lexicons", "positive_words_" + self.config.name + ".txt"),
]
for file_idx, filepath in enumerate(filepaths):
with open(filepath, encoding="utf-8") as f:
for id_, line in enumerate(f):
if "negative" in filepath:
yield f"{file_idx}_{id_}", {
"word": line.strip(" \n"),
"sentiment": "negative",
}
elif "positive" in filepath:
yield f"{file_idx}_{id_}", {
"word": line.strip(" \n"),
"sentiment": "positive",
}
|