Clean an input string by removing HTML escapes, control characters, and other unwanted characters.
(input: Any)
| 207 | # Refer the utils functions of the official GraphRAG implementation: |
| 208 | # https://github.com/microsoft/graphrag |
| 209 | def clean_str(input: Any) -> str: |
| 210 | """Clean an input string by removing HTML escapes, control characters, and other unwanted characters.""" |
| 211 | # If we get non-string input, just give it back |
| 212 | if not isinstance(input, str): |
| 213 | return input |
| 214 | |
| 215 | result = html.unescape(input.strip()) |
| 216 | # https://stackoverflow.com/questions/4324790/removing-control-characters-from-a-string-in-python |
| 217 | return re.sub(r"[\x00-\x1f\x7f-\x9f]", "", result) |
| 218 | |
| 219 | |
| 220 | # Utils types ----------------------------------------------------------------------- |
no outgoing calls
no test coverage detected