nirs4all.data.parsers.base module

Base parser interface for dataset configuration.

This module defines the abstract base class for configuration parsers. All parsers should inherit from BaseParser and implement the required methods.

class nirs4all.data.parsers.base.BaseParser[source]

Bases: ABC

Abstract base class for configuration parsers.

Subclasses must implement: - can_parse(): Check if this parser can handle the input - parse(): Parse the input and return a ParserResult

abstractmethod can_parse(input_data: Any) bool[source]

Check if this parser can handle the given input.

Parameters:

input_data – The input to check.

Returns:

True if this parser can handle the input, False otherwise.

abstractmethod parse(input_data: Any) ParserResult[source]

Parse the input and return a configuration.

Parameters:

input_data – The input to parse.

Returns:

ParserResult with parsed configuration or errors.

class nirs4all.data.parsers.base.ParserResult(success: bool, config: ~typing.Dict[str, ~typing.Any] | None = None, dataset_name: str | None = None, errors: ~typing.List[str] = <factory>, warnings: ~typing.List[str] = <factory>, source_type: str | None = None)[source]

Bases: object

Result of parsing a configuration.

success

Whether parsing was successful.

Type:

bool

config

The parsed configuration dictionary.

Type:

Dict[str, Any] | None

dataset_name

The extracted or inferred dataset name.

Type:

str | None

errors

List of error messages if parsing failed.

Type:

List[str]

warnings

List of warning messages (non-fatal issues).

Type:

List[str]

source_type

Type of source that was parsed (‘dict’, ‘file’, ‘folder’, ‘array’).

Type:

str | None

config: Dict[str, Any] | None = None
dataset_name: str | None = None
errors: List[str]
source_type: str | None = None
success: bool
warnings: List[str]