File size: 7,588 Bytes
25e624c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# -*- coding: utf-8 -*-
"""
Comprehensive Emotion Test - Test recognition across many text strings

Tests:
1. Greetings (should be neutral)
2. Questions (should be neutral/curious)
3. Positive emotions
4. Negative emotions
5. Complex/mixed emotions
6. Edge cases

Ensures the system interprets text correctly.
"""

import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from avatar.sentiment_transformer import SentimentAnalyzer as BinaryAnalyzer
from avatar.sentiment_multi_emotion import MultiEmotionAnalyzer
from avatar.sentiment_emoji_map import EmojiMapper


def run_comprehensive_test():
    """Run comprehensive emotion recognition test"""
    
    print("=" * 80)
    print("COMPREHENSIVE EMOTION RECOGNITION TEST")
    print("=" * 80)
    print()
    
    # Load analyzers
    print("Loading analyzers...")
    binary = BinaryAnalyzer()
    multi = MultiEmotionAnalyzer()
    mapper = EmojiMapper()
    
    # Test cases organized by category
    test_cases = {
        "GREETINGS (should be neutral/positive)": [
            ("How are you?", "neutral"),
            ("Hello! How are you?", "neutral"),
            ("Hey, how are you?", "neutral"),
            ("Hi there!", "neutral"),
            ("What's up?", "neutral"),
            ("Good morning!", "neutral"),
            ("Good evening!", "neutral"),
            ("How is it going?", "neutral"),
            ("How have you been?", "neutral"),
            ("Are you okay?", "neutral"),
            ("Yo!", "neutral"),
            ("Hey!", "neutral"),
            ("Greetings!", "neutral"),
        ],
        
        "QUESTIONS (should be neutral/curious)": [
            ("What time is it?", "neutral"),
            ("Where is the store?", "neutral"),
            ("Can you help me?", "neutral"),
            ("Do you know the answer?", "neutral"),
            ("What do you think?", "neutral"),
            ("Is this correct?", "neutral"),
            ("Why did that happen?", "neutral"),
            ("How does this work?", "neutral"),
            ("What is the meaning of life?", "neutral"),
            ("Who is that?", "neutral"),
        ],
        
        "POSITIVE EMOTIONS": [
            ("I am so happy today!", "positive"),
            ("I love this!", "positive"),
            ("This is amazing!", "positive"),
            ("Thank you so much!", "positive"),
            ("I'm grateful for everything", "positive"),
            ("This makes me so excited!", "positive"),
            ("I feel wonderful!", "positive"),
            ("You're the best!", "positive"),
            ("I'm thrilled about this!", "positive"),
            ("What a beautiful day!", "positive"),
            ("I can't wait!", "positive"),
            ("This is fantastic!", "positive"),
            ("I'm so proud of you!", "positive"),
            ("Best day ever!", "positive"),
            ("I'm feeling great!", "positive"),
        ],
        
        "NEGATIVE EMOTIONS": [
            ("I am so sad", "negative"),
            ("This is terrible", "negative"),
            ("I'm really angry", "negative"),
            ("This makes me furious", "negative"),
            ("I hate this", "negative"),
            ("I'm scared", "negative"),
            ("This is awful", "negative"),
            ("I feel miserable", "negative"),
            ("I'm disappointed", "negative"),
            ("This is frustrating", "negative"),
            ("I can't stand this", "negative"),
            ("I'm heartbroken", "negative"),
            ("Everything is wrong", "negative"),
            ("I feel hopeless", "negative"),
            ("This is disgusting", "negative"),
        ],
        
        "NEUTRAL STATEMENTS": [
            ("The weather is okay", "neutral"),
            ("It's Monday", "neutral"),
            ("The meeting is at 3pm", "neutral"),
            ("I need to go shopping", "neutral"),
            ("The car is blue", "neutral"),
            ("I'm going to work", "neutral"),
            ("It's raining outside", "neutral"),
            ("The document is ready", "neutral"),
            ("I'll call you later", "neutral"),
            ("The report is on my desk", "neutral"),
        ],
        
        "EDGE CASES": [
            ("I'm not happy", "negative"),
            ("I don't feel bad", "positive"),
            ("This isn't terrible", "neutral"),
            ("Meh", "neutral"),
            ("Whatever", "neutral"),
            ("Fine", "neutral"),
            ("Ok", "neutral"),
            ("Sure", "neutral"),
            ("I guess", "neutral"),
            ("Maybe", "neutral"),
        ],
        
        "SARCASM (tricky)": [
            ("Oh great, just what I needed", "negative"),
            ("Yeah, that's exactly what I wanted", "negative"),
            ("Oh wonderful", "negative"),
            ("How fantastic", "negative"),
            ("Just perfect", "negative"),
        ],
        
        "MIXED EMOTIONS (should detect last sentiment)": [
            ("I was sad, but now I'm happy!", "positive"),
            ("Started great, ended terribly", "negative"),
            ("Good news and bad news", "neutral"),
            ("I love this! Wait, no I hate it", "negative"),
            ("Happy at first, now confused", "neutral"),
        ],
    }
    
    # Run tests
    results = {"pass": 0, "fail": 0, "total": 0}
    failed_tests = []
    
    for category, tests in test_cases.items():
        print(f"\n{'='*80}")
        print(f"📋 {category}")
        print(f"{'='*80}")
        
        for text, expected_polarity in tests:
            results["total"] += 1
            
            # Test binary analyzer
            binary_result = binary.analyze(text)
            binary_label = binary_result["label"]
            
            # Test multi-emotion analyzer
            multi_result = multi.analyze(text)
            multi_label = multi_result["label"]
            multi_polarity = multi_result["polarity"]
            
            # Get emoji
            emoji = mapper.get_emoji(multi_label)
            
            # Determine pass/fail based on polarity expectation
            if expected_polarity == "neutral":
                # Neutral can also be positive for greetings
                passed = multi_polarity in ["neutral", "positive"]
            elif expected_polarity == "positive":
                passed = multi_polarity == "positive"
            elif expected_polarity == "negative":
                passed = multi_polarity == "negative"
            else:
                passed = True
            
            status = "✅" if passed else "❌"
            
            if passed:
                results["pass"] += 1
            else:
                results["fail"] += 1
                failed_tests.append((text, expected_polarity, multi_label, multi_polarity))
            
            print(f"{status} '{text[:40]:40}' -> {multi_label:15} ({multi_polarity:8}) {emoji}")
    
    # Summary
    print("\n" + "=" * 80)
    print("📊 SUMMARY")
    print("=" * 80)
    print(f"Total tests: {results['total']}")
    print(f"Passed: {results['pass']} ({results['pass']/results['total']*100:.1f}%)")
    print(f"Failed: {results['fail']} ({results['fail']/results['total']*100:.1f}%)")
    
    if failed_tests:
        print("\n❌ FAILED TESTS:")
        print("-" * 80)
        for text, expected, detected, polarity in failed_tests:
            print(f"  '{text[:50]}' - expected {expected}, got {detected} ({polarity})")
    
    return results


if __name__ == "__main__":
    run_comprehensive_test()