DocClassify / test_classifier.py
Seth
Update
f6e574f
#!/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)