Skip to content

Utils

pipelines.enrichment.shared.utils

Summary

Description/candidate utilities (port of domain/enrichment/entity/utils.py).

Functions

extract_candidates

1
2
3
4
extract_candidates(
    description: str,
    candidate_regexes: Iterable[re.Pattern],
) -> List[str]

Extract valid payee candidates from a description.

Parameters:

Name Type Description Default
description str

Raw description text.

required
candidate_regexes Iterable[Pattern]

Compiled extraction regexes.

required

Returns:

Type Description
List[str]

List[str]: The normalized valid candidates.

is_valid_candidate

is_valid_candidate(candidate: str) -> bool

Return True when a candidate looks like a plausible payee.

Parameters:

Name Type Description Default
candidate str

Extracted candidate value.

required

Returns:

Name Type Description
bool bool

True when the candidate passes the length/content heuristics.

lookup_mapping

lookup_mapping(candidate: str, mapping: dict)

Look up mapping values for a candidate token.

Parameters:

Name Type Description Default
candidate str

Candidate token.

required
mapping dict

Mapping dict of key → MappingValue.

required

Returns:

Name Type Description
list

Matching value names, or (None, None) when the candidate is empty.

normalize_description

normalize_description(text: str) -> str

Normalize a description: separators → space, lowercase, drop OCR noise.

Parameters:

Name Type Description Default
text str

Raw description.

required

Returns:

Name Type Description
str str

The normalized lowercase description.

normalize_money_str

normalize_money_str(x) -> str

Format a numeric value as a fixed two-decimal string.

Parameters:

Name Type Description Default
x float

Value coercible to float.

required

Returns:

Name Type Description
str str

The value formatted to exactly two decimals.

normalize_person_handle

normalize_person_handle(handle: str) -> str

Normalize a person/UPI handle into a capitalized display name.

Parameters:

Name Type Description Default
handle str

Raw handle (may carry a UPI suffix or trailing digits).

required

Returns:

Name Type Description
str str

The cleaned handle, or "" when only hex characters remain.

remove_number_sequence

1
2
3
remove_number_sequence(
    text: str, amt: str, bal: str
) -> str

Strip amount/balance digit sequences from a description.

Parameters:

Name Type Description Default
text str

Description text.

required
amt str

Amount value.

required
bal str

Balance value.

required

Returns:

Name Type Description
str str

The cleaned, whitespace-collapsed description.