src.fairreckitlib.data.ratings.convert_config_parsing
This module contains a parser for the dataset rating conversion configuration.
Functions:
parse_data_convert_config: parse convert configuration.
This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course. © Copyright Utrecht University (Department of Information and Computing Sciences)
1"""This module contains a parser for the dataset rating conversion configuration. 2 3Functions: 4 5 parse_data_convert_config: parse convert configuration. 6 7This program has been developed by students from the bachelor Computer Science at 8Utrecht University within the Software Project course. 9© Copyright Utrecht University (Department of Information and Computing Sciences) 10""" 11 12from typing import Any, Dict, Optional 13 14from ...core.config.config_factories import GroupFactory 15from ...core.events.event_dispatcher import EventDispatcher 16from ...core.parsing.parse_config_object import parse_config_object 17from ..set.dataset import Dataset 18from .convert_config import ConvertConfig 19from .convert_constants import KEY_RATING_CONVERTER 20 21 22def parse_data_convert_config( 23 dataset_config: Dict[str, Any], 24 dataset: Dataset, 25 matrix_name: str, 26 converter_factory: GroupFactory, 27 event_dispatcher: EventDispatcher) -> Optional[ConvertConfig]: 28 """Parse a dataset rating converter configuration. 29 30 Args: 31 dataset_config: the dataset's total configuration. 32 dataset: the dataset related to the converter configuration. 33 matrix_name: the dataset's matrix name to use. 34 converter_factory: the converter factory containing available converters. 35 event_dispatcher: to dispatch the parse event on failure. 36 37 Returns: 38 the parsed configuration or None on failure. 39 """ 40 # dataset rating conversion is optional 41 if KEY_RATING_CONVERTER not in dataset_config: 42 return None 43 44 dataset_converter_factory = converter_factory.get_factory(dataset.get_name()) 45 matrix_converter_factory = dataset_converter_factory.get_factory(matrix_name) 46 47 converter, _ = parse_config_object( 48 'dataset ' + dataset.get_name() + ' \'' + matrix_name + '\' rating converter', 49 dataset_config[KEY_RATING_CONVERTER], 50 matrix_converter_factory, 51 event_dispatcher 52 ) 53 54 return ConvertConfig(converter.name, converter.params) if bool(converter) else None
def
parse_data_convert_config( dataset_config: Dict[str, Any], dataset: src.fairreckitlib.data.set.dataset.Dataset, matrix_name: str, converter_factory: src.fairreckitlib.core.config.config_factories.GroupFactory, event_dispatcher: src.fairreckitlib.core.events.event_dispatcher.EventDispatcher) -> Optional[src.fairreckitlib.data.ratings.convert_config.ConvertConfig]:
23def parse_data_convert_config( 24 dataset_config: Dict[str, Any], 25 dataset: Dataset, 26 matrix_name: str, 27 converter_factory: GroupFactory, 28 event_dispatcher: EventDispatcher) -> Optional[ConvertConfig]: 29 """Parse a dataset rating converter configuration. 30 31 Args: 32 dataset_config: the dataset's total configuration. 33 dataset: the dataset related to the converter configuration. 34 matrix_name: the dataset's matrix name to use. 35 converter_factory: the converter factory containing available converters. 36 event_dispatcher: to dispatch the parse event on failure. 37 38 Returns: 39 the parsed configuration or None on failure. 40 """ 41 # dataset rating conversion is optional 42 if KEY_RATING_CONVERTER not in dataset_config: 43 return None 44 45 dataset_converter_factory = converter_factory.get_factory(dataset.get_name()) 46 matrix_converter_factory = dataset_converter_factory.get_factory(matrix_name) 47 48 converter, _ = parse_config_object( 49 'dataset ' + dataset.get_name() + ' \'' + matrix_name + '\' rating converter', 50 dataset_config[KEY_RATING_CONVERTER], 51 matrix_converter_factory, 52 event_dispatcher 53 ) 54 55 return ConvertConfig(converter.name, converter.params) if bool(converter) else None
Parse a dataset rating converter configuration.
Args: dataset_config: the dataset's total configuration. dataset: the dataset related to the converter configuration. matrix_name: the dataset's matrix name to use. converter_factory: the converter factory containing available converters. event_dispatcher: to dispatch the parse event on failure.
Returns: the parsed configuration or None on failure.