"""SentiNews: Manually sentiment annotated Slovenian news corpus.""" import csv import datasets _CITATION = """\ @article{buvcar2018annotated, title={Annotated news corpora and a lexicon for sentiment analysis in Slovene}, author={Bu{\v{c}}ar, Jo{\v{z}}e and {\v{Z}}nidar{\v{s}}i{\v{c}}, Martin and Povh, Janez}, journal={Language Resources and Evaluation}, volume={52}, number={3}, pages={895--919}, year={2018}, publisher={Springer} } """ _DESCRIPTION = """\ SentiNews is a Slovenian sentiment classification dataset, consisting of news articles manually annotated with their sentiment by between 2 and 6 annotators. The news articles contain political, business, economic and financial content from the Slovenian news portals 24ur, Dnevnik, Finance, Rtvslo, and Žurnal24. The texts were annotated using the five-level Lickert scale (1 – very negative, 2 – negative, 3 – neutral, 4 – positive, and 5 – very positive) on three levels of granularity, i.e. on the document, paragraph, and sentence level. The final sentiment is determined using the following criterion: negative (if average of scores ≤ 2.4); neutral (if average of scores is between 2.4 and 3.6); positive (average of annotated scores ≥ 3.6). """ _HOMEPAGE = "https://github.com/19Joey85/Sentiment-annotated-news-corpus-and-sentiment-lexicon-in-Slovene/" _LICENSE = "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)" _URLS = { "document_level": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1110/SentiNews_document-level.txt", "paragraph_level": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1110/SentiNews_paragraph-level.txt", "sentence_level": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1110/SentiNews_sentence-level.txt" } class Sentinews(datasets.GeneratorBasedBuilder): """SentiNews: Manually sentiment annotated Slovenian news corpus. Version 1.0.""" VERSION = datasets.Version("1.0.0") BUILDER_CONFIGS = [ datasets.BuilderConfig(name="document_level", version=VERSION, description="Dataset annotated at document level."), datasets.BuilderConfig(name="paragraph_level", version=VERSION, description="Dataset annotated at paragraph level."), datasets.BuilderConfig(name="sentence_level", version=VERSION, description="Dataset annotated at sentence level."), ] def _info(self): _config_features = { "nid": datasets.Value("uint16"), "content": datasets.Value("string"), "sentiment": datasets.Value("string") } if self.config.name == "paragraph_level": _config_features["pid"] = datasets.Value("uint8") elif self.config.name == "sentence_level": _config_features["pid"] = datasets.Value("uint8") _config_features["sid"] = datasets.Value("uint8") features = datasets.Features(_config_features) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, supervised_keys=("content", "sentiment"), homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): urls = _URLS[self.config.name] data_file = dl_manager.download_and_extract(urls) return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"data_file": data_file})] def _generate_examples(self, data_file): _keys_to_return = ["nid", "content", "sentiment"] if self.config.name == "paragraph_level": _keys_to_return.append("pid") elif self.config.name == "sentence_level": _keys_to_return.append("pid") _keys_to_return.append("sid") with open(data_file, encoding="utf-8") as f: data = csv.DictReader(f, delimiter="\t") for idx, row in enumerate(data): yield idx, {_k: row[_k] for _k in _keys_to_return}