Merged in optimization/tin_npi (pull request #790)
Optimization/tin npi * updated signature page and added for tin npi * updated signature page * removed print statements * removed print statement * updated test for extract signature page * updated data type Approved-by: Katon Minhas
This commit is contained in:
committed by
Katon Minhas
parent
4334800fa3
commit
2482adb465
@@ -379,6 +379,12 @@ def extract_signature_page(text_dict: dict, filename: str) -> dict:
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
keywords = [
|
||||
"signature and information",
|
||||
"signature authorization",
|
||||
"in witness whereof",
|
||||
]
|
||||
|
||||
# First pass: Try to match the full textract pattern
|
||||
for page_num, page_text in text_dict.items():
|
||||
if textract_pattern.search(page_text):
|
||||
@@ -386,22 +392,20 @@ def extract_signature_page(text_dict: dict, filename: str) -> dict:
|
||||
|
||||
# If no pages found with textract pattern, try with keyword
|
||||
if not signature_pages:
|
||||
page_items = list(text_dict.items())
|
||||
for i, (page_num, page_text) in enumerate(page_items):
|
||||
# Iterate through each page in the text dictionary and check for keywords
|
||||
for page_num, page_text in text_dict.items():
|
||||
lower_text = page_text.lower()
|
||||
if (
|
||||
"signature page follow" in lower_text
|
||||
or "signature authorization" in lower_text
|
||||
):
|
||||
# curr_page = int(float(page_num))
|
||||
if page_num not in signature_pages:
|
||||
signature_pages[page_num] = page_text # current page
|
||||
if i + 1 < len(page_items):
|
||||
next_page_num, next_page_text = page_items[i + 1]
|
||||
# next_page = int(float(next_page_num))
|
||||
if next_page_num not in signature_pages:
|
||||
signature_pages[next_page_num] = next_page_text # next page
|
||||
if any(keyword in lower_text for keyword in keywords):
|
||||
signature_pages[page_num] = page_text
|
||||
|
||||
# If no signature pages found, try checking for the word "signature page follows" and return the next page only if it exists
|
||||
if not signature_pages:
|
||||
for page_num, page_text in text_dict.items():
|
||||
if "signature page follows" in page_text.lower():
|
||||
next_page_num = str(int(page_num) + 1)
|
||||
if next_page_num in text_dict:
|
||||
signature_pages[next_page_num] = text_dict[next_page_num]
|
||||
|
||||
return signature_pages
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user