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:
ABCAbstract 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: dict[str, ~typing.Any] | None=None, dataset_name: str | None = None, errors: list[str] = <factory>, warnings: list[str] = <factory>, source_type: str | None = None)[source]
Bases:
objectResult of parsing a configuration.
- Variables:
success (bool) – Whether parsing was successful.
config (dict[str, Any] | None) – The parsed configuration dictionary.
dataset_name (str | None) – The extracted or inferred dataset name.
errors (list[str]) – List of error messages if parsing failed.
warnings (list[str]) – List of warning messages (non-fatal issues).
source_type (str | None) – Type of source that was parsed (‘dict’, ‘file’, ‘folder’, ‘array’).