mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-08-15 01:39:32 +02:00
Feature/ner (#103)
NER und Sentiment-Pipeline mit Services zur Datenextraktion. --------- Co-authored-by: Philipp Horstenkamp <philipp@horstenkamp.de> Co-authored-by: TrisNol <tristan.nolde@yahoo.de>
This commit is contained in:
78
tests/utils/mongo/sentiment_service_test.py
Normal file
78
tests/utils/mongo/sentiment_service_test.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""Tests for checking Sentiment Services."""
|
||||
|
||||
|
||||
from aki_prj23_transparenzregister.utils.mongo.sentiment_service import (
|
||||
SentimentAnalysisService,
|
||||
)
|
||||
|
||||
|
||||
def test_sentiment_service_with_spacy_pos() -> None:
|
||||
"""Mock testing spaCy Sentiment Service with positive sentiment."""
|
||||
# Init SentimentAnalysisService with spaCy
|
||||
sentiment_service = SentimentAnalysisService(use_spacy=True)
|
||||
|
||||
# run the test
|
||||
text = "Dies ist ein großartiger Test. Ich liebe es!"
|
||||
sentiment, score = sentiment_service.sentiment_spacy(text)
|
||||
assert sentiment == "positive"
|
||||
assert score > 0
|
||||
|
||||
|
||||
def test_sentiment_service_with_spacy_neg() -> None:
|
||||
"""Mock testing spaCy Sentiment Service with negative sentiment."""
|
||||
# Init SentimentAnalysisService with spaCy
|
||||
sentiment_service = SentimentAnalysisService(use_spacy=True)
|
||||
|
||||
# run the test
|
||||
text = "Dies ist ein wirklich schrecklicher Test. Ich hasse ihn!"
|
||||
sentiment, score = sentiment_service.sentiment_spacy(text)
|
||||
assert sentiment == "negative"
|
||||
assert score > 0
|
||||
|
||||
|
||||
def test_sentiment_service_with_spacy_neut() -> None:
|
||||
"""Mock testing spaCy Sentiment Service with neutral sentiment."""
|
||||
# Init SentimentAnalysisService with spaCy
|
||||
sentiment_service = SentimentAnalysisService(use_spacy=True)
|
||||
|
||||
# run the test
|
||||
text = "Dies ist ein Test."
|
||||
sentiment, score = sentiment_service.sentiment_spacy(text)
|
||||
assert sentiment == "neutral"
|
||||
assert score >= 0
|
||||
|
||||
|
||||
def test_sentiment_service_with_transformer_pos() -> None:
|
||||
"""Mock testing Transformer Sentiment Service with positive Sentiment."""
|
||||
# Init SentimentAnalysisService with Transformer
|
||||
sentiment_service = SentimentAnalysisService(use_transformer=True)
|
||||
|
||||
# run the test
|
||||
text = "Dies ist ein großartiger Test. Ich liebe es!"
|
||||
sentiment, score = sentiment_service.sentiment_transformer(text)
|
||||
assert sentiment == "positive"
|
||||
assert score > 0
|
||||
|
||||
|
||||
def test_sentiment_service_with_transformer_neg() -> None:
|
||||
"""Mock testing Transformer Sentiment Service with negative Sentiment."""
|
||||
# Init SentimentAnalysisService with Transformer
|
||||
sentiment_service = SentimentAnalysisService(use_transformer=True)
|
||||
|
||||
# run the test
|
||||
text = "Dies ist ein wirklich schrecklicher Test. Ich hasse ihn!"
|
||||
sentiment, score = sentiment_service.sentiment_transformer(text)
|
||||
assert sentiment == "negative"
|
||||
assert score > 0
|
||||
|
||||
|
||||
def test_sentiment_service_with_transformer_neut() -> None:
|
||||
"""Mock testing Transformer Sentiment Service with neutral Sentiment."""
|
||||
# Init SentimentAnalysisService with Transformer
|
||||
sentiment_service = SentimentAnalysisService(use_transformer=True)
|
||||
|
||||
# run the test
|
||||
text = "Das ist ein Text, ohne besondere Stimmung."
|
||||
sentiment, score = sentiment_service.sentiment_transformer(text)
|
||||
assert sentiment == "neutral"
|
||||
assert score >= 0
|
Reference in New Issue
Block a user