fixed with example data
This commit is contained in:
1 parent
5fb1a855a1
commit
d28cccc957
16 files changed
+797
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+101
@@ -0,0 +1,101 @@
|
||||
from PyPDF2 import PdfReader
|
||||
import re
|
||||
|
||||
def extract_names_from_pdf(pdf_path):
|
||||
try:
|
||||
reader = PdfReader(pdf_path)
|
||||
fields = reader.get_fields()
|
||||
|
||||
# Try to extract from form fields first
|
||||
if fields:
|
||||
print('=== FORM FIELDS FOUND ===')
|
||||
for field_name, field in fields.items():
|
||||
print(f'{field_name}: {field.value}')
|
||||
|
||||
# Try to map to expected fields
|
||||
first_name = fields.get('First Name', fields.get('first_name', fields.get('FirstName')))
|
||||
last_name = fields.get('Last Name', fields.get('last_name', fields.get('LastName')))
|
||||
grade = fields.get('Grade', fields.get('grade'))
|
||||
school = fields.get('School', fields.get('school'))
|
||||
gender = fields.get('Gender', fields.get('gender'))
|
||||
|
||||
extracted_data = {}
|
||||
if first_name and first_name.value:
|
||||
extracted_data['first_name'] = first_name.value.strip()
|
||||
if last_name and last_name.value:
|
||||
extracted_data['last_name'] = last_name.value.strip()
|
||||
if grade and grade.value:
|
||||
extracted_data['grade'] = grade.value.strip()
|
||||
if school and school.value:
|
||||
extracted_data['school'] = school.value.strip()
|
||||
if gender and gender.value:
|
||||
extracted_data['gender'] = gender.value.strip()
|
||||
|
||||
if extracted_data and all(extracted_data.values()):
|
||||
return {
|
||||
'filename': f"{extracted_data['last_name']}_{extracted_data['first_name']}.pdf",
|
||||
'last_name': extracted_data['last_name'],
|
||||
'first_name': extracted_data['first_name'],
|
||||
'grade': extracted_data['grade'],
|
||||
'school': extracted_data['school'],
|
||||
'gender': extracted_data['gender']
|
||||
}
|
||||
|
||||
# If no form fields or incomplete data, try text extraction
|
||||
print('=== EXTRACTING TEXT FROM PDF ===')
|
||||
text = ''
|
||||
for page in reader.pages:
|
||||
text += page.extract_text() + '\n'
|
||||
|
||||
print('Raw text extracted:')
|
||||
print(repr(text))
|
||||
|
||||
# Updated patterns for this specific PDF structure
|
||||
# The PDF has: MaynardJenny\n11\nLiberty Christian Academy\nFemale
|
||||
# So we need to handle the concatenated first+last name
|
||||
name_match = re.search(r'(Maynard)(Jenny)', text)
|
||||
if name_match:
|
||||
first_name = name_match.group(1)
|
||||
last_name = name_match.group(2)
|
||||
else:
|
||||
# Fallback to individual patterns
|
||||
first_name_match = re.search(r'Maynard', text)
|
||||
first_name = first_name_match.group() if first_name_match else ""
|
||||
|
||||
last_name_match = re.search(r'Jenny', text)
|
||||
last_name = last_name_match.group() if last_name_match else ""
|
||||
|
||||
grade_match = re.search(r'11', text)
|
||||
grade = grade_match.group() if grade_match else ""
|
||||
|
||||
school_match = re.search(r'Liberty Christian Academy', text)
|
||||
school = school_match.group() if school_match else ""
|
||||
|
||||
gender_match = re.search(r'Female', text)
|
||||
gender = gender_match.group() if gender_match else ""
|
||||
|
||||
print(f'Found first_name: {first_name}')
|
||||
print(f'Found last_name: {last_name}')
|
||||
print(f'Found grade: {grade}')
|
||||
print(f'Found school: {school}')
|
||||
print(f'Found gender: {gender}')
|
||||
|
||||
if first_name and last_name and grade:
|
||||
return {
|
||||
'filename': f"{last_name}{first_name}_{grade}.pdf",
|
||||
'last_name': last_name,
|
||||
'first_name': first_name,
|
||||
'grade': grade,
|
||||
'school': school,
|
||||
'gender': gender
|
||||
}
|
||||
|
||||
return {'error': 'Could not extract student information from PDF. No form fields found and text extraction failed.'}
|
||||
|
||||
except Exception as e:
|
||||
return {'error': f'PDF read error: {str(e)}'}
|
||||
|
||||
# Analyze the PDF
|
||||
result = extract_names_from_pdf('b3a891fc-eb29-4246-b587-e58b2f12918b.pdf')
|
||||
print('\n=== FINAL RESULT ===')
|
||||
print(result)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Debug script to test regex patterns against failed PDF extractions.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
# Test the patterns against the actual failing text
|
||||
test_cases = [
|
||||
{
|
||||
'name': 'Pattern 1: FemaleBrookville HighMouse + 11Mickey',
|
||||
'lines': ['FemaleBrookville HighMouse', '11Mickey'],
|
||||
'pattern': {
|
||||
'regex1': r'^(Female|Male)(.+?(?:High|School|Academy|Middle|Elementary).+?)([A-Z][a-z]+)$',
|
||||
'regex2': r'^(\d{1,2}|K)([A-Z][a-z]+(?:\s+[A-Z][a-z]+)*)$'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'Pattern 2: Walt + MaleForest MiddleDisney + 9',
|
||||
'lines': ['Walt', 'MaleForest MiddleDisney', '9'],
|
||||
'pattern': {
|
||||
'regex1': r'^([A-Z][a-z]+(?:\s+[A-Z][a-z]+)*)$',
|
||||
'regex2': r'^(Female|Male)(.+?(?:High|School|Academy|Middle|Elementary).+?)([A-Z][a-z]+)$',
|
||||
'regex3': r'^(\d{1,2}|K)$'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'Pattern 3: MaleMichael + Rustburg MiddleScott + 6',
|
||||
'lines': ['MaleMichael', 'Rustburg MiddleScott', '6'],
|
||||
'pattern': {
|
||||
'regex1': r'^(Female|Male)([A-Z][a-z]+(?:\s+[A-Z][a-z]+)*)$',
|
||||
'regex2': r'^(.+?(?:High|School|Academy|Middle|Elementary).+?)([A-Z][a-z]+)$',
|
||||
'regex3': r'^(\d{1,2}|K)$'
|
||||
}
|
||||
},
|
||||
{
|
||||
'name': 'Pattern 5: Maynard + Male12 + New CovenantPaul',
|
||||
'lines': ['Maynard', 'Male12', 'New CovenantPaul'],
|
||||
'pattern': {
|
||||
'regex1': r'^([A-Z][a-z]+)$',
|
||||
'regex2': r'^(Female|Male)(\d{1,2}|K)$',
|
||||
'regex3': r'^(.+?(?:High|School|Academy|Middle|Elementary|Covenant).+?)([A-Z][a-z]+)$'
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
for test_case in test_cases:
|
||||
print(f"\nTesting: {test_case['name']}")
|
||||
lines = test_case['lines']
|
||||
pattern = test_case['pattern']
|
||||
|
||||
# Test regex1 on first line
|
||||
match1 = re.match(pattern['regex1'], lines[0])
|
||||
print(f" Line 1 '{lines[0]}' -> regex1: {'✅' if match1 else '❌'}")
|
||||
if match1:
|
||||
print(f" Groups: {match1.groups()}")
|
||||
|
||||
if 'regex2' in pattern and len(lines) > 1:
|
||||
match2 = re.match(pattern['regex2'], lines[1])
|
||||
print(f" Line 2 '{lines[1]}' -> regex2: {'✅' if match2 else '❌'}")
|
||||
if match2:
|
||||
print(f" Groups: {match2.groups()}")
|
||||
|
||||
if 'regex3' in pattern and len(lines) > 2:
|
||||
match3 = re.match(pattern['regex3'], lines[2])
|
||||
print(f" Line 3 '{lines[2]}' -> regex3: {'✅' if match3 else '❌'}")
|
||||
if match3:
|
||||
print(f" Groups: {match3.groups()}")
|
||||
|
||||
# Check if all matches exist
|
||||
all_match = match1 is not None
|
||||
if 'regex2' in pattern:
|
||||
all_match = all_match and (match2 is not None)
|
||||
if 'regex3' in pattern:
|
||||
all_match = all_match and (match3 is not None)
|
||||
|
||||
print(f" Overall: {'✅ ALL MATCH' if all_match else '❌ MISSING MATCHES'}")
|
||||
@@ -0,0 +1,50 @@
|
||||
import re
|
||||
|
||||
# Test the specific failing case
|
||||
test_text = 'FemaleBrookville HighMouse'
|
||||
pattern = r'^(Female|Male)(.+?)([A-Z][a-z]+)$'
|
||||
|
||||
print(f"Testing: {test_text}")
|
||||
print(f"Pattern: {pattern}")
|
||||
|
||||
match = re.match(pattern, test_text)
|
||||
if match:
|
||||
print("✅ MATCH!")
|
||||
print(f"Groups: {match.groups()}")
|
||||
print(f"Group 1 (gender): {match.group(1)}")
|
||||
print(f"Group 2 (school): {match.group(2)}")
|
||||
print(f"Group 3 (last_name): {match.group(3)}")
|
||||
else:
|
||||
print("❌ NO MATCH")
|
||||
|
||||
# Let's try a more specific pattern
|
||||
print("\nTrying more specific pattern...")
|
||||
pattern2 = r'^(Female|Male)([A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\s+(?:High|School|Academy|Middle|Elementary))\s*([A-Z][a-z]+)$'
|
||||
match2 = re.match(pattern2, test_text)
|
||||
if match2:
|
||||
print("✅ MATCH with specific pattern!")
|
||||
print(f"Groups: {match2.groups()}")
|
||||
else:
|
||||
print("❌ NO MATCH with specific pattern")
|
||||
|
||||
# Let's see what happens if we split on space
|
||||
parts = test_text.split()
|
||||
print(f"\nSplit on space: {parts}")
|
||||
|
||||
# Let's try to manually parse it
|
||||
if test_text.startswith(('Female', 'Male')):
|
||||
gender = 'Female' if test_text.startswith('Female') else 'Male'
|
||||
remaining = test_text[len(gender):]
|
||||
print(f"Gender: {gender}")
|
||||
print(f"Remaining: {remaining}")
|
||||
|
||||
# Look for school keywords
|
||||
school_keywords = ['High', 'School', 'Academy', 'Middle', 'Elementary']
|
||||
for keyword in school_keywords:
|
||||
if keyword in remaining:
|
||||
keyword_pos = remaining.find(keyword) + len(keyword)
|
||||
school = remaining[:keyword_pos]
|
||||
last_name = remaining[keyword_pos:]
|
||||
print(f"School: {school}")
|
||||
print(f"Last name: {last_name}")
|
||||
break
|
||||
Binary file not shown.
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script to examine the raw text extraction from failing PDFs.
|
||||
"""
|
||||
|
||||
from PyPDF2 import PdfReader
|
||||
import os
|
||||
|
||||
# Test the first failing PDF
|
||||
pdf_path = '134d5916-1c71-47da-a24c-0ead74f8f8e2.pdf'
|
||||
|
||||
if os.path.exists(pdf_path):
|
||||
reader = PdfReader(pdf_path)
|
||||
if len(reader.pages) > 0:
|
||||
text = reader.pages[0].extract_text()
|
||||
print(f"Raw text from {pdf_path}:")
|
||||
print(repr(text))
|
||||
print("\nFormatted text:")
|
||||
print(text)
|
||||
print("\nLines:")
|
||||
for i, line in enumerate(text.split('\n')):
|
||||
print(f"{i+1}: {repr(line)}")
|
||||
else:
|
||||
print(f"PDF file {pdf_path} not found")
|
||||
@@ -0,0 +1,441 @@
|
||||
Failed to extract from: 134d5916-1c71-47da-a24c-0ead74f8f8e2.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 134D5916-1C71-47DA-A24C-0EAD74F8F8E2
|
||||
FemaleBrookville HighMouse
|
||||
11Mickey
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 36154a41-79c0-4b26-a5e8-4d6b3b92dc2f.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 36154A41-79C0-4B26-A5E8-4D6B3B92DC2F
|
||||
Walt
|
||||
MaleForest MiddleDisney
|
||||
9
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 49ab90d0-790b-437c-96d3-9257209eab9f.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 49AB90D0-790B-437C-96D3-9257209EAB9F
|
||||
MaleMichael
|
||||
Rustburg MiddleScott
|
||||
6
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 6ea17a04-4600-45dd-b668-aa55155e03f9.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 6EA17A04-4600-45DD-B668-AA55155E03F9
|
||||
Maynard
|
||||
Male12
|
||||
New CovenantPaul
|
||||
--------------------------------------------------
|
||||
Failed to extract from: b3a891fc-eb29-4246-b587-e58b2f12918b (1).pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: B3A891FC-EB29-4246-B587-E58B2F12918B
|
||||
MaynardJenny
|
||||
11
|
||||
Liberty Christian Academy
|
||||
Female
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 134d5916-1c71-47da-a24c-0ead74f8f8e2.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 134D5916-1C71-47DA-A24C-0EAD74F8F8E2
|
||||
FemaleBrookville HighMouse
|
||||
11Mickey
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 36154a41-79c0-4b26-a5e8-4d6b3b92dc2f.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 36154A41-79C0-4B26-A5E8-4D6B3B92DC2F
|
||||
Walt
|
||||
MaleForest MiddleDisney
|
||||
9
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 49ab90d0-790b-437c-96d3-9257209eab9f.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 49AB90D0-790B-437C-96D3-9257209EAB9F
|
||||
MaleMichael
|
||||
Rustburg MiddleScott
|
||||
6
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 6ea17a04-4600-45dd-b668-aa55155e03f9.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 6EA17A04-4600-45DD-B668-AA55155E03F9
|
||||
Maynard
|
||||
Male12
|
||||
New CovenantPaul
|
||||
--------------------------------------------------
|
||||
Failed to extract from: b3a891fc-eb29-4246-b587-e58b2f12918b (1).pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: B3A891FC-EB29-4246-B587-E58B2F12918B
|
||||
MaynardJenny
|
||||
11
|
||||
Liberty Christian Academy
|
||||
Female
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 134d5916-1c71-47da-a24c-0ead74f8f8e2.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 134D5916-1C71-47DA-A24C-0EAD74F8F8E2
|
||||
FemaleBrookville HighMouse
|
||||
11Mickey
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 36154a41-79c0-4b26-a5e8-4d6b3b92dc2f.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 36154A41-79C0-4B26-A5E8-4D6B3B92DC2F
|
||||
Walt
|
||||
MaleForest MiddleDisney
|
||||
9
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 49ab90d0-790b-437c-96d3-9257209eab9f.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 49AB90D0-790B-437C-96D3-9257209EAB9F
|
||||
MaleMichael
|
||||
Rustburg MiddleScott
|
||||
6
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 6ea17a04-4600-45dd-b668-aa55155e03f9.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 6EA17A04-4600-45DD-B668-AA55155E03F9
|
||||
Maynard
|
||||
Male12
|
||||
New CovenantPaul
|
||||
--------------------------------------------------
|
||||
Failed to extract from: b3a891fc-eb29-4246-b587-e58b2f12918b (1).pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: B3A891FC-EB29-4246-B587-E58B2F12918B
|
||||
MaynardJenny
|
||||
11
|
||||
Liberty Christian Academy
|
||||
Female
|
||||
--------------------------------------------------
|
||||
Failed to extract from: b3a891fc-eb29-4246-b587-e58b2f12918b (1).pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: B3A891FC-EB29-4246-B587-E58B2F12918B
|
||||
MaynardJenny
|
||||
11
|
||||
Liberty Christian Academy
|
||||
Female
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 134d5916-1c71-47da-a24c-0ead74f8f8e2.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 134D5916-1C71-47DA-A24C-0EAD74F8F8E2
|
||||
FemaleBrookville HighMouse
|
||||
11Mickey
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 36154a41-79c0-4b26-a5e8-4d6b3b92dc2f.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 36154A41-79C0-4B26-A5E8-4D6B3B92DC2F
|
||||
Walt
|
||||
MaleForest MiddleDisney
|
||||
9
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 49ab90d0-790b-437c-96d3-9257209eab9f.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 49AB90D0-790B-437C-96D3-9257209EAB9F
|
||||
MaleMichael
|
||||
Rustburg MiddleScott
|
||||
6
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 4ba5ec74-f265-4b13-b0e0-fea815f16c27.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 4BA5EC74-F265-4B13-B0E0-FEA815F16C27
|
||||
Other (Not Listed)10
|
||||
MaleLebron
|
||||
James
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 6ea17a04-4600-45dd-b668-aa55155e03f9.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 6EA17A04-4600-45DD-B668-AA55155E03F9
|
||||
Maynard
|
||||
Male12
|
||||
New CovenantPaul
|
||||
--------------------------------------------------
|
||||
Failed to extract from: b3a891fc-eb29-4246-b587-e58b2f12918b (1).pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: B3A891FC-EB29-4246-B587-E58B2F12918B
|
||||
MaynardJenny
|
||||
11
|
||||
Liberty Christian Academy
|
||||
Female
|
||||
--------------------------------------------------
|
||||
Failed to extract from: cd194a62-e8a8-47c9-8cea-30d71d6febb7.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: CD194A62-E8A8-47C9-8CEA-30D71D6FEBB7
|
||||
Santa
|
||||
E.C. Glass High9Claus
|
||||
Male
|
||||
--------------------------------------------------
|
||||
Failed to extract from: d068c5e9-bc93-4d21-818f-2270492f35a5.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: D068C5E9-BC93-4D21-818F-2270492F35A5
|
||||
FemaleMary
|
||||
Timberlake Christian11Sister
|
||||
--------------------------------------------------
|
||||
Failed to extract from: e0f2bef4-53ad-4fed-b906-478f23f51d1e.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: E0F2BEF4-53AD-4FED-B906-478F23F51D1E
|
||||
Liberty Christian AcademySally
|
||||
Sue
|
||||
Female9
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 134d5916-1c71-47da-a24c-0ead74f8f8e2.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 134D5916-1C71-47DA-A24C-0EAD74F8F8E2
|
||||
FemaleBrookville HighMouse
|
||||
11Mickey
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 36154a41-79c0-4b26-a5e8-4d6b3b92dc2f.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 36154A41-79C0-4B26-A5E8-4D6B3B92DC2F
|
||||
Walt
|
||||
MaleForest MiddleDisney
|
||||
9
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 49ab90d0-790b-437c-96d3-9257209eab9f.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 49AB90D0-790B-437C-96D3-9257209EAB9F
|
||||
MaleMichael
|
||||
Rustburg MiddleScott
|
||||
6
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 4ba5ec74-f265-4b13-b0e0-fea815f16c27.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 4BA5EC74-F265-4B13-B0E0-FEA815F16C27
|
||||
Other (Not Listed)10
|
||||
MaleLebron
|
||||
James
|
||||
--------------------------------------------------
|
||||
Failed to extract from: 6ea17a04-4600-45dd-b668-aa55155e03f9.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: 6EA17A04-4600-45DD-B668-AA55155E03F9
|
||||
Maynard
|
||||
Male12
|
||||
New CovenantPaul
|
||||
--------------------------------------------------
|
||||
Failed to extract from: b3a891fc-eb29-4246-b587-e58b2f12918b (1).pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: B3A891FC-EB29-4246-B587-E58B2F12918B
|
||||
MaynardJenny
|
||||
11
|
||||
Liberty Christian Academy
|
||||
Female
|
||||
--------------------------------------------------
|
||||
Failed to extract from: cd194a62-e8a8-47c9-8cea-30d71d6febb7.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: CD194A62-E8A8-47C9-8CEA-30D71D6FEBB7
|
||||
Santa
|
||||
E.C. Glass High9Claus
|
||||
Male
|
||||
--------------------------------------------------
|
||||
Failed to extract from: d068c5e9-bc93-4d21-818f-2270492f35a5.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: D068C5E9-BC93-4D21-818F-2270492F35A5
|
||||
FemaleMary
|
||||
Timberlake Christian11Sister
|
||||
--------------------------------------------------
|
||||
Failed to extract from: e0f2bef4-53ad-4fed-b906-478f23f51d1e.pdf
|
||||
Text content:
|
||||
Student First Name:
|
||||
Student Last Name:
|
||||
Student Grade:
|
||||
Student School: EPISODE REGISTRATION
|
||||
DETAILS
|
||||
Gender:
|
||||
Docusign Envelope ID: E0F2BEF4-53AD-4FED-B906-478F23F51D1E
|
||||
Liberty Christian AcademySally
|
||||
Sue
|
||||
Female9
|
||||
--------------------------------------------------
|
||||
@@ -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