Module utilities.v_str

String implementation used to associate source context and confidence with information extracted from the PDF

Classes

class vStr (_str, context: str = '', confidence: float = 0.0, force_type: bool | None = None, og_value: str | None = None, verified: bool | None = None)

Built-in string extended with attributes used in data validation.

Atrributes

ctx [str]: point of origin data for the value (context arg) con [float]: confidence that the value is correct (confidence arg) frc [bool]: force all descendents to class vStr (force_type arg) ogv [str]: originalValue in data_entry_fields (og_value arg) tru [bool]: isVerified in data_entry_fields (verified arg)

Ancestors

  • builtins.str

Static methods

def cat(*args) ‑> vStr

equivalent to vStr.jn("", (args)). emulates ''.join(args)

def from_data_entry_dict(de_dict: dict[str, Any], verify_all: bool = False) ‑> vStr

Return a vStr constructed from a data_entry_fields object from the claimmaker DB and/or a validated claimmaker job dict

def from_nested(val: Any, is_verified: bool = False) ‑> str | vStr

Used when manually created cases contain data in nested columns with no corresponding entry in the data_entry_fields column.

returns a 1.0 confidence vStr with context 'DB.User' for 'non-null' vals i.e. when val != type(val)()

def jn(sep: str, iterable: Iterable[str | vStr]) ‑> vStr

emulates str.join()

def merge_attrs(iterable: Iterable[str | vStr]) ‑> tuple[str, float, bool, str | None, bool]

merge vStr attrs from multiple instances. returns pipe delimited string for ctx and mean for con or empty string / 0.0 if no vStr is present in input

Instance variables

var con
var ctx
prop data_entry_dict

return a data_entry_fields dict representing this vStr

var frc
prop is_verified : bool

True if value has been validated by a user.

var ogv
var tru

Methods

def extend_context(self, suffix: str) ‑> str

Append suffix to current ctx value

def format(self, *args, **kwargs) ‑> vStr

If any of the supplied args or kwargs is of type vStr, return the str.format result as a vStr having attributes merged from all vStr inputs. If none of the inputs are

def mutation_decorator(self, mutation_func: Callable[..., str])

Decorates underlying str mutation functions (e.g. upper, lower, strip, split, etc.) to restore ctx and con attributes post mutation

def prepend_context(self, prefix: str) ‑> str

Prepend prefix to current ctx value

def replace_context(self, new_context: str) ‑> str

Prepend prefix to current ctx value

def set_custom_attrs(self, context: str, confidence: float, force_type: bool, og_value: str, verified: bool)

set custom attributes ("ctx", "con", "frc", "ogv", "tru")