src.fairreckitlib.data.filter.filter_factory

This module combines all three types of filters into a factory.

Functions: create_filter_factory: Creates a factory of three filter objects.

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 combines all three types of filters into a factory.
 2
 3Functions:
 4    create_filter_factory: Creates a factory of three filter objects.
 5
 6This program has been developed by students from the bachelor Computer Science at
 7Utrecht University within the Software Project course.
 8© Copyright Utrecht University (Department of Information and Computing Sciences)
 9"""
10
11from ...core.config.config_factories import GroupFactory
12from ..set.dataset import Dataset
13from ..set.dataset_registry import DataRegistry
14from ..data_modifier import DataModifierFactory, create_data_modifier_factory
15from .filter_params import (
16    create_params_categorical, create_params_numerical, create_params_count)
17from .filter_constants import KEY_DATA_SUBSET
18from .numerical_filter import create_numerical_filter
19from .categorical_filter import create_categorical_filter
20from .count_filter import create_count_filter
21from .filter_constants import FILTER_COUNT
22
23
24# NUMERICAL ['rating', 'timestamp']
25# CATEGORICAL, ['user_occupation','artist_genres','movie_genres']
26# COUNT ['user_country', 'artist_genres', 'movie_genres']
27
28def create_filter_factory(data_registry: DataRegistry) -> GroupFactory:
29    """Create the dataframe filter factory.
30
31    Args:
32
33        data_registry: the data registry with available datasets.
34
35    Returns:
36        the factory with all available filters.
37    """
38    def on_add_entries(matrix_factory: DataModifierFactory, dataset: Dataset) -> None:
39        """Add the filters to the matrix factory.
40
41        Args:
42            matrix_factory: the factory to add the filters to.
43            dataset: the dataset associated with the matrix factory.
44        """
45        matrix_name = matrix_factory.get_name()
46
47        for table_name, table_columns in dataset.get_available_columns(matrix_name).items():
48            table_age = table_name + '_age'
49            if table_age in table_columns:
50                matrix_factory.add_obj(
51                    table_age,
52                    create_numerical_filter,
53                    create_params_numerical
54                )
55
56            table_country = table_name + '_country'
57            if table_country in table_columns:
58                matrix_factory.add_obj(
59                    table_country,
60                    create_categorical_filter,
61                    create_params_categorical
62                )
63                matrix_factory.add_obj(
64                    table_country + '_' + FILTER_COUNT,
65                    create_count_filter,
66                    create_params_count
67                )
68
69            table_gender = table_name + '_gender'
70            if table_gender in table_columns:
71                matrix_factory.add_obj(
72                    table_gender,
73                    create_categorical_filter,
74                    create_params_categorical
75                    )
76
77    return create_data_modifier_factory(data_registry, KEY_DATA_SUBSET, on_add_entries)
def create_filter_factory( data_registry: src.fairreckitlib.data.set.dataset_registry.DataRegistry) -> src.fairreckitlib.core.config.config_factories.GroupFactory:
29def create_filter_factory(data_registry: DataRegistry) -> GroupFactory:
30    """Create the dataframe filter factory.
31
32    Args:
33
34        data_registry: the data registry with available datasets.
35
36    Returns:
37        the factory with all available filters.
38    """
39    def on_add_entries(matrix_factory: DataModifierFactory, dataset: Dataset) -> None:
40        """Add the filters to the matrix factory.
41
42        Args:
43            matrix_factory: the factory to add the filters to.
44            dataset: the dataset associated with the matrix factory.
45        """
46        matrix_name = matrix_factory.get_name()
47
48        for table_name, table_columns in dataset.get_available_columns(matrix_name).items():
49            table_age = table_name + '_age'
50            if table_age in table_columns:
51                matrix_factory.add_obj(
52                    table_age,
53                    create_numerical_filter,
54                    create_params_numerical
55                )
56
57            table_country = table_name + '_country'
58            if table_country in table_columns:
59                matrix_factory.add_obj(
60                    table_country,
61                    create_categorical_filter,
62                    create_params_categorical
63                )
64                matrix_factory.add_obj(
65                    table_country + '_' + FILTER_COUNT,
66                    create_count_filter,
67                    create_params_count
68                )
69
70            table_gender = table_name + '_gender'
71            if table_gender in table_columns:
72                matrix_factory.add_obj(
73                    table_gender,
74                    create_categorical_filter,
75                    create_params_categorical
76                    )
77
78    return create_data_modifier_factory(data_registry, KEY_DATA_SUBSET, on_add_entries)

Create the dataframe filter factory.

Args:

data_registry: the data registry with available datasets.

Returns: the factory with all available filters.