File size: 2,375 Bytes
a14c2d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Test verification module."""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent))

from src.annotation.automatic_verifier import (
    AutomaticVerifier,
    TextLengthRule,
    SentimentConsistencyRule,
)


def test_verifier_init():
    """Test verifier initialization."""
    verifier = AutomaticVerifier()
    assert len(verifier.rules) > 0
    print("βœ“ Verifier init test passed")


def test_text_length_rule():
    """Test text length verification rule."""
    rule = TextLengthRule(min_length=5, max_length=100)
    
    # Test too short
    passed, msg = rule.verify({"text": "Hi"})
    assert not passed
    
    # Test valid
    passed, msg = rule.verify({"text": "Valid length text"})
    assert passed
    
    print("βœ“ Text length rule test passed")


def test_sentiment_consistency():
    """Test sentiment consistency rule."""
    rule = SentimentConsistencyRule()
    
    # Positive text with positive label
    passed, msg = rule.verify({
        "text": "ကျေးဇူးပါ",
        "sentiment": "positive",
    })
    assert passed
    
    print("βœ“ Sentiment consistency rule test passed")


def test_dataset_verification():
    """Test full dataset verification."""
    verifier = AutomaticVerifier()
    
    samples = [
        {"id": "utt_001", "text": "ကျေးဇူးပါ", "sentiment": "positive"},
        {"id": "utt_002", "text": "မကျေနပ်", "sentiment": "negative"},
    ]
    
    results = verifier.verify_dataset(samples)
    
    assert results["total_samples"] == 2
    assert "statistics" in results
    
    print("βœ“ Dataset verification test passed")


def test_sample_filtering():
    """Test sample filtering based on verification."""
    verifier = AutomaticVerifier()
    
    samples = [
        {"id": "utt_001", "text": "ကျေးဇူးပါ", "sentiment": "positive"},
        {"id": "utt_002", "text": "", "sentiment": "negative"},  # Invalid
    ]
    
    kept, removed = verifier.filter_samples(samples)
    
    assert len(kept) == 1
    assert len(removed) == 1
    
    print("βœ“ Sample filtering test passed")


if __name__ == "__main__":
    test_verifier_init()
    test_text_length_rule()
    test_sentiment_consistency()
    test_dataset_verification()
    test_sample_filtering()
    print("\nβœ… All verifier tests passed!")