mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-23 06:46:40 +08:00
Refactor:book parser use with to handle bytesIO (#11800)
### What problem does this PR solve? book parser use with to handle bytesIO ### Type of change - [x] Refactoring
This commit is contained in:
@ -143,13 +143,14 @@ def chunk(filename, binary=None, from_page=0, to_page=100000,
|
|||||||
|
|
||||||
elif re.search(r"\.doc$", filename, re.IGNORECASE):
|
elif re.search(r"\.doc$", filename, re.IGNORECASE):
|
||||||
callback(0.1, "Start to parse.")
|
callback(0.1, "Start to parse.")
|
||||||
binary = BytesIO(binary)
|
with BytesIO(binary) as binary:
|
||||||
doc_parsed = parser.from_buffer(binary)
|
binary = BytesIO(binary)
|
||||||
sections = doc_parsed['content'].split('\n')
|
doc_parsed = parser.from_buffer(binary)
|
||||||
sections = [(line, "") for line in sections if line]
|
sections = doc_parsed['content'].split('\n')
|
||||||
remove_contents_table(sections, eng=is_english(
|
sections = [(line, "") for line in sections if line]
|
||||||
random_choices([t for t, _ in sections], k=200)))
|
remove_contents_table(sections, eng=is_english(
|
||||||
callback(0.8, "Finish parsing.")
|
random_choices([t for t, _ in sections], k=200)))
|
||||||
|
callback(0.8, "Finish parsing.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
|
|||||||
Reference in New Issue
Block a user