77 lines
2.8 KiB
Python
77 lines
2.8 KiB
Python
#!/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'}") |