MCPcopy Create free account
hub / github.com/Saberlve/LLM-Kit / text_parse

Function text_parse

text_parse/parse.py:24–49  ·  view source on GitHub ↗

Text document parsing, which is essentially making a copy of the file :param file_path: Original file path :param save_path: Path for the parsed file :return: Path of the parsed file

(file_path,save_path)

Source from the content-addressed store, hash-verified

22 return str(res) if res is not None else ""
23
24def text_parse(file_path,save_path):
25 """
26 Text document parsing, which is essentially making a copy of the file
27 :param file_path: Original file path
28 :param save_path: Path for the parsed file
29 :return: Path of the parsed file
30 """
31
32 # Read file content
33 with open(file_path, 'r', encoding='utf-8') as f:
34 data = f.readlines()
35
36 print(f"Parsing text file and saving results to {save_path}")
37
38 # Get filename and construct save path
39 file_name = file_path.split('/')[-1] # Extract filename
40 base_name = file_name.split('.')[0] # Extract part without extension
41 save_file_path = os.path.join(save_path, base_name + '.txt').replace('\\', '/') # Concatenate full path
42
43 # Ensure the save path directory exists
44 os.makedirs(save_path, exist_ok=True)
45 # Write to file
46 with open(save_file_path, 'w', encoding='utf-8') as f:
47 for line in data:
48 f.write(line)
49 return save_file_path
50
51def pdf_parse(file_path, save_path, progress_callback=None):
52 """PDF file parsing, supports progress callback"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected