brain_pipe.parser.yaml.YAMLTemplateFileParser

class YAMLTemplateFileParser

Bases: YAMLMixin, TemplateFileParser

YAML parser that can parse YAML template files.

Attributes

ARGS_STR

CALLABLE_STR

CONFIG_STR

DATALOADERS_STR

DATA_FROM_STR

DEFAULT_ENVIRONMENT_KWARGS

EXTRA_PATHS_STR

FILEDIR_STR

FILE_STR

NAME_STR

PARSER_STR

PIPELINES_STR

POINTER_STR

READ_MODE

RUNNER_CLASS_STR

RUNNER_STR

__init__()

Create a new TemplateTextParser.

Methods

__init__()

Create a new TemplateTextParser.

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.

load_file(path)

Load a file into a text that can be parsed.

parse_all(all_info)

Parse all information in the text dictionary.

parse_text_to_dict(text)

Parse YAML text to a dictionary.

recursive_parse(text_dict)

Parse the configuration.

set_additional_kwargs(kwargs)

Set additional arguments for the parser.

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 (str) – The input string that should be parsed when the parser is called.

  • 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]]

load_file(path: str) str

Load a file into a text that can be parsed.

Parameters:

path (str) – The path to the file to load.

Returns:

The text that was loaded from the file.

Return type:

str

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]]]

parse_text_to_dict(text)

Parse YAML text to a dictionary.

Parameters:

text (str) – The YAML text to parse.

Returns:

The parsed dictionary.

Return type:

Dict[str, Any]

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(kwargs: Dict[str, Any])

Set additional arguments for the parser.

Parameters:

kwargs (Dict[str, Any]) – A dictionary containing the names of the arguments as keys and the options (kwargs) for a (CLI) argument parser as values.