mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 19:17:13 -05:00 
			
		
		
		
	Extends the regex to find dates in documents as reported by @isaacsando
This commit is contained in:
		
							parent
							
								
									178361b247
								
							
						
					
					
						commit
						07d06d9aee
					
				@ -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
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								src/paperless_tesseract/tests/samples/tests_date_8.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/paperless_tesseract/tests/samples/tests_date_8.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								src/paperless_tesseract/tests/samples/tests_date_9.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/paperless_tesseract/tests/samples/tests_date_9.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@ -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()))
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user