MCPcopy Create free account
hub / github.com/NanGePlus/LightRAGTest / clean_str

Function clean_str

LightRAG/lightrag/utils.py:170–178  ·  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

168# Refer the utils functions of the official GraphRAG implementation:
169# https://github.com/microsoft/graphrag
170def 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
181def is_float_regex(value):

Calls

no outgoing calls

Tested by

no test coverage detected