Download code/numeric_target_scoring_v2.py from dfdu233/MeningiomaBench: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/datasets/dfdu233/MeningiomaBench/resolve/main/code/numeric_target_scoring_v2.py
- Command line
-
hf download hf://datasets/dfdu233/MeningiomaBench/code/numeric_target_scoring_v2.py
-
curl -L -o numeric_target_scoring_v2.py https://huggingface.co/datasets/dfdu233/MeningiomaBench/resolve/main/code/numeric_target_scoring_v2.py
1.71 kB
| """Representation-aware parsing; preserve explicit time qualifiers for separate checks.""" | |
| import re | |
| from numeric_target_scoring import N, U, SEP, unit, parse_answer as parse_v1 | |
| def parse_answer(text, expected_kind): | |
| if not isinstance(text, str): | |
| return None | |
| clean = text.strip().replace('−', '-') | |
| marker = re.match(r'^(approximately|about|~)\s*', clean, re.I) | |
| approximate = marker.group(1) if marker else None | |
| if marker: | |
| clean = clean[marker.end():] | |
| if clean.endswith('.'): | |
| clean = clean[:-1].rstrip() | |
| result = parse_v1(clean, expected_kind) | |
| if result is None and expected_kind == 'estimate_with_ci': | |
| pattern = (rf'(?P<value>{N})\s*(?P<unit>{U})\s*' | |
| rf'(?:at\s+(?P<time_value>{N})\s+(?P<time_unit>years?|months?|days?))?\s*\(\s*' | |
| rf'(?:(?P<confidence_level>{N})\s*%\s*(?:CI|confidence interval)\s*[:,]?\s*)?' | |
| rf'(?P<lower>{N})\s*(?P<lower_unit>{U})?\s*{SEP}\s*' | |
| rf'(?P<upper>{N})\s*(?P<upper_unit>{U})?\s*\)') | |
| match = re.fullmatch(pattern, clean, re.I) | |
| if match: | |
| data = {k: v for k, v in match.groupdict().items() if v is not None} | |
| if any(unit(data[k]) != unit(data['unit']) for k in ('lower_unit', 'upper_unit') if k in data): | |
| return None | |
| data.pop('lower_unit', None); data.pop('upper_unit', None) | |
| if 'time_value' in data: | |
| data['reported_timepoint'] = {'value': data.pop('time_value'), 'unit': unit(data.pop('time_unit'))} | |
| result = {'kind': 'estimate_with_ci', **data} | |
| if result is not None and approximate: | |
| result['approximation_marker'] = approximate | |
| return result | |