|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""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" |
|
|
|
|
|
_URL = "data.zip" |
|
|
|
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") |
|
|
|
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 = dl_manager.download_and_extract(_URL) |
|
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", |
|
} |
|
|