factories package#
Submodules#
factories.abstract_classifier_factory module#
- class academic_metrics.factories.abstract_classifier_factory.ClassifierFactory(taxonomy, ai_api_key)[source]#
Bases:
objectFactory for creating AbstractClassifier instances.
- logger#
Logger for the factory.
- Type:
- abstract_classifier_factory(
self, doi_abstract_dict: Dict[str, str], extra_context: dict | None = None, pre_classification_model: str | None = None, classification_model: str | None = None, theme_model: str | None = None,
- ) -> AbstractClassifier
Creates an AbstractClassifier instance.
- abstract_classifier_factory(doi_abstract_dict, extra_context=None, pre_classification_model='gpt-4o-mini', classification_model='gpt-4o-mini', theme_model='gpt-4o-mini')[source]#
Creates an AbstractClassifier instance.
- Parameters:
doi_abstract_dict (Dict[str, str]) – Dictionary of DOIs and abstracts.
extra_context (dict | None) – Extra context for the classifier.
pre_classification_model (str | None) – Pre-classification model for the classifier.
classification_model (str | None) – Classification model for the classifier.
theme_model (str | None) – Theme model for the classifier.
- Returns:
An AbstractClassifier instance.
- Return type:
classifier (AbstractClassifier)
factories.dataclass_factory module#
- class academic_metrics.factories.dataclass_factory.DataClassFactory[source]#
Bases:
objectFactory for creating and managing dataclass instances.
This class provides centralized creation, registration, and management of dataclasses used throughout the application. It maintains a registry of dataclass types and handles their instantiation with proper initialization.
- _registry#
Internal registry mapping dataclass types to their classes.
- Type:
Dict[str, Type[dataclass]]
- logger#
Logger instance for this class.
- Type:
- __init__()[source]#
Initialize the DataClassFactory with logging configuration.
Sets up both file and console handlers for logging factory operations.
- classmethod register_dataclass(dataclass_type)[source]#
Decorator to register a dataclass with the factory.
- Parameters:
dataclass_type (DataClassTypes) – The type of dataclass to register.
- classmethod get_dataclass(dataclass_type, **init_params)[source]#
Creates a new instance of the registered dataclass.
- Parameters:
dataclass_type (DataClassTypes) – The enum type of the dataclass to create
init_params (dict) – Parameters to initialize the dataclass
- Returns:
An instance of the requested dataclass
- Return type:
instance (Type[dataclass])
- Raises:
ValueError – If no dataclass is registered for the given type
- classmethod is_registered(dataclass_type)[source]#
Check if a dataclass type is registered.
- Parameters:
dataclass_type (DataClassTypes) – The enum type to check
- Returns:
True if the dataclass is registered, False otherwise
- Return type:
factories.strategy_factory module#
- class academic_metrics.factories.strategy_factory.StrategyFactory[source]#
Bases:
objectA factory class for managing and retrieving attribute extraction strategies.
This class provides a mechanism to register and retrieve different strategies for extracting attributes from data entries. It uses a dictionary to map attribute types to their corresponding strategy classes, allowing for flexible and dynamic strategy management.
- _strategies#
A class-level dictionary that maps attribute types to their corresponding strategy classes.
- Type:
- register_strategy(*attribute_types)[source]#
Registers a strategy class for one or more attribute types.
- get_strategy(attribute_type, warning_manager)[source]#
Retrieves the strategy class for a given attribute type and initializes it with a warning manager.
Usage: - Add a strategy to the factory: - StrategyFactory.register_strategy(AttributeTypes.TITLE)(TitleExtractionStrategy) - Add the enum to enums.py - get a strategy from the factory: - get_attributes() in utilities.py will then use this factory to get the strategy for a given attribute type.
- classmethod register_strategy(*attribute_types)[source]#
Registers a strategy class for one or more attribute types.
This method is used to associate a strategy class with specific attribute types. The strategy class is stored in the _strategies dictionary, allowing it to be retrieved later based on the attribute type.
- Parameters:
*attribute_types (AttributeTypes) – One or more attribute types to associate with the strategy class.
- Returns:
A decorator function that registers the strategy class.
- Return type:
function
- classmethod get_strategy(attribute_type, warning_manager)[source]#
Retrieves the strategy class for a given attribute type and initializes it with a warning manager.
This method looks up the strategy class associated with the specified attribute type in the _strategies dictionary. If a strategy class is found, it is instantiated with the provided warning manager and returned.
- Parameters:
attribute_type (AttributeTypes)
class. (- An instance of WarningManager to be passed to the strategy)
warning_manager (WarningManager)
class.
- Returns:
An instance of the strategy class associated with the specified attribute type.
- Return type:
strategy (AttributeExtractionStrategy)
- Raises:
- If no strategy is found for the specified attribute type. –