brain_pipe.parser.simple_dict.SimpleDictParser

class SimpleDictParser

Bases: Parser, ObjectsWithConfig

Parser that can parse dictionaries contain only text.

Attributes

ARGS_STR

CALLABLE_STR

CONFIG_STR

DATALOADERS_STR

DATA_FROM_STR

EXTRA_PATHS_STR

NAME_STR

PARSER_STR

PIPELINES_STR

POINTER_STR

RUNNER_CLASS_STR

RUNNER_STR

__init__()

Initialize the parser.

Methods

__init__()

Initialize the parser.

apply_config(config)

Apply the configuration to the parser.

get_additional_kwargs(input_, info)

Find the additional arguments that should be passed to the parser.

get_runner_from_parsed_config(parsed_config)

Construct a runner from the configuration.

link_loader_to_pipeline(pipelines, loaders)

Pair pipelines with their corresponding dataloaders.

parse_all(all_info)

Parse all information in the text dictionary.

recursive_parse(text_dict)

Parse the configuration.

set_additional_kwargs(args)

Set the additional arguments defined in get_additional_kwargs().

apply_config(config: Dict[str, Any])

Apply the configuration to the parser.

Parameters:

config (Dict[str, Any]) – The configuration to apply.

get_additional_kwargs(input_: Any, info: Dict[str, Any]) Dict[str, Any]

Find the additional arguments that should be passed to the parser.

This function identifies additional arguments that should be passed to the parser by e.g. a CLI.

Parameters:
  • input (Dict[str, Any]) – The input for the parser.

  • info (Dict[str, Any]) – A dictionary containing available info, such as e.g. parsed CLI arguments. This information can be used to determine the additional arguments.

Returns:

A dictionary containing the names of the arguments as keys and the options (kwargs) for a (CLI) argument parser as values.

Return type:

Dict[str, Any]

get_runner_from_parsed_config(parsed_config: Dict[str, Any])

Construct a runner from the configuration.

Parameters:

parsed_config (Dict[str, Any]) – The already parsed configuration.

Return type:

Runner

Pair pipelines with their corresponding dataloaders.

Parameters:
  • pipelines (Sequence[Tuple[str, Pipeline]]) – A dictionary containing a mapping between the name of a loader and the Pipeline object

  • loaders (Dict[str, DataLoader]) – A dictionary containing a mapping between the name of a loader and the DataLoader object

Returns:

A list of tuples containing a DataLoader and its corresponding Pipeline.

Return type:

List[Tuple[DataLoader, Pipeline]]

parse_all(all_info: Dict[str, Any])

Parse all information in the text dictionary.

Parameters:

all_info (Dict[str, Any]) – The text dictionary to parse.

Returns:

A runner and a list of tuples containing a Pipeline and its DataLoader.

Return type:

Tuple[Runner, List[Tuple[Pipeline, DataLoader]]]

recursive_parse(text_dict: Dict[str, Any])

Parse the configuration.

Parameters:

text_dict (Dict[str, Any]) – The text dictionary to parse.

Returns:

The parsed dictionary (i.e. with objects).

Return type:

Union[Dict[str, Any], Tuple[str, Dict[str, Any]]]

set_additional_kwargs(args: Dict[str, Any])

Set the additional arguments defined in get_additional_kwargs().

Parameters:

args (Dict[str, Any]) – The additional arguments.

Notes

This method calls apply_config() internally, so the additional arguments can also be specified in the dictionary itself under the parser configuration.