File size: 1,804 Bytes
f6e574f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Test the document classifier."""
import sys
from pathlib import Path

# Add backend to path
sys.path.insert(0, str(Path(__file__).parent / "backend"))

from app.classifier import get_classifier

def test_classifier():
    """Test the classifier with sample text."""
    print("Loading classifier...")
    classifier = get_classifier()
    
    # Test with sample texts
    test_cases = [
        ("Invoice for services rendered. Total amount due: $500.00. Payment terms: Net 30.", "invoice"),
        ("This is to certify that John Doe has completed the course.", "certificate"),
        ("Dear Sir, I am writing to inform you...", "letter"),
        ("Account Statement - Account #12345. Balance: $1,000.00", "bank statement"),
    ]
    
    print("\n" + "="*60)
    print("Testing Document Classifier")
    print("="*60 + "\n")
    
    for i, (text, expected_type) in enumerate(test_cases, 1):
        print(f"Test {i}: Expected type: {expected_type}")
        print(f"Text: {text[:50]}...")
        
        result = classifier.classify_document(text)
        
        print(f"✅ Classified as: {result['document_type']}")
        print(f"   Confidence: {result['confidence']:.1%}")
        print(f"   Top 3: {list(result['all_scores'].keys())[:3]}")
        
        if result['document_type'] == expected_type:
            print("   ✅ PASS - Correct classification!")
        else:
            print(f"   ⚠️  Expected '{expected_type}' but got '{result['document_type']}'")
        
        print()
    
    print("="*60)
    print("Test completed!")

if __name__ == "__main__":
    try:
        test_classifier()
    except Exception as e:
        print(f"❌ Error during testing: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)