Spaces:
Build error
Build error
File size: 923 Bytes
837e221 |
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 |
from typing import List
import re
from smolagents import tool
@tool
def extract_dates(text: str) -> List[str]:
"""
Extract dates from text content.
Args:
text: Text content to extract dates from
Returns:
List of date strings found in the text
"""
# Simple regex patterns for date extraction
# These patterns can be expanded for better coverage
date_patterns = [
r"\d{1,2}/\d{1,2}/\d{2,4}", # MM/DD/YYYY or DD/MM/YYYY
r"\d{1,2}-\d{1,2}-\d{2,4}", # MM-DD-YYYY or DD-MM-YYYY
r"\b(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]* \d{1,2},? \d{4}\b", # Month DD, YYYY
r"\b\d{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]* \d{4}\b", # DD Month YYYY
]
results = []
for pattern in date_patterns:
matches = re.findall(pattern, text, re.IGNORECASE)
results.extend(matches)
return results |