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. |
|
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: cosapp.base.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_split(expression: str, separators: List[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 [List[str]]:
List 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'], ['+', '-', '-', '+']