Newer
Older

Michał Pogoda
committed
from src.detections import DateDetection, Optional

Michał Pogoda
committed
def _parse_day_or_month(re_entry) -> List[Tuple[int, int, DateDetection]]:
assert re_entry["day_or_month_year"] is not None
result = []
if re_entry["day_month1"] is not None:
if len(re_entry["day_month1"]) == 1:

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGITS_DAY, "0" + re_entry["day_month1"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGITS_DAY, re_entry["day_month1"]))
result.append((DateDetection.AnnotationPart.OTHER, re_entry["punct1"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGIT_MONTH, "0" + re_entry["day_month2"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGIT_MONTH, re_entry["day_month2"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.OTHER, re_entry["punct1"]))
elif "day_month2" in re_entry:
if len(re_entry["day_month2"]) == 1:

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGIT_MONTH, "0" + re_entry["day_month2"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGIT_MONTH, re_entry["day_month2"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.OTHER, re_entry["punct1"]))
if "year1" in re_entry:
if len(re_entry["year1"]) == 2:

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGIT_YEAR, re_entry["year1"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.FOUR_DIGIT_YEAR, re_entry["year1"]))

Michał Pogoda
committed
def _parse_year_month_or_day(re_entry) -> List[Tuple[int, int, DateDetection]]:
assert re_entry["year_month_or_day"] is not None
result = []
if "year2" in re_entry:
if len(re_entry["year2"]) == 2:

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGIT_YEAR, re_entry["year2"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.FOUR_DIGIT_YEAR, re_entry["year2"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.OTHER, re_entry["punct3"]))
if "day_month3" in re_entry:
if len(re_entry["day_month3"]) == 1:

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGITS_DAY, "0" + re_entry["day_month3"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGITS_DAY, re_entry["day_month3"]))
result.append((DateDetection.AnnotationPart.OTHER, re_entry["punct4"]))
if "day_month4" in re_entry:
if len(re_entry["day_month4"]) == 1:

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGIT_MONTH, "0" + re_entry["day_month4"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGIT_MONTH, re_entry["day_month4"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.OTHER, re_entry["punct4"]))

Michał Pogoda
committed
def _parse_month_in_words(re_entry) -> List[Tuple[DateDetection.AnnotationPart, str]]:
assert re_entry["month_in_words"] is not None
result = []
if re_entry["day1"] is not None:
if len(re_entry["day1"]) == 1:

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGITS_DAY, "0" + re_entry["day1"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGITS_DAY, re_entry["day1"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.OTHER, re_entry["punct5"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TEXT_MONTH, re_entry["month"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.OTHER, re_entry["punct7"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.OTHER, re_entry["punct6"]))
if re_entry["day2"] is not None:
if len(re_entry["day2"]) == 1:

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGITS_DAY, "0" + re_entry["day2"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGITS_DAY, re_entry["day2"]))
result.append((DateDetection.AnnotationPart.OTHER, re_entry["punct6"]))
if re_entry["year3"] is not None:
if len(re_entry["year3"]) == 2:

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.TWO_DIGIT_YEAR, re_entry["year3"]))

Michał Pogoda
committed
result.append((DateDetection.AnnotationPart.FOUR_DIGIT_YEAR, re_entry["year3"]))

Michał Pogoda
committed
def _parse_date_to_format(re_entry) -> Optional[List[Tuple[DateDetection.AnnotationPart, str]]]:
if re_entry["day_or_month_year"] is not None:
result = _parse_day_or_month(re_entry)
elif re_entry["year_month_or_day"] is not None:
result = _parse_year_month_or_day(re_entry)
elif re_entry["month_in_words"] is not None:
result = _parse_month_in_words(re_entry)
else:
result = None
return result