bidsbuilder.schema.interpreter.selectors¶
- class SelectorParser¶
Bases:
objectSelector Parser is a recursive descent parser to interpret BIDS schema logic into executable python functions
It includes a from_raw() method enabling tokenisation and parsing from the raw string expression
- ADD_OPS = {'+': <built-in function add>, '-': <built-in function sub>}¶
- EQ_OPS = {'!=': <built-in function ne>, '<': <built-in function lt>, '<=': <built-in function le>, '==': <built-in function eq>, '>': <built-in function gt>, '>=': <built-in function ge>, 'in': <function contains>}¶
- EVAL_FUNCS = {'allequal': <function allequal>, 'count': <function count>, 'exists': <function exists>, 'index': <function index>, 'intersects': <function intersects>, 'length': <function length>, 'match': <function nMatch>, 'max': <function max>, 'min': <function min>, 'sorted': <function nSorted>, 'substr': <function substr>, 'type': <function nType>}¶
- FIELDS_MAP = {'associations': <function associations>, 'columns': <function columns>, 'dataset': <function dataset>, 'datatype': <function datatype>, 'entities': <function entities>, 'extension': <function extension>, 'gzip': <function gzip>, 'json': <function json>, 'modality': <function modality>, 'nifti_header': <function nifti_header>, 'ome': <function ome>, 'path': <function path>, 'schema': <function schema>, 'sidecar': <function sidecar>, 'subject': <function subject>, 'suffix': <function suffix>, 'tiff': <function tiff>}¶
- LOGIC_OPS = {'&&': <function op_and>, '||': <function op_or>}¶
- MULT_OPS = {'*': <built-in function mul>, '/': <built-in function truediv>}¶
- POSTFIX_OPS = {'.': <function get_property>, '[': <function get_list_index>}¶
- UNARY_OPS = {'!': <built-in function not_>, '+': <built-in function pos>, '-': <built-in function neg>}¶
- __init__(tokens)¶
- Parameters:
tokens (list)
- additive_term()¶
- advance()¶
- boolean()¶
- brackets()¶
- equality_term()¶
- classmethod from_raw(selector)¶
used to instantiate a selectorParser from a raw string, so tokenises the input before returning an instance with the correct tokens
- Return type:
- Parameters:
selector (str | None)
- identifier()¶
identifier is a bit special as it adds “tags”
identifier holds the predefined bids vocabulary of interpreted functions and fields
Each field and the function “exists()” is considered a tag (these are attributes belonging to a file which can be hooked and allow to re-check the schema if these attributes change)
- logic_term()¶
- match(*types)¶
- Return type:
Any
- mult_term()¶
- nanToken = token(val=None, kind='NONE')¶
- number()¶
- p_float()¶
- parentheses()¶
- parse()¶
- Return type:
- postfix_term()¶
- primary()¶
lowest level priority. These are all considered terminal and just return the interpreted value
- string()¶
- tok_regex = '(?P<FLOAT>\\d+\\.\\d+|\\.\\d+)|(?P<NUMBER>\\d+)|(?P<STRING>"[^"]*"|\\\'[^\\\']*\\\')|(?P<EQ_OP>==|!=|<=|>=|\\bin\\b|[<>])|(?P<ADD_OP>[+\\-])|(?P<MULT_OP>[*/])|(?P<LOGIC_OP>&&|\\|\\|)|(?P<BOOL>false|true)|(?P<ID>[A-Za-z_]\\w*)|(?P<LPAREN>\\()|(?P<RPAREN>\\))|(?P<LBRACK>\\[)|(?P<RBRACK>\\])|(?P<SEP>[, \\t]+)|(?P<UNARY>!)|(?P<DOT>\\.)|(?P<MISMATCH>.)'¶
- token_specification = [('FLOAT', '\\d+\\.\\d+|\\.\\d+'), ('NUMBER', '\\d+'), ('STRING', '"[^"]*"|\\\'[^\\\']*\\\''), ('EQ_OP', '==|!=|<=|>=|\\bin\\b|[<>]'), ('ADD_OP', '[+\\-]'), ('MULT_OP', '[*/]'), ('LOGIC_OP', '&&|\\|\\|'), ('BOOL', 'false|true'), ('ID', '[A-Za-z_]\\w*'), ('LPAREN', '\\('), ('RPAREN', '\\)'), ('LBRACK', '\\['), ('RBRACK', '\\]'), ('SEP', '[, \\t]+'), ('UNARY', '!'), ('DOT', '\\.'), ('MISMATCH', '.')]¶
- tokenizer(string, pos=0, endpos=9223372036854775807)¶
Matches zero or more characters at the beginning of the string.
- unary_term()¶
- class selectorFunc¶
Bases:
object- __init__(val, args=NOTHING, requires_input=False, is_callable=False)¶
Method generated by attrs for class selectorFunc.
- Parameters:
val (Any)
args (list[Any])
requires_input (bool)
is_callable (bool)
- Return type:
None
-
args:
list[Any]¶
- evaluate_static_nodes()¶
- Return type:
bool
-
is_callable:
bool¶
-
requires_input:
bool¶
-
tags:
Optional[set]¶
-
val:
Any¶
- class selectorHook¶
Bases:
object- __init__(funcs, original, tags=NOTHING)¶
Method generated by attrs for class selectorHook.
- Parameters:
funcs (list[Callable])
original (list[str])
tags (set[str])
- Return type:
None
- classmethod from_raw(r_selector)¶
- Return type:
- Parameters:
r_selector (list[str])
-
funcs:
list[Callable]¶
-
original:
list[str]¶
-
tags:
set[str]¶