cosapp.utils.parsing¶
Functions
|
Decompose a string expression into basename and selector, where selector is a suitable mask expression for an array. |
|
Decompose a variable specification into its base name and mask. |
|
Reciprocal of multi_split. |
|
Extension of str.split, accounting for more than one split separators. |
Classes
|
- class cosapp.utils.parsing.MaskedVarInfo(basename, selector, mask)[source]¶
Bases:
NamedTuple- basename: str¶
Alias for field number 0
- property fullname: bool¶
- mask: ndarray | None¶
Alias for field number 2
- selector: str¶
Alias for field number 1
- cosapp.utils.parsing.find_selector(expression: str) Tuple[str, str][source]¶
Decompose a string expression into basename and selector, where selector is a suitable mask expression for an array.
Parameters:¶
expression [str]: the expression to be parsed.
Returns:¶
baseline, selector [str, str]
- cosapp.utils.parsing.get_indices(system: System, name: str) MaskedVarInfo[source]¶
Decompose a variable specification into its base name and mask.
- Parameters:
system (System) – System to which variable belongs
name (str) – Variable specification (variable name + optional array mask, if required)
- Returns:
basename [str]: variable name
selector [str]: array selector
mask [numpy.ndarray[bool]]: mask (if array) or None
- Return type:
MaskedVarInfo (named tuple)
- cosapp.utils.parsing.multi_join(expressions: List[str], separators: List[str], add_space=False) str[source]¶
Reciprocal of multi_split.
Parameters:¶
- expressions [list[str]]:
Expression to be split.
- separators [list[str]]:
List of separators.
Returns:¶
- expression [str]:
Joined expression.
Examples:¶
>>> multi_join(['a', 'b', 'c', 'd', 'e'], ['+', '-', '-', '+']) 'a+b-c-d+e' >>> multi_join(['a', 'b', 'c', 'd', 'e'], ['+', '-', '-', '+'], add_space=True) 'a + b - c - d + e'
- cosapp.utils.parsing.multi_split(expression: str, separators: Collection[str]) Tuple[List[str], List[str]][source]¶
Extension of str.split, accounting for more than one split separators.
Parameters:¶
- expression [str]:
Expression to be split.
- separators [collection[str]]:
List/tuple/set of separators.
Returns:¶
- expressions [list[str]]:
List of n split expressions.
- separators [list[str]]:
Sequence of (n - 1) separators between split expressions.
Examples:¶
>>> multi_split('a+b-c-d+e', list('+-')) ['a', 'b', 'c', 'd', 'e'], ['+', '-', '-', '+']