Download src/utils/string_utils.py from EQUES/Response-Quality-Assessment: direct link, hf CLI and curl.
- Browser
- Download file 858 Bytes
-
https://huggingface.co/spaces/EQUES/Response-Quality-Assessment/resolve/main/src/utils/string_utils.py
- Command line
-
hf download hf://spaces/EQUES/Response-Quality-Assessment/src/utils/string_utils.py
-
curl -L -o string_utils.py https://huggingface.co/spaces/EQUES/Response-Quality-Assessment/resolve/main/src/utils/string_utils.py
858 Bytes
| import re | |
| def extract_tag_content(input_string): | |
| # Use regular expression to find all content between <s> and </s> tags | |
| pattern = re.compile(r"<s>(.*?)</s>") | |
| matches = pattern.findall(input_string) | |
| return matches | |
| def extract_array_result(input_string): | |
| # Use regular expression to find array result betweenn [] | |
| # Assume input only have 1 array, or just want to get first array | |
| pattern = re.compile( | |
| r"\[(.*?)\]", re.DOTALL | |
| ) # Use DOTALL to handle multiline content | |
| matches = pattern.findall(input_string) | |
| if len(matches) > 0: | |
| return matches[0] | |
| return "[]" | |
| def extract_string_array(input_string): | |
| items = input_string.strip("[").strip("]").strip('"').strip().split(";") | |
| # remove empty string in list and trim \n | |
| items = [i.replace("\n", "") for i in items if i] | |
| return items | |