freeports_analysis.formats.utils
Utilities of general interest common to all formats and that can be used for creating pdf_filter or text_extract or deserialize functions
Functions
|
Decorator to provide a default implementation when primary function fails. |
|
Normalize a string by: 1. |
|
Normalize a word by: 1. |
|
Decorator to override default implementation with primary implementation. |
- freeports_analysis.formats.utils.default_if_not_implemented(default_func: Callable[[P], R]) Callable[[P], R]
Decorator to provide a default implementation when primary function fails.
Replace the decorated function with a default given as argument of the decorator if the decorated function raises NotImplementedError or returns None.
- Parameters:
default_func (Callable[P,R]) – Default function to use when primary function is not implemented
- Returns:
Wrapped function that falls back to default implementation when needed
- Return type:
Callable[P,R]
Notes
This decorator is useful for creating extensible function hierarchies where subclasses can override specific functionality while falling back to default implementations when not overridden.
- freeports_analysis.formats.utils.normalize_string(string: str, lower: bool = True) str
Normalize a string by: 1. Stripping leading/trailing whitespace 2. Converting to lowercase if lower 3. Collapsing multiple whitespaces into single spaces
- Parameters:
string (str) – Input string to normalize
lower (bool) – Determine if the string has to be lowered
- Returns:
Normalized string
- Return type:
str
- freeports_analysis.formats.utils.normalize_word(word: str, lower: bool = False) str
Normalize a word by: 1. Stripping leading/trailing whitespace 2. Removing all whitespace between characters 3. Converting to lowercase if lower
- Parameters:
word (str) – Input word to normalize
lower (bool) – Determine if the string has to be lowered
- Returns:
Normalized word with no whitespace
- Return type:
str
- freeports_analysis.formats.utils.overwrite_if_implemented(primary_func: Callable[[P], R]) Callable[[P], R]
Decorator to override default implementation with primary implementation.
Replace the decorated default function with a function given as argument of the decorator if that function does not raise a NotImplementedError or return None.
- Parameters:
primary_func (Callable[P,R]) – Primary implementation of a function that should override the default
- Returns:
Wrapped function that uses primary implementation when available, otherwise falls back to default implementation
- Return type:
Callable[P,R]
Notes
This is the inverse of default_if_not_implemented and is useful when you want to provide a primary implementation that should override a default implementation when available.
Modules
Utils for creating deserialize routines and functions |
|
Utilities for writing pdf_filter functions. |
|
Module for text block processing and extraction in document analysis. |