예제 #1
0
    def __init__(
        self,
        input_handler: InputHandler,
        output_handlers: Sequence[OutputHandler] = ()
    ) -> None:
        """
        The constructor of the InputOutputHandler class.

        Parameters
        ----------
        input_handler : input_output_handler.input_handler.InputHandler
            The input handler.
        output_handlers : Sequence[input_output_handler.output_handler.OutputHandler]
            The sequence of output handlers.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           input_handler=input_handler.__class__.__name__,
                           output_handlers=[
                               output_handler.__class__.__name__
                               for output_handler in output_handlers
                           ])
        self._input_handler = input_handler
        # Event Handlers may refer to the alias (if there is one) of the .ini file which is included in the
        # __class__.__name__ property in the factory. get_alias() extracts this alias
        self._output_handlers_dictionary = {
            to_snake_case(get_alias(output_handler.__class__.__name__)):
            output_handler
            for output_handler in output_handlers
        }
예제 #2
0
    def __init__(self,
                 charge_values: Sequence[float],
                 charge_name: str = None) -> None:
        """
        The constructor of the ChargeValues class.

        If the charge name is None, the name of the class is used. If the JF factory included an alias in the classname,
        the alias is used.

        Parameters
        ----------
        charge_values : Sequence[float]
            The sequence of charges for each leaf node particle within a single tree.
        charge_name : str or None, optional
            The name of the charge.
        """
        log_init_arguments(logging.getLogger(__name__).debug,
                           self.__class__.__name__,
                           charge_values=charge_values,
                           charge_name=charge_name)
        # If no charge name is given, we want to use the alias of the .ini file which is included in the
        # __class__.__name__ property in the factory. get_alias() extracts this alias
        self._charge_name = (charge_name if charge_name is not None else
                             to_snake_case(get_alias(self.__class__.__name__)))
        self._charge_values = charge_values
예제 #3
0
    def initialize(self, extracted_global_state: Sequence[Node],
                   internal_states: Sequence[InternalState]) -> None:
        """
        Initialize the taggers based on the full extracted global state and all initialized internal states.

        Extends the initialize method of the Tagger class. Use this method once in the beginning of the run to
        initialize the tagger. Only after a call of this method, other public methods of this class can be called
        without raising an error.
        This method extracts the internal state corresponding to the internal state label out of the sequence of
        internal states. If a tagger also need to initialize their event handlers, it should further extend this method.
        The full extracted global state is given as a sequence of cnodes of all root nodes stored in the global state.

        Parameters
        ----------
        extracted_global_state : Sequence[base.node.Node]
            The full extracted global state from the state handler.
        internal_states : Sequence[activator.internal_state.InternalState]
            Sequence of all initialized internal states in the activator.
        """
        super().initialize(extracted_global_state, internal_states)
        relevant_internal_state = [
            state for state in internal_states
            if to_snake_case(get_alias(state.__class__.__name__)) ==
            self._internal_state_label
        ]
        if len(relevant_internal_state) == 0:
            raise ConfigurationError(
                "The given internal state label '{0}' does not exist!".format(
                    self._internal_state_label))
        if len(relevant_internal_state) > 1:
            raise ConfigurationError(
                "The given internal state label '{0}' exists more than once!".
                format(self._internal_state_label))
        self._internal_state = relevant_internal_state[0]
예제 #4
0
    def __init__(
        self,
        create: Sequence[str],
        trash: Sequence[str],
        event_handler: EventHandler,
        number_event_handlers: int,
        tag: str = None,
        activate: Sequence[str] = (),
        deactivate: Sequence[str] = ()
    ) -> None:
        """
        The constructor of the abstract tagger class.

        Parameters
        ----------
        create : Sequence[str]
            Sequence of tags to create after an event handler of this tagger has committed an event to the global state.
        trash : Sequence[str]
            Sequence of tags to trash after an event handler of this tagger has committed an event to the global state.
        event_handler : event_handler.EventHandler
            A single event handler instance.
        number_event_handlers : int
            Number of event handlers to prepare. The tagger will deepcopy the given event handler instance to create
            this number of event handlers.
        tag : str or None, optional
            Tag used in all four lists (also of other taggers). If None, the class name (or the alias set in the
            factory) will be used as the tag.
        activate : Sequence[str], optional
            Sequence of tags to activate after an event handler of this tagger has committed an event to the global
            state.
        deactivate : Sequence[str], optional
            Sequence of tags to deactivate after an event handler of this tagger has committed an event to the global
            state.
        """
        self._activates = activate
        self._deactivates = deactivate
        # Do this before calling super().__init__(), because Initializer class will overwrite public methods
        self._deactivated_yield_identifiers_send_event_time = lambda separated_active_units: iter(
            ())
        self._activated_yield_identifiers_send_event_time = self.yield_identifiers_send_event_time
        super().__init__()
        # If no tag is given, we want to use the alias of the .ini file which is included in the __class__.__name__
        # property in the factory. get_alias() extracts this alias
        self._tag = tag if tag is not None else to_snake_case(
            get_alias(self.__class__.__name__))
        self._creates = create
        self._trashes = trash
        self._event_handlers = [event_handler] + [
            deepcopy(event_handler) for _ in range(1, number_event_handlers)
        ]
예제 #5
0
 def test_get_alias_empty_string_raises_error(self):
     with self.assertRaises(ConfigurationError):
         factory.get_alias("")
예제 #6
0
 def test_get_alias_empty_class_raises_error(self):
     with self.assertRaises(ConfigurationError):
         factory.get_alias("Test ()")
예제 #7
0
 def test_get_alias_missing_brackets_raises_error(self):
     with self.assertRaises(ConfigurationError):
         factory.get_alias("Test SomeClass")
예제 #8
0
 def test_get_alias_too_many_whitespaces_raises_error(self):
     with self.assertRaises(ConfigurationError):
         factory.get_alias("Test  (SomeClass)")
예제 #9
0
 def test_get_alias_alias_not_set(self):
     self.assertEqual(factory.get_alias("SomeClass"), "SomeClass")
예제 #10
0
 def test_get_alias_alias_set(self):
     self.assertEqual(factory.get_alias("Test (SomeClass)"), "Test")