Download utils.py from sanjoy19/RAGBench_General_knowledge1: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/sanjoy19/RAGBench_General_knowledge1/resolve/main/utils.py
- Command line
-
hf download hf://spaces/sanjoy19/RAGBench_General_knowledge1/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/sanjoy19/RAGBench_General_knowledge1/resolve/main/utils.py
1.09 kB
| import re | |
| # ===================================================== | |
| # Convert Contract ID to Filesystem-Safe Format | |
| # ===================================================== | |
| def safe_contract_id(contract_id: str) -> str: | |
| """ | |
| Convert a contract ID to a filesystem-safe directory name. | |
| """ | |
| contract_id = re.sub(r'[<>:"/\\|?*#]', "_", contract_id) | |
| contract_id = re.sub(r"\s+", " ", contract_id).strip() | |
| return contract_id | |
| # ===================================================== | |
| # Extract Contract ID | |
| # ===================================================== | |
| def get_contract_id(sample_id: str) -> str: | |
| """ | |
| Extract the contract ID from a CUAD sample ID and | |
| return its filesystem-safe version. | |
| """ | |
| return safe_contract_id(sample_id.split("__", 1)[0]) | |
| # ===================================================== | |
| # Get Contract ID for Legal Dataset | |
| # ===================================================== | |
| def get_contract_id_if_needed( | |
| config, contract_id | |
| ): | |
| if config.domain != "legal": | |
| return None | |
| return get_contract_id(contract_id) | |