Icici
pipelines.extraction.pdf.banks.icici
Summary
Icici bank-specific port implementations (pdf statement path).
Banks EXTEND the concrete Impl* classes — they never reinvent the ABC
contracts. Each Icici* class overrides only the behavior that DIFFERS from the
common Impl*; anything shared is inherited.
Derived from the real domain/extraction/banks/icici/pdf.py:
- NumberPort : Icici get_numbers returns decimals[-2:] (last 2)
- DescPort : Icici STARTTERS + fix_ocr OCR replacements
- AmountBalancePort : Icici adjust_balance negates balances flagged as negative by OCR brackets (the executed diff)
- TxnBlocksPort : Icici CONFIG (min_numbers=2, limit_first=True, line_offset=1, detect_date_ranges=True) as class attrs.
- RawLinesPort : Icici CONFIG covert_to_image=True (image-binarized OCR).
- missing_number_candidates : the Icici one-number hook, called live by ResolutionContext (Option B) — with only one OCR number, try it as either the amount or the balance.
Classes
IciciAmountBalancePort
Bases: ImplAmountBalancePort
Icici amount/balance leaf — negates bracketed OCR balances.
Attributes:
| Name | Type | Description |
|---|---|---|
number |
IciciNumberPort
|
Icici number leaf. |
Functions
adjust_balance
Negate a balance flagged as negative by OCR brackets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
balance |
float
|
OCR balance. |
required |
line |
str
|
Transaction line. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Negated balance when a bracket marker is present, else the |
float
|
balance unchanged. |
missing_number_candidates
Provide one-number candidates: the number as amount or as balance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx |
The active |
required |
Returns:
| Type | Description |
|---|---|
|
Set of |
resolve
Resolve (amount, balance) via ResolutionContext.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount |
OCR amount. |
required | |
balance |
OCR balance (adjusted first). |
required | |
prev_balance |
Previous transaction balance. |
required | |
line |
Raw transaction line. |
required | |
numbers |
Extracted numbers; default None. |
None
|
Returns:
| Type | Description |
|---|---|
|
(signed amount, resolved balance) tuple. |
IciciBucketFinderPort
Bases: ImplBucketFinderPort
Icici bucket finder — pins the Icici number leaf.
Functions
get_opening_balance_buckets
Divide raw lines into opening-balance buckets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines |
Raw text lines. |
required | |
limit_first |
Keep only the first bucket. |
False
|
|
line_offset |
Offset added to starting indices. |
0
|
Returns:
| Type | Description |
|---|---|
|
List of |
IciciDescPort
Bases: ImplDescPort
Icici description leaf — slices at Icici markers and fixes OCR typos.
Attributes:
| Name | Type | Description |
|---|---|---|
starters |
Optional[List[str]]
|
Description starter markers. |
Functions
extract_description
Extract and clean the transaction description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description |
str
|
Raw description text. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Cleaned description. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
When no starters are configured. |
fix_ocr
Fix common Icici OCR typos in the description text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text |
str
|
Text to fix. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Text with OCR replacements applied. |
IciciNumberPort
Bases: ImplNumberPort
Icici number leaf — prefers the last two decimal numbers.
Functions
get_numbers
Extract monetary numbers, preferring trailing decimals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line |
str
|
Text line to scan. |
required |
Returns:
| Type | Description |
|---|---|
List[float]
|
List[float]: Cleaned monetary numbers. |
get_opening_balance
Return the last number as the opening balance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line |
str
|
Text line to scan. |
required |
Returns:
| Type | Description |
|---|---|
Optional[float]
|
Optional[float]: The last number, else |
IciciPdfExtractionPipeline
Bases: ImplPDFExtractionPipeline
Icici pdf graph root — pins raw-lines, txn-blocks, and txn-dicts stages.
Attributes:
| Name | Type | Description |
|---|---|---|
raw_lines |
IciciRawLinesPort
|
Icici raw-lines stage. |
txn_blocks |
IciciTxnBlocksPort
|
Icici txn-blocks stage. |
txn_dicts |
IciciTxnDictsPort
|
Icici txn-dicts stage. |
Functions
run
Run the pdf extraction chain end-to-end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source |
Raw extraction source. |
required |
Returns:
| Type | Description |
|---|---|
|
List of raw expense records. |
IciciRawLinesPort
Bases: ImplRawLinesPort
Icici raw-lines leaf — binarized OCR.
Attributes:
| Name | Type | Description |
|---|---|---|
covert_to_image |
bool
|
Binarize pages via image conversion. |
Functions
extract
Extract raw OCR text lines from content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content |
PDF bytes, Content, or dict payload. |
required |
Returns:
| Type | Description |
|---|---|
|
List of raw text lines. |
Raises:
| Type | Description |
|---|---|
TypeError
|
When content is not PDF bytes or Content with |
IciciSplitterPort
Bases: ImplSplitterPort
Icici splitter — pins the Icici number leaf.
Functions
split_blocks
Split bucket lines into transaction blocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines |
Bucket lines. |
required | |
has_header |
Whether a header precedes the rows. |
False
|
|
min_numbers |
Minimum numbers for a split. |
3
|
|
detect_date_ranges |
Detect date-range lines. |
False
|
Returns:
| Type | Description |
|---|---|
|
List of transaction block texts. |
IciciTransactionParserPort
Bases: ImplTransactionParserPort
Icici transaction parser — pins Icici-stage leaves and indices.
Attributes:
| Name | Type | Description |
|---|---|---|
number |
IciciNumberPort
|
Icici number leaf. |
desc |
IciciDescPort
|
Icici description leaf. |
amount_balance |
IciciAmountBalancePort
|
Icici amount/balance leaf. |
min_numbers |
int
|
Minimum numbers for a block. |
amount_index |
int
|
Index of the amount in the number list. |
balance_index |
int
|
Index of the balance in the number list. |
Functions
parse
Parse a transaction block into a txn dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
txn_text |
Transaction block text. |
required | |
prev_date_str |
Previous transaction date string. |
required | |
prev_balance |
Running balance from the previous transaction. |
required |
Returns:
| Type | Description |
|---|---|
|
Txn dict, or |
IciciTxnBlocksPort
Bases: ImplTxnBlocksPort
Icici txn-blocks stage — min_numbers=2, first bucket only.
Attributes:
| Name | Type | Description |
|---|---|---|
bucket_finder |
IciciBucketFinderPort
|
Icici bucket finder. |
splitter |
IciciSplitterPort
|
Icici splitter. |
min_numbers |
int
|
Minimum numbers for a block. |
limit_first |
bool
|
Keep only the first bucket. |
line_offset |
int
|
Offset added to starting indices. |
detect_date_ranges |
bool
|
Date-range detection enabled. |
Functions
extract
Extract txn blocks keyed by opening balance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_lines |
Raw OCR text lines. |
required |
Returns:
| Type | Description |
|---|---|
|
Dict[float, List[str]]: Opening balance → block texts. |
IciciTxnDictsPort
Bases: ImplTxnDictsPort
Icici txn-dicts stage — pins the Icici transaction parser.
Functions
extract
Extract balance-chained txn dicts from blocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
txn_blocks |
Opening balance → block texts. |
required |
Returns:
| Type | Description |
|---|---|
|
List of txn dicts. |