Datasets:
compactfact-training-data / sources /date-head /src /compact_fact_extraction /normalization /agreements.py
Download sources/date-head/src/compact_fact_extraction/normalization/agreements.py from Monyzik/compactfact-training-data: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/datasets/Monyzik/compactfact-training-data/resolve/main/sources/date-head/src/compact_fact_extraction/normalization/agreements.py
- Command line
-
hf download hf://datasets/Monyzik/compactfact-training-data/sources/date-head/src/compact_fact_extraction/normalization/agreements.py
-
curl -L -o agreements.py https://huggingface.co/datasets/Monyzik/compactfact-training-data/resolve/main/sources/date-head/src/compact_fact_extraction/normalization/agreements.py
1.42 kB
| """Recover unambiguous future deadlines near the source of an agreement.""" | |
| from collections import defaultdict | |
| from datetime import datetime | |
| import re | |
| _TODAY = re.compile(r"\b(?:сегодня|сегодняшн\w*|прямо\s+сейчас)\b", re.I) | |
| def future_dates_by_turn(candidates, anchor): | |
| by_turn = defaultdict(set) | |
| for candidate in candidates: | |
| if candidate["turn"] < 0 or candidate["value"] is None: | |
| continue | |
| value = datetime.fromisoformat(candidate["value"]) | |
| if value.date() > anchor.date(): | |
| by_turn[candidate["turn"]].add(value) | |
| return by_turn | |
| def agreement_deadline(future_dates, turns, source, anchor, start, end): | |
| """Return a deadline when a same-day fallback has one nearby alternative.""" | |
| if start.date() != anchor.date() or _TODAY.search(turns[source]["text"]): | |
| return start | |
| nearby = future_dates.get(source, set()) | |
| if not nearby: | |
| nearby = future_dates.get(source - 1, set()) | future_dates.get(source + 1, set()) | |
| if len({value.date() for value in nearby}) != 1: | |
| return start | |
| explicit_times = {value for value in nearby if value.hour or value.minute} | |
| if len(explicit_times) == 1: | |
| deadline = next(iter(explicit_times)) | |
| else: | |
| deadline = min(nearby).replace(hour=0, minute=0, second=0, microsecond=0) | |
| return deadline if end is None or deadline <= end else start | |