Download lifemem/parse.py from mtorres98/lifemem-replication-src: direct link, hf CLI and curl.
- Browser
- Download file 903 Bytes
-
https://huggingface.co/datasets/mtorres98/lifemem-replication-src/resolve/main/lifemem/parse.py
- Command line
-
hf download hf://datasets/mtorres98/lifemem-replication-src/lifemem/parse.py
-
curl -L -o parse.py https://huggingface.co/datasets/mtorres98/lifemem-replication-src/resolve/main/lifemem/parse.py
903 Bytes
| from __future__ import annotations | |
| import re | |
| _THINK_BLOCK = re.compile(r"<think>.*?</think>", re.DOTALL | re.IGNORECASE) | |
| def strip_thinking(text: str) -> str: | |
| """Drop Qwen thinking spans before Likert parsing.""" | |
| if not text: | |
| return "" | |
| cleaned = _THINK_BLOCK.sub("", text) | |
| marker = "</think>" | |
| lower = cleaned.lower() | |
| if marker in lower: | |
| cleaned = cleaned[lower.rfind(marker) + len(marker) :] | |
| return cleaned.strip() | |
| def parse_option_code(raw: str, valid_codes: tuple[str, ...]) -> str | None: | |
| if not raw: | |
| return None | |
| text = strip_thinking(raw) | |
| if text in valid_codes: | |
| return text | |
| match = re.search(r"\d+", text) | |
| if match and match.group(0) in valid_codes: | |
| return match.group(0) | |
| lowered = text.lower() | |
| for code in valid_codes: | |
| if code.lower() == lowered: | |
| return code | |
| return None | |