Clean an input string by removing HTML escapes, control characters, and other unwanted characters.
(input: Any)
| 168 | # Refer the utils functions of the official GraphRAG implementation: |
| 169 | # https://github.com/microsoft/graphrag |
| 170 | def clean_str(input: Any) -> str: |
| 171 | """Clean an input string by removing HTML escapes, control characters, and other unwanted characters.""" |
| 172 | # If we get non-string input, just give it back |
| 173 | if not isinstance(input, str): |
| 174 | return input |
| 175 | |
| 176 | result = html.unescape(input.strip()) |
| 177 | # https://stackoverflow.com/questions/4324790/removing-control-characters-from-a-string-in-python |
| 178 | return re.sub(r"[\x00-\x1f\x7f-\x9f]", "", result) |
| 179 | |
| 180 | |
| 181 | def is_float_regex(value): |
no outgoing calls
no test coverage detected