Fix Indian Bank statement detection and extraction
This commit is contained in:
@@ -8,11 +8,22 @@ class IndianBankModernParser(BaseParser):
|
|||||||
bank_name='Indian Bank'; parser_name='IndianBankModernParser'
|
bank_name='Indian Bank'; parser_name='IndianBankModernParser'
|
||||||
@classmethod
|
@classmethod
|
||||||
def detect(cls,text):
|
def detect(cls,text):
|
||||||
u=text.upper(); return 0.98 if 'ACCOUNT STATEMENT' in u and 'TRANSACTION DETAILS' in u and 'TOTAL CREDITS' in u else 0
|
# pdfplumber's layout mode can insert multiple spaces inside headings
|
||||||
|
# (for example, 'ACCOUNT STATEMENT'). Normalize whitespace before
|
||||||
|
# matching so the same bank PDF is detected whether pdftotext is
|
||||||
|
# installed in the runtime image or the pdfplumber fallback is used.
|
||||||
|
u=norm(text).upper()
|
||||||
|
return 0.98 if 'ACCOUNT STATEMENT' in u and 'TRANSACTION DETAILS' in u and 'TOTAL CREDITS' in u else 0
|
||||||
def parse(self,path,text=None):
|
def parse(self,path,text=None):
|
||||||
text=text or extract_text(path); meta=StatementMeta(bank_name=self.bank_name,source_file=Path(path).name,parser_name=self.parser_name,confidence='High')
|
text=text or extract_text(path); meta=StatementMeta(bank_name=self.bank_name,source_file=Path(path).name,parser_name=self.parser_name,confidence='High')
|
||||||
meta.customer_name=find(r'Account Holder Name\s*\n\s*([^\n]+)',text)
|
# Some Indian Bank statements leave these values blank. Do not let a
|
||||||
meta.account_number=find(r'Account Number\s*\n?\s*([0-9X*]+)',text)
|
# value from the adjacent ACCOUNT SUMMARY column become the customer
|
||||||
|
# name merely because PDF text extraction merges the two columns.
|
||||||
|
customer=find(r'Account Holder Name[ \t]*([^\n]*)',text)
|
||||||
|
customer=norm(customer)
|
||||||
|
if customer and not re.search(r'^(Opening Balance|Account Type|Account Number|Customer)',customer,re.I):
|
||||||
|
meta.customer_name=customer
|
||||||
|
meta.account_number=find(r'Account Number[ \t]*([0-9X*]{4,})',text)
|
||||||
m=re.search(r'For period:\s*(\d{2}\s+[A-Za-z]{3}\s+\d{4})\s*-\s*(\d{2}\s+[A-Za-z]{3}\s+\d{4})',text,re.I)
|
m=re.search(r'For period:\s*(\d{2}\s+[A-Za-z]{3}\s+\d{4})\s*-\s*(\d{2}\s+[A-Za-z]{3}\s+\d{4})',text,re.I)
|
||||||
if m:
|
if m:
|
||||||
meta.period_from=pd.to_datetime(m.group(1),dayfirst=True).strftime('%Y-%m-%d'); meta.period_to=pd.to_datetime(m.group(2),dayfirst=True).strftime('%Y-%m-%d')
|
meta.period_from=pd.to_datetime(m.group(1),dayfirst=True).strftime('%Y-%m-%d'); meta.period_to=pd.to_datetime(m.group(2),dayfirst=True).strftime('%Y-%m-%d')
|
||||||
|
|||||||
Reference in New Issue
Block a user