Skip to content

Commit

Permalink
修复分割函数中使用的变量错误 (#1443)
Browse files Browse the repository at this point in the history
* Fix force_breakdown function parameter name

* Add handling for PDFs with lowercase starting paragraphs

* Change first lowercase word in meta_txt to uppercase
  • Loading branch information
Menghuan1918 authored Jan 3, 2024
1 parent a96f842 commit aba8713
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions crazy_functions/crazy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ def starts_with_lowercase_word(s):
return True
else:
return False
# 对于某些PDF会有第一个段落就以小写字母开头,为了避免索引错误将其更改为大写
if starts_with_lowercase_word(meta_txt[0]):
meta_txt[0] = meta_txt[0].capitalize()
for _ in range(100):
for index, block_txt in enumerate(meta_txt):
if starts_with_lowercase_word(block_txt):
Expand Down
4 changes: 2 additions & 2 deletions crazy_functions/pdf_fns/breakdown_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def cut(limit, get_token_fn, txt_tocut, must_break_at_empty_line, break_anyway=F
# 如果没有找到合适的切分点
if break_anyway:
# 是否允许暴力切分
prev, post = force_breakdown(txt_tocut, limit, get_token_fn)
prev, post = force_breakdown(remain_txt_to_cut, limit, get_token_fn)
else:
# 不允许直接报错
raise RuntimeError(f"存在一行极长的文本!{txt_tocut}")
raise RuntimeError(f"存在一行极长的文本!{remain_txt_to_cut}")

# 追加列表
res.append(prev); fin_len+=len(prev)
Expand Down

0 comments on commit aba8713

Please sign in to comment.