| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| """SentiWS: German-language resource for sentiment analysis, pos-tagging""" |
|
|
|
|
| import os |
|
|
| import datasets |
|
|
|
|
| _CITATION = """\ |
| @INPROCEEDINGS{remquahey2010, |
| title = {SentiWS -- a Publicly Available German-language Resource for Sentiment Analysis}, |
| booktitle = {Proceedings of the 7th International Language Resources and Evaluation (LREC'10)}, |
| author = {Remus, R. and Quasthoff, U. and Heyer, G.}, |
| year = {2010} |
| } |
| """ |
|
|
| _DESCRIPTION = """\ |
| SentimentWortschatz, or SentiWS for short, is a publicly available German-language resource for sentiment analysis, and pos-tagging. The POS tags are ["NN", "VVINF", "ADJX", "ADV"] -> ["noun", "verb", "adjective", "adverb"], and positive and negative polarity bearing words are weighted within the interval of [-1, 1]. |
| """ |
|
|
| _HOMEPAGE = "" |
|
|
| _LICENSE = "Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License" |
|
|
| _URLs = ["https://pcai056.informatik.uni-leipzig.de/downloads/etc/SentiWS/SentiWS_v2.0.zip"] |
|
|
|
|
| class SentiWS(datasets.GeneratorBasedBuilder): |
| """SentiWS: German-language resource for sentiment analysis, pos-tagging""" |
|
|
| VERSION = datasets.Version("1.1.0") |
|
|
| BUILDER_CONFIGS = [ |
| datasets.BuilderConfig(name="pos-tagging", version=VERSION, description="This covers pos-tagging task"), |
| datasets.BuilderConfig( |
| name="sentiment-scoring", |
| version=VERSION, |
| description="This covers the sentiment-scoring in [-1, 1] corresponding to (negative, positive) sentiment", |
| ), |
| ] |
|
|
| DEFAULT_CONFIG_NAME = "pos-tagging" |
|
|
| def _info(self): |
|
|
| if ( |
| self.config.name == "pos-tagging" |
| ): |
| features = datasets.Features( |
| { |
| "word": datasets.Value("string"), |
| "pos-tag": datasets.ClassLabel(names=["NN", "VVINF", "ADJX", "ADV"]), |
| } |
| ) |
| else: |
| features = datasets.Features( |
| { |
| "word": datasets.Value("string"), |
| "sentiment-score": datasets.Value("float32"), |
| } |
| ) |
| return datasets.DatasetInfo( |
| |
| description=_DESCRIPTION, |
| |
| features=features, |
| |
| |
| |
| supervised_keys=None, |
| |
| homepage=_HOMEPAGE, |
| |
| license=_LICENSE, |
| |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| """Returns SplitGenerators.""" |
| |
| |
|
|
| |
| |
| |
| my_urls = _URLs |
| data_dir = dl_manager.download_and_extract(my_urls) |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| |
| gen_kwargs={ |
| "sourcefiles": [ |
| os.path.join(data_dir[0], f) |
| for f in ["SentiWS_v2.0_Positive.txt", "SentiWS_v2.0_Negative.txt"] |
| ], |
| "split": "train", |
| }, |
| ), |
| ] |
|
|
| def _generate_examples(self, sourcefiles, split): |
| """Yields examples.""" |
| |
| |
| |
| for file_idx, filepath in enumerate(sourcefiles): |
| with open(filepath, encoding="utf-8") as f: |
| for id_, row in enumerate(f): |
| word = row.split("|")[0] |
| if self.config.name == "pos-tagging": |
| tag = row.split("|")[1].split("\t")[0] |
| yield f"{file_idx}_{id_}", {"word": word, "pos-tag": tag} |
| else: |
| sentiscore = row.split("|")[1].split("\t")[1] |
| yield f"{file_idx}_{id_}", {"word": word, "sentiment-score": float(sentiscore)} |
|
|