fixed with example data
This commit is contained in:
1 parent
5fb1a855a1
commit
d28cccc957
16 files changed
+797
No files matched your search
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to validate PDF extraction improvements.
|
||||
Tests the enhanced extraction logic with various edge cases.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
from pdf_renamer import extract_names_from_pdf, analyze_failed_extractions
|
||||
|
||||
def test_pdf_extraction():
|
||||
"""Test PDF extraction on all PDFs in the current directory."""
|
||||
pdf_files = glob.glob('*.pdf')
|
||||
|
||||
if not pdf_files:
|
||||
print("No PDF files found in current directory.")
|
||||
return
|
||||
|
||||
print(f"Testing extraction on {len(pdf_files)} PDF files...\n")
|
||||
|
||||
success_count = 0
|
||||
failed_files = []
|
||||
|
||||
for pdf_file in pdf_files:
|
||||
print(f"Testing: {pdf_file}")
|
||||
result = extract_names_from_pdf(pdf_file)
|
||||
|
||||
if 'error' in result:
|
||||
print(f" ❌ FAILED: {result['error']}")
|
||||
failed_files.append(pdf_file)
|
||||
else:
|
||||
print(f" ✅ SUCCESS: {result['filename']}")
|
||||
print(f" Name: {result['first_name']} {result['last_name']}")
|
||||
print(f" Grade: {result['grade']}, School: {result['school']}, Gender: {result['gender']}")
|
||||
success_count += 1
|
||||
|
||||
print()
|
||||
|
||||
print(f"Results: {success_count}/{len(pdf_files)} PDFs extracted successfully")
|
||||
|
||||
if failed_files:
|
||||
print(f"\nFailed files: {', '.join(failed_files)}")
|
||||
|
||||
# Check for failed extraction log
|
||||
log_path = 'failed_extractions.log'
|
||||
if os.path.exists(log_path):
|
||||
print("\nAnalyzing failed extractions...")
|
||||
suggestions = analyze_failed_extractions(log_path)
|
||||
print("Suggestions for improvement:")
|
||||
print(suggestions)
|
||||
else:
|
||||
print("No failed extraction log found.")
|
||||
|
||||
return success_count == len(pdf_files)
|
||||
|
||||
def test_edge_cases():
|
||||
"""Test various edge cases that might cause issues."""
|
||||
print("Testing edge cases...\n")
|
||||
|
||||
# Test cases with different concatenation patterns
|
||||
test_cases = [
|
||||
# Test multi-part names
|
||||
"John Michael Smith",
|
||||
# Test different school formats
|
||||
"St. Mary's Catholic School",
|
||||
"Liberty Christian Academy",
|
||||
# Test grade variations
|
||||
"Grade 9", "9th Grade", "K", "12",
|
||||
# Test gender variations
|
||||
"Male", "Female", "M", "F", "Boy", "Girl"
|
||||
]
|
||||
|
||||
from pdf_renamer import extract_student_info_from_text
|
||||
|
||||
for test_case in test_cases:
|
||||
print(f"Testing edge case: '{test_case}'")
|
||||
result = extract_student_info_from_text(test_case)
|
||||
if result:
|
||||
print(f" ✅ Extracted: {result}")
|
||||
else:
|
||||
print(" ❌ No extraction")
|
||||
print()
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("PDF Extraction Validation Test")
|
||||
print("=" * 40)
|
||||
|
||||
# Test actual PDFs
|
||||
pdf_success = test_pdf_extraction()
|
||||
|
||||
print("\n" + "=" * 40)
|
||||
|
||||
# Test edge cases
|
||||
test_edge_cases()
|
||||
|
||||
print("\n" + "=" * 40)
|
||||
if pdf_success:
|
||||
print("✅ All PDF extractions successful!")
|
||||
else:
|
||||
print("❌ Some PDF extractions failed. Check failed_extractions.log for details.")
|
||||
|
||||
print("\nTo analyze failed extractions in detail, run:")
|
||||
print('python -c "from pdf_renamer import analyze_failed_extractions; print(analyze_failed_extractions(\'failed_extractions.log\'))"')
|
||||
Reference in new issue
Block a user