Spaces:
Sleeping
Sleeping
capture more info with due dates
Browse files
app.py
CHANGED
|
@@ -341,41 +341,62 @@ def regex_extract_schedule(text):
|
|
| 341 |
return events
|
| 342 |
|
| 343 |
def regex_extract_deadlines(text):
|
| 344 |
-
"""Regex extraction for deadlines"""
|
| 345 |
events = []
|
| 346 |
|
| 347 |
-
# Pattern 1: Due dates section
|
| 348 |
due_dates_section = re.search(
|
| 349 |
-
r'Due Dates:(.*?)(?
|
| 350 |
text,
|
| 351 |
re.DOTALL | re.IGNORECASE
|
| 352 |
)
|
| 353 |
|
| 354 |
if due_dates_section:
|
| 355 |
section_text = due_dates_section.group(1)
|
|
|
|
|
|
|
| 356 |
|
| 357 |
patterns = [
|
| 358 |
-
# Traditional codes
|
| 359 |
-
r'([A-Z]+\d+(?:\s*-\s*[A-Z]+\d*)?)\s+(?:Due\s+)?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}(?:st|nd|rd|th)?,?\s+\d{1,2}:\d{2}\s*(?:AM|PM|am|pm))',
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
r'((?:Assignment|Paper|Homework|Quiz|Lab|Midterm|Final|Project)\s+\d+)[:\s]+(?:Due\s+)?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}(?:st|nd|rd|th)?)',
|
| 364 |
-
#
|
| 365 |
-
r'(Midterm|Final)[:\s]+(?:Due\s+)?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}(?:st|nd|rd|th)?
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
| 367 |
]
|
| 368 |
|
| 369 |
-
for pattern in patterns:
|
| 370 |
-
|
|
|
|
|
|
|
|
|
|
| 371 |
assignment = match.group(1).strip()
|
| 372 |
date = match.group(2).strip()
|
| 373 |
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
events.append({
|
| 376 |
"Event": assignment,
|
| 377 |
"Date/Time": date
|
| 378 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
|
| 380 |
# Pattern 2: Important dates
|
| 381 |
important_section = re.search(
|
|
@@ -385,6 +406,7 @@ def regex_extract_deadlines(text):
|
|
| 385 |
)
|
| 386 |
|
| 387 |
if important_section:
|
|
|
|
| 388 |
section_text = important_section.group(1)
|
| 389 |
lines = section_text.split('\n')
|
| 390 |
|
|
@@ -403,6 +425,7 @@ def regex_extract_deadlines(text):
|
|
| 403 |
"Event": event,
|
| 404 |
"Date/Time": date
|
| 405 |
})
|
|
|
|
| 406 |
|
| 407 |
# Pattern 3: Schedule dates with assignments
|
| 408 |
schedule_pattern = r'(\d{1,2}/\d{1,2})\s*\([MTWRFS]+\)\s*[-–]\s*(.+?)(?:\n|$)'
|
|
@@ -417,6 +440,7 @@ def regex_extract_deadlines(text):
|
|
| 417 |
"Event": desc,
|
| 418 |
"Date/Time": date
|
| 419 |
})
|
|
|
|
| 420 |
|
| 421 |
# Pattern 4: Final exam
|
| 422 |
final_pattern = r"\*\s*((?:JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER)\s+\d{1,2},\s+\d{4}):\s*(\d{1,2}\s*(?:AM|PM|am|pm)\s*[-–]\s*\d{1,2}\s*(?:AM|PM|am|pm))"
|
|
@@ -429,7 +453,9 @@ def regex_extract_deadlines(text):
|
|
| 429 |
"Event": "Final Presentation",
|
| 430 |
"Date/Time": f"{date} {time}"
|
| 431 |
})
|
|
|
|
| 432 |
|
|
|
|
| 433 |
return events
|
| 434 |
|
| 435 |
# ---------------------------------------
|
|
|
|
| 341 |
return events
|
| 342 |
|
| 343 |
def regex_extract_deadlines(text):
|
| 344 |
+
"""Regex extraction for deadlines with debugging"""
|
| 345 |
events = []
|
| 346 |
|
| 347 |
+
# Pattern 1: Due dates section
|
| 348 |
due_dates_section = re.search(
|
| 349 |
+
r'Due Dates:\s*(.*?)(?=\n\s*\n\s*[A-Z][a-zA-Z\s&]+:|$)',
|
| 350 |
text,
|
| 351 |
re.DOTALL | re.IGNORECASE
|
| 352 |
)
|
| 353 |
|
| 354 |
if due_dates_section:
|
| 355 |
section_text = due_dates_section.group(1)
|
| 356 |
+
logger.info(f"Found 'Due Dates' section with {len(section_text)} characters")
|
| 357 |
+
logger.info(f"Section text: {repr(section_text[:500])}") # Show first 500 chars
|
| 358 |
|
| 359 |
patterns = [
|
| 360 |
+
# Traditional codes WITH time
|
| 361 |
+
(r'([A-Z]+\d+(?:\s*-\s*[A-Z]+\d*)?)\s+(?:Due\s+)?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}(?:st|nd|rd|th)?,?\s+\d{1,2}:\d{2}\s*(?:AM|PM|am|pm))', "Traditional with time"),
|
| 362 |
+
# Traditional codes WITHOUT time
|
| 363 |
+
(r'([A-Z]+\d+(?:\s*-\s*[A-Z]+\d*)?)\s+(?:Due\s+)?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}(?:st|nd|rd|th)?)', "Traditional without time"),
|
| 364 |
+
# Word-based WITH time
|
| 365 |
+
(r'((?:Assignment|Paper|Homework|Quiz|Lab|Midterm|Final|Project)\s+\d+)[:\s]+(?:Due\s+)?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}(?:st|nd|rd|th)?,?\s+\d{1,2}:\d{2}\s*(?:AM|PM|am|pm))', "Word-based with time"),
|
| 366 |
+
# Word-based WITHOUT time
|
| 367 |
+
(r'((?:Assignment|Paper|Homework|Quiz|Lab|Midterm|Final|Project)\s+\d+)[:\s]+(?:Due\s+)?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}(?:st|nd|rd|th)?)', "Word-based without time"),
|
| 368 |
+
# Exams WITH time
|
| 369 |
+
(r'(Midterm|Final)[:\s]+(?:Due\s+)?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}(?:st|nd|rd|th)?,?\s+\d{1,2}:\d{2}\s*(?:AM|PM|am|pm))', "Exam with time"),
|
| 370 |
+
# Exams WITHOUT time
|
| 371 |
+
(r'(Midterm|Final)[:\s]+(?:Due\s+)?((?:January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}(?:st|nd|rd|th)?)', "Exam without time"),
|
| 372 |
]
|
| 373 |
|
| 374 |
+
for pattern, pattern_name in patterns:
|
| 375 |
+
matches = list(re.finditer(pattern, section_text, re.IGNORECASE))
|
| 376 |
+
logger.info(f"Pattern '{pattern_name}' found {len(matches)} matches")
|
| 377 |
+
|
| 378 |
+
for match in matches:
|
| 379 |
assignment = match.group(1).strip()
|
| 380 |
date = match.group(2).strip()
|
| 381 |
|
| 382 |
+
logger.info(f" Matched: '{assignment}' -> '{date}'")
|
| 383 |
+
|
| 384 |
+
# Check if valid
|
| 385 |
+
is_valid = is_valid_assignment_code(assignment) or "midterm" in assignment.lower() or "final" in assignment.lower()
|
| 386 |
+
logger.info(f" is_valid_assignment_code: {is_valid}")
|
| 387 |
+
|
| 388 |
+
if is_valid:
|
| 389 |
events.append({
|
| 390 |
"Event": assignment,
|
| 391 |
"Date/Time": date
|
| 392 |
})
|
| 393 |
+
logger.info(f" ✓ Added to events")
|
| 394 |
+
else:
|
| 395 |
+
logger.info(f" ✗ Rejected (not valid assignment code)")
|
| 396 |
+
else:
|
| 397 |
+
logger.info("No 'Due Dates' section found")
|
| 398 |
+
|
| 399 |
+
logger.info(f"Total events extracted from Due Dates section: {len(events)}")
|
| 400 |
|
| 401 |
# Pattern 2: Important dates
|
| 402 |
important_section = re.search(
|
|
|
|
| 406 |
)
|
| 407 |
|
| 408 |
if important_section:
|
| 409 |
+
logger.info("Found 'Important Dates' section")
|
| 410 |
section_text = important_section.group(1)
|
| 411 |
lines = section_text.split('\n')
|
| 412 |
|
|
|
|
| 425 |
"Event": event,
|
| 426 |
"Date/Time": date
|
| 427 |
})
|
| 428 |
+
logger.info(f"Added from Important Dates: '{event}' -> '{date}'")
|
| 429 |
|
| 430 |
# Pattern 3: Schedule dates with assignments
|
| 431 |
schedule_pattern = r'(\d{1,2}/\d{1,2})\s*\([MTWRFS]+\)\s*[-–]\s*(.+?)(?:\n|$)'
|
|
|
|
| 440 |
"Event": desc,
|
| 441 |
"Date/Time": date
|
| 442 |
})
|
| 443 |
+
logger.info(f"Added from schedule: '{desc}' -> '{date}'")
|
| 444 |
|
| 445 |
# Pattern 4: Final exam
|
| 446 |
final_pattern = r"\*\s*((?:JANUARY|FEBRUARY|MARCH|APRIL|MAY|JUNE|JULY|AUGUST|SEPTEMBER|OCTOBER|NOVEMBER|DECEMBER)\s+\d{1,2},\s+\d{4}):\s*(\d{1,2}\s*(?:AM|PM|am|pm)\s*[-–]\s*\d{1,2}\s*(?:AM|PM|am|pm))"
|
|
|
|
| 453 |
"Event": "Final Presentation",
|
| 454 |
"Date/Time": f"{date} {time}"
|
| 455 |
})
|
| 456 |
+
logger.info(f"Added final presentation: '{date} {time}'")
|
| 457 |
|
| 458 |
+
logger.info(f"Total events before cleaning: {len(events)}")
|
| 459 |
return events
|
| 460 |
|
| 461 |
# ---------------------------------------
|