S=“20多年来,这项投资的成本是中性的,因为它被一个适度的、舒适的ch arge™Œ覆盖,低于基于well -proven EnergieSprong模型的等效能源账单Œ。资本预算不是投机性的将投资于商业地产(商业案例尚不清楚),而是建议地方政府在开发新太阳能农场的不断壮大的基础上,向市政总署( j oin )提出建议。这符合我们的政策目标,并提供一个温和但有保障的回报(不包括借款)。我们建议投资的5100万英镑(类似于最初打算用于商业公关操作的金额)。“
这是一个使用基本python及其PyPDF库从web中获取的文本。
我想删除黑体字中不需要的空格。
Note:为了解释我的问题,我手工地把它们写成了粗体的。如果有人能帮上忙我会很感激的。提前谢谢!
发布于 2022-03-22 16:38:17
请参阅我的答案和这条线中的其他答案。
假设您从这个DOCX或此PDF获取文本:如果您有DOCX,那么使用它而不是pdf,因为docx是一种基于XML的格式,可以在没有错误的情况下从其中提取文本。
您还会注意到,如果将pdf文档复制并粘贴到任何其他文本文档中,就不会得到这些错误的空格,因为这是一个导致PDF解析器工作方式的问题(对字符的水平间距感到困惑,并在基于字符位置有空格的情况下做错误的假设)。
您可以尝试使用不同的解析器或复制并粘贴(当然,只有当它不是图像PDF )到易于解析的格式,以避免这些问题。
通常,您可能可以通过尝试修复结果文本来降低错误率(如果确实需要,请查看光学字符识别后更正/OCR Post更正),但是使用这段时间来改进解析可能会更有效。
发布于 2022-03-22 09:12:34
此方法删除单词中的空白。
def remove_space_in_word(text, word):
index = text.find(word)
parts = word.split(" ")
part1_len = len(parts[0])
return text[:index + part1_len] + text[index + part1_len + 1:]输出:

发布于 2022-03-22 10:26:18
简单的人工方法
如果您已经确定'pr operty'倾向于使用额外的空格编写,下面是一个简单的函数,它将从所有出现的pr operty中删除空格
def remove_whitespace_in_word(text, word):
return text.replace(word, ''.join(word.split()))
s = "The pr operty. Over 20 years of pr operty, this investment is cost neutral as it is covered by a modest ‚comfort ch arge™ Œ less than the equivalent energy bills would have been Œ based on the well -proven EnergieSprong model. Capital Budget Rather than speculatively invest ing in commercial property, for which the business case is unclear, we propose that the Council j oin the growing ranks of local authorities developing new solar farms. This meets our pr operty policy objectives and provides a modest, but secure, return (net of borrowing). The £51m we propose to invest in pr operty (similar to the amount originally intended for commercial pr operty)"
new_text = remove_whitespace_in_word(s, 'pr operty')
print(new_text)
# 'The property. Over 20 years of property, this investment is cost neutral as it is covered by a modest ‚comfort ch arge™ Œ less than the equivalent energy bills would have been Œ based on the well -proven EnergieSprong model. Capital Budget Rather than speculatively invest ing in commercial property, for which the business case is unclear, we propose that the Council j oin the growing ranks of local authorities developing new solar farms. This meets our property policy objectives and provides a modest, but secure, return (net of borrowing). The £51m we propose to invest in property (similar to the amount originally intended for commercial property)'您只需要调用它一次就可以修复pr operty的所有出现;但是您需要对其他每一个违规的单词(例如ch arge )再次调用它。
复杂的自动化方法
下面是一种建议的算法。这并不完美,但应该处理许多错误:
"pr operty",您只需要询问一次确认。https://stackoverflow.com/questions/71568547
复制相似问题