Skip to content

SAIM - Strain Authentication and Identification Methods#

parse #

string #

clean_string(text, /, *pattern_args) #

Removes all occurrences of one or multiple regex patterns from a string.

Parameters:

Name Type Description Default
text str

The input string to clean.

required
*pattern_args Pattern[str]

One or more compiled regex patterns to remove from the string.

()

Returns:

Name Type Description
str str

The cleaned string with all occurrences of the given patterns replaced by an empty string.

Source code in src/saim/shared/parse/string.py
def clean_string(text: str, /, *pattern_args: Pattern[str]) -> str:
    """Removes all occurrences of one or multiple regex patterns from a string.

    Args:
        text (str): The input string to clean.
        *pattern_args (Pattern[str]): One or more compiled regex patterns
            to remove from the string.

    Returns:
        str: The cleaned string with all occurrences of the given patterns
            replaced by an empty string.
    """
    clean_string = text
    for pattern in pattern_args:
        clean_string = pattern.sub("", clean_string)
    return clean_string

search #

radix_tree #

RadixTree #

Creates a radix tree by splitting a string into nodes forming a prefix hierarchy.

Each node contains a mapping (con) of characters to child RadixTree nodes, representing the next character in the string. The splitting continues until the end of the string, indicated by end == True. For example, the string 'ABC#$' is stored as:

RadixTree('ABC#$') -> con = { 'A': RadixTree('BC#$') }
RadixTree('BC#$')  -> con = { 'B': RadixTree('C#$') }
RadixTree('C#$')   -> con = { 'C': RadixTree('#$') }
RadixTree('#$')    -> con = { ':': RadixTree('$') }
RadixTree('$')     -> con = { ':': RadixTree() }, end == True

Attributes:

Name Type Description
con tuple[_RQP[T], ...]

Child nodes keyed by character.

end bool

True if this node represents the end of a word.

index tuple[T, ...]

Associated index or data for this node.

max int

The maximum length of a substring key among this node's immediate children..

ready bool

Flag indicating if the node is ready (compact implementation of a prefix tree).

Parameters:

Name Type Description Default
init str

The initial string to build the radix tree node from.

required
index tuple[T, ...]

Tuple of associated data or index values.

required
Source code in src/saim/shared/search/radix_tree.py
@final
class RadixTree[T]:
    """Creates a radix tree by splitting a string into nodes forming a prefix hierarchy.

    Each node contains a mapping (`con`) of characters to child RadixTree nodes,
    representing the next character in the string. The splitting continues
    until the end of the string, indicated by `end == True`.
    For example, the string 'ABC#$' is stored as:
        ```
        RadixTree('ABC#$') -> con = { 'A': RadixTree('BC#$') }
        RadixTree('BC#$')  -> con = { 'B': RadixTree('C#$') }
        RadixTree('C#$')   -> con = { 'C': RadixTree('#$') }
        RadixTree('#$')    -> con = { ':': RadixTree('$') }
        RadixTree('$')     -> con = { ':': RadixTree() }, end == True
        ```

    Attributes:
        con (tuple[_RQP[T], ...]): Child nodes keyed by character.
        end (bool): True if this node represents the end of a word.
        index (tuple[T, ...]): Associated index or data for this node.
        max (int): The maximum length of a substring key among this
            node's immediate children..
        ready (bool): Flag indicating if the node is ready
            (compact implementation of a prefix tree).

    Args:
        init (str): The initial string to build the radix tree node from.
        index (tuple[T, ...]): Tuple of associated data or index values.
    """

    __slots__ = ("con", "end", "index", "max", "ready")

    def __init__(self, init: str, index: tuple[T, ...], /) -> None:
        mer_init = _merge_lead_string_sep(init)
        self.end: bool = len(mer_init) == 0
        self.index: tuple[T, ...] = tuple()
        if index is not None and self.end:
            self.index = index
        self.ready: bool = False
        self.con: tuple[_RQP[T], ...] = tuple()
        self.max = 1
        if mer_init:
            self.con = ((mer_init[0].upper(), RadixTree[T](mer_init[1:], index)),)
        super().__init__()

private #

cached_session #