MCPcopy Create free account
hub / github.com/CIawevy/TextPecker / preprocess_string

Function preprocess_string

eval/OneIG-Benchmark/scripts/text/text_utils.py:5–15  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

3from collections import Counter
4
5def preprocess_string(s):
6 cleaned = re.sub(r"[^\u4e00-\u9fa5a-zA-Z0-9\sàâäéèêëîïôöùûüçÀÂÄÉÈÊËÎÏÔÖÙÛÜÇ]", '', s)
7 if contains_chinese(cleaned):
8 pattern = re.compile(r"[\u4e00-\u9fa5a-zA-Z0-9àâäéèêëîïôöùûüçÀÂÄÉÈÊËÎÏÔÖÙÛÜÇ]")
9 s = ''.join(pattern.findall(s))
10
11 return s.strip()
12
13 normalized = re.sub(r'\s+', ' ', cleaned)
14
15 return normalized.strip()
16
17def clean_and_remove_hallucinations(texts):
18 # keywords_list can be added to process ocr results to a cleaner version

Callers 1

mainFunction · 0.90

Calls 1

contains_chineseFunction · 0.85

Tested by

no test coverage detected