MCPcopy Index your code
hub / github.com/KnowledgeXLab/LeanRAG / clean_str

Function clean_str

tools/_utils.py:209–217  ·  view source on GitHub ↗

Clean an input string by removing HTML escapes, control characters, and other unwanted characters.

(input: Any)

Source from the content-addressed store, hash-verified

207# Refer the utils functions of the official GraphRAG implementation:
208# https://github.com/microsoft/graphrag
209def 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 -----------------------------------------------------------------------

Calls

no outgoing calls

Tested by

no test coverage detected