我必须从 PDF 中提取所有可用的日期,然后检查合同日期的日期。
首先,我想提取从 PDF 中提取的文本中的所有日期。现在日期可以是各种格式。我尝试在下面的示例中添加所有口味的日期。
我尝试使用Datefinder Python 模块来提取所有日期。虽然它很接近,但最初抛出的垃圾日期很少,也与第一个 Date 不正确匹配。
import datefinder
dateContent = """ Test
I want to apply for leaves August, 11, 2017 I want to apply for leaves Aug, 23, 2017 I want to apply for leaves Aug, 21, 17
I want to apply for leaves August 20 2017
I want to apply for leaves August 30th, 2017 I want to apply for leaves August 31st 17
I want to apply for leaves 8/26/2017 I want to apply for leaves 8/27/17
I want to apply for leaves 28/8/2017 I want to apply for leaves 29/8/17 I want to apply for leaves 30/08/17
I want to apply for leaves 15 Jan 17 I want to apply for leaves 14 January 17
I want to apply for leaves 13 Jan 2017
I want to apply for leaves Jan 10 17 I want to apply for leaves Jan 11 2017 I want to apply for leaves January 12 2017
"""
matches = datefinder.find_dates(dateContent)
for match in matches:
print(match)
回复 :
2019-08-05 00:00:00
2019-06-11 00:00:00
2017-06-05 00:00:00
2017-08-23 00:00:00
2017-08-21 00:00:00
2017-08-20 00:00:00
2017-08-30 00:00:00
2017-08-31 00:00:00
2017-08-26 00:00:00
2017-08-27 00:00:00
2017-08-28 00:00:00
2017-08-29 00:00:00
2017-08-30 00:00:00
2017-01-15 00:00:00
2017-01-14 00:00:00
2017-01-13 00:00:00
2017-01-10 00:00:00
2017-01-11 00:00:00
2017-01-12 00:00:00
如您所见,我有 17 个这样的 Date 对象,但我得到了 19 个。从底部检查,最后 16 个匹配正确。然后是那些最初的垃圾。 一旦我正确地获得了这些日期,我就可以使用某种 N-Gram 模型来检查哪些日期上下文是合同信息。
解决问题的任何帮助都会很棒。