Spaces:
Sleeping
Sleeping
Download src/evaluation/citation_parser.py from Kurapika993/papermind: direct link, hf CLI and curl.
- Browser
- Download file 821 Bytes
-
https://huggingface.co/spaces/Kurapika993/papermind/resolve/main/src/evaluation/citation_parser.py
- Command line
-
hf download hf://spaces/Kurapika993/papermind/src/evaluation/citation_parser.py
-
curl -L -o citation_parser.py https://huggingface.co/spaces/Kurapika993/papermind/resolve/main/src/evaluation/citation_parser.py
821 Bytes
| from __future__ import annotations | |
| import re | |
| EVIDENCE_ID = re.compile(r"\bE\d+\b", re.IGNORECASE) | |
| def normalize_evidence_id(value: str) -> str: | |
| match = EVIDENCE_ID.search(value.strip()) | |
| return match.group(0).upper() if match else "" | |
| def extract_evidence_ids(text: str) -> list[str]: | |
| return list(dict.fromkeys(match.upper() for match in EVIDENCE_ID.findall(text))) | |
| def cited_sentences(markdown: str) -> list[tuple[str, list[str]]]: | |
| normalized = re.sub(r"\s+", " ", markdown).strip() | |
| if not normalized: | |
| return [] | |
| sentences = re.split(r"(?<=[.!?])\s+(?=[A-Z0-9*])", normalized) | |
| output: list[tuple[str, list[str]]] = [] | |
| for sentence in sentences: | |
| ids = extract_evidence_ids(sentence) | |
| if ids: | |
| output.append((sentence.strip(), ids)) | |
| return output | |