-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_word_forms.py
More file actions
51 lines (44 loc) · 1.54 KB
/
debug_word_forms.py
File metadata and controls
51 lines (44 loc) · 1.54 KB
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
#!/usr/bin/env python3
"""Debug script to test word form parsing."""
import re
from datetime import datetime, timedelta
def test_current_pattern():
test_cases = [
"5d",
"5 d",
"5day",
"5 day",
"5 days",
"5days",
"2w",
"2 weeks",
"2weeks"
]
# Fixed pattern - longer forms first
current_pattern = r'(\d+)\s*(days?|weeks?|months?|years?|[dwmy])'
print("Testing current regex pattern:")
print(f"Pattern: {current_pattern}")
print("=" * 60)
for test_case in test_cases:
match = re.search(current_pattern, test_case.lower())
if match:
print(f"'{test_case}' -> groups: {match.groups()}")
amount = int(match.group(1))
unit = match.group(2)
print(f" Amount: {amount}, Unit: '{unit}'")
# Test the unit matching logic
if unit in ('d', 'day', 'days'):
print(f" -> Would parse as {amount} days")
elif unit in ('w', 'week', 'weeks'):
print(f" -> Would parse as {amount} weeks")
elif unit in ('m', 'month', 'months'):
print(f" -> Would parse as {amount} months")
elif unit in ('y', 'year', 'years'):
print(f" -> Would parse as {amount} years")
else:
print(f" -> ERROR: Unit '{unit}' not recognized!")
else:
print(f"'{test_case}' -> NO MATCH")
print()
if __name__ == "__main__":
test_current_pattern()