Utils
domain.enrichment.entity.utils
Summary
Text utilities for entity enrichment: description normalization, number sequence removal, candidate validity checks, and candidate extraction.
Functions
extract_candidates
Extract validated payee candidates from a description.
For each regex, reads the payee named group, checks validity,
and appends the normalized key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description |
str
|
Description text to scan. |
required |
candidate_regexes |
Iterable[Pattern]
|
Compiled regexes exposing a |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Validated, normalized candidate keys. |
is_valid_candidate
Check whether a string is a plausible entity candidate.
Rejects empty/short strings, pure-hex strings, and pure digits (unless exactly 10 digits); requires at least one letter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidate |
str
|
Candidate string to validate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
lookup_mapping
Look up candidate display names in a mapping.
A normalized exact key match returns the single mapped name; otherwise
returns every mapped name whose key is a substring of the candidate.
Falsy candidates return (None, None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidate |
str
|
Candidate to look up. |
required |
mapping |
dict
|
Mapping of normalized keys to |
required |
Returns:
| Type | Description |
|---|---|
|
A single matching name, a list of substring matches, or |
|
|
|
normalize_description
Normalize a description for downstream matching.
Strips whitespace, drops page N of M markers, OCR hex blobs,
separators, @ and ., collapses runs of spaces, and
lower-cases the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text |
str
|
Raw description text. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The normalized, lower-cased description. |
normalize_money_str
Format a number as a two-decimal string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x |
Value coercible to |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The number formatted to two decimals. |
normalize_person_handle
Normalize a UPI-style handle into a display name.
Strips the @ suffix and trailing digits, capitalizes word pieces
(preserving known acronyms), and removes bracket characters; returns
"" when the result is purely hex-like.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handle |
str
|
Raw handle string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The normalized person name (possibly empty). |
remove_number_sequence
Strip digit runs that echo the amount/balance.
Builds a regex from the concatenated amount+balance digits and removes candidate runs within one edit of that digit string, collapsing the remaining whitespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text |
str
|
Description text to clean. |
required |
amt |
str
|
Transaction amount, formatted via |
required |
bal |
str
|
Balance, formatted via |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The cleaned description with echoed numbers removed. |