Update modules/analyzer.py
Browse files- modules/analyzer.py +25 -3
modules/analyzer.py
CHANGED
@@ -18,8 +18,22 @@ class Analyzer:
|
|
18 |
"""Klasse zur Analyse von Nutzereingaben"""
|
19 |
|
20 |
def __init__(self, api_token: str = config.API_TOKEN):
|
21 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
self.api_token = api_token
|
|
|
23 |
# Einfache Wörterbücher für die Stimmungsanalyse ohne ML-Bibliotheken
|
24 |
self.positive_words = [
|
25 |
"glücklich", "froh", "zufrieden", "gut", "großartig", "toll", "wunderbar",
|
@@ -34,7 +48,15 @@ class Analyzer:
|
|
34 |
"denke", "glaube", "meine", "verstehe", "sehe", "höre", "fühle",
|
35 |
"normal", "gewöhnlich", "alltäglich", "regelmäßig"
|
36 |
]
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
def analyze_emotion(self, text: str) -> str:
|
39 |
"""
|
40 |
Analysiert die Emotion in einem Text ohne ML-Bibliotheken
|
@@ -170,4 +192,4 @@ class Analyzer:
|
|
170 |
"themes": themes,
|
171 |
"complexity": complexity,
|
172 |
"suggested_intensity": min(complexity + (1 if emotion == "negative" else 0), 5)
|
173 |
-
}
|
|
|
18 |
"""Klasse zur Analyse von Nutzereingaben"""
|
19 |
|
20 |
def __init__(self, api_token: str = config.API_TOKEN):
|
21 |
+
"""
|
22 |
+
Initialisiert den Analyzer mit API-Token
|
23 |
+
|
24 |
+
Args:
|
25 |
+
api_token: Der API-Token für externe Services
|
26 |
+
|
27 |
+
Raises:
|
28 |
+
ValueError: Wenn der API-Token ungültig ist
|
29 |
+
"""
|
30 |
+
if not isinstance(api_token, str):
|
31 |
+
raise ValueError("api_token must be a string")
|
32 |
+
if not api_token:
|
33 |
+
raise ValueError("api_token cannot be empty")
|
34 |
+
|
35 |
self.api_token = api_token
|
36 |
+
|
37 |
# Einfache Wörterbücher für die Stimmungsanalyse ohne ML-Bibliotheken
|
38 |
self.positive_words = [
|
39 |
"glücklich", "froh", "zufrieden", "gut", "großartig", "toll", "wunderbar",
|
|
|
48 |
"denke", "glaube", "meine", "verstehe", "sehe", "höre", "fühle",
|
49 |
"normal", "gewöhnlich", "alltäglich", "regelmäßig"
|
50 |
]
|
51 |
+
|
52 |
+
# Validierung der Wörterlisten
|
53 |
+
if not all(isinstance(word, str) for word in self.positive_words):
|
54 |
+
raise ValueError("All words in positive_words must be strings")
|
55 |
+
if not all(isinstance(word, str) for word in self.negative_words):
|
56 |
+
raise ValueError("All words in negative_words must be strings")
|
57 |
+
if not all(isinstance(word, str) for word in self.neutral_words):
|
58 |
+
raise ValueError("All words in neutral_words must be strings")
|
59 |
+
|
60 |
def analyze_emotion(self, text: str) -> str:
|
61 |
"""
|
62 |
Analysiert die Emotion in einem Text ohne ML-Bibliotheken
|
|
|
192 |
"themes": themes,
|
193 |
"complexity": complexity,
|
194 |
"suggested_intensity": min(complexity + (1 if emotion == "negative" else 0), 5)
|
195 |
+
}
|