diff --git a/src/paperless_tesseract/parsers.py b/src/paperless_tesseract/parsers.py index 85209dd8e..847e87f1a 100644 --- a/src/paperless_tesseract/parsers.py +++ b/src/paperless_tesseract/parsers.py @@ -208,11 +208,13 @@ class RasterisedDocumentParser(DocumentParser): # - XX/YY/ZZZZ with XX + YY being 1 or 2 and ZZZZ being 2 or 4 digits # - XX-YY-ZZZZ with XX + YY being 1 or 2 and ZZZZ being 2 or 4 digits # - XX. MONTH ZZZZ with XX being 1 or 2 and ZZZZ being 2 or 4 digits - # - MONTH ZZZZ + # - MONTH ZZZZ, with ZZZZ being 4 digits + # - MONTH XX, ZZZZ with XX being 1 or 2 and ZZZZ being 4 digits m = re.search( r'\b([0-9]{1,2})[\.\/-]([0-9]{1,2})[\.\/-]([0-9]{4}|[0-9]{2})\b|' + - r'\b([0-9]{1,2}\. [^ ]{3,9} ([0-9]{4}|[0-9]{2}))\b|' + - r'\b([^ ]{3,9} [0-9]{4})\b', text) + r'\b([0-9]{1,2}[\. ]+[^ ]{3,9} ([0-9]{4}|[0-9]{2}))\b|' + + r'\b([\w]{3,9} [0-9]{1,2}, ([0-9]{4}))\b|' + + r'\b([\w]{3,9} [0-9]{4})\b', text) if m is None: return None diff --git a/src/paperless_tesseract/tests/samples/tests_date_8.pdf b/src/paperless_tesseract/tests/samples/tests_date_8.pdf new file mode 100644 index 000000000..ea7495f29 Binary files /dev/null and b/src/paperless_tesseract/tests/samples/tests_date_8.pdf differ diff --git a/src/paperless_tesseract/tests/samples/tests_date_9.pdf b/src/paperless_tesseract/tests/samples/tests_date_9.pdf new file mode 100644 index 000000000..2dedadf56 Binary files /dev/null and b/src/paperless_tesseract/tests/samples/tests_date_9.pdf differ diff --git a/src/paperless_tesseract/tests/test_date.py b/src/paperless_tesseract/tests/test_date.py index 019d5199a..7b1f75f6c 100644 --- a/src/paperless_tesseract/tests/test_date.py +++ b/src/paperless_tesseract/tests/test_date.py @@ -204,3 +204,29 @@ class TestDate(TestCase): self.assertEqual(document.get_date(), datetime.datetime(2018, 4, 1, 0, 0, tzinfo=tz.tzutc())) + + @mock.patch( + "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", + SAMPLE_FILES + ) + def test_get_text_8_pdf(self): + input_file = os.path.join(self.SAMPLE_FILES, "tests_date_8.pdf") + document = RasterisedDocumentParser(input_file) + document.get_text() + self.assertEqual(document._is_ocred(), True) + self.assertEqual(document.get_date(), + datetime.datetime(2017, 12, 31, 0, 0, + tzinfo=tz.tzutc())) + + @mock.patch( + "paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH", + SAMPLE_FILES + ) + def test_get_text_9_pdf(self): + input_file = os.path.join(self.SAMPLE_FILES, "tests_date_9.pdf") + document = RasterisedDocumentParser(input_file) + document.get_text() + self.assertEqual(document._is_ocred(), True) + self.assertEqual(document.get_date(), + datetime.datetime(2017, 12, 31, 0, 0, + tzinfo=tz.tzutc()))