File size: 1,016 Bytes
7bbae49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from app.extract_dates.validate_date import find_smallest_date, validate_date


def date_extractor(ocr_list):
    try:
        global dob_found
        dob_found = False
        dob = None
        dates_list = []

        for index,word in enumerate(ocr_list):
            date_valid ,pattern = validate_date(word)
            if date_valid:
                # valid_pattern = pattern
                ocr_list.pop(index) # removing elements from list that is being used.
                dates_list.append(word)

        if dates_list:
            # print(dates_list)
            dob = find_smallest_date(dates_list) # smallest date will be DOB
            dob_found = True

            print("DATE OF BIRTH : ", dob)
        else:
            print("Date not found")
            dob_found = False
            dob = ''
        
        return dob_found, dob, ocr_list
        
    except Exception as e:
        print("[Exception in date_extractor] : ", str(e))
        dob = ''
        return dob_found, dob, ocr_list