Skip to content

Raise Error Strategy

This module defines the RaiseErrorFallbackStrategy class, which is a concrete implementation of the LemmatizationFallbackStrategy protocol. It represents a fallback strategy that raises a ValueError when the lemma of a token cannot be determined.

Classes

RaiseErrorFallbackStrategy

Bases: LemmatizationFallbackStrategy

Raise Error Fallback Strategy. RaiseErrorFallbackStrategy is a concrete implementation of the LemmatizationFallbackStrategy protocol. It represents a fallback strategy that raises a ValueError when the lemma of a token cannot be determined.

Source code in simplemma/strategies/fallback/raise_error.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class RaiseErrorFallbackStrategy(LemmatizationFallbackStrategy):
    """
    Raise Error Fallback Strategy.
    RaiseErrorFallbackStrategy is a concrete implementation of the LemmatizationFallbackStrategy protocol. It represents
    a fallback strategy that raises a ValueError when the lemma of a token cannot be determined.
    """

    def get_lemma(self, token: str, lang: str) -> str:
        """
        Raise a ValueError indicating that the token was not found.

        This method is called when the lemma of a token cannot be determined using other lemmatization strategies.
        It raises a ValueError with an appropriate error message indicating that the token was not found.

        Args:
            token (str): The token for which the lemma could not be determined.
            lang (str): The language of the token.

        Raises:
            ValueError: The token was not found and its lemma cannot be determined.
        """
        raise ValueError(f"Token not found: {token}")

Functions

get_lemma(token, lang)

Raise a ValueError indicating that the token was not found.

This method is called when the lemma of a token cannot be determined using other lemmatization strategies. It raises a ValueError with an appropriate error message indicating that the token was not found.

Parameters:

Name Type Description Default
token str

The token for which the lemma could not be determined.

required
lang str

The language of the token.

required

Raises:

Type Description
ValueError

The token was not found and its lemma cannot be determined.

Source code in simplemma/strategies/fallback/raise_error.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def get_lemma(self, token: str, lang: str) -> str:
    """
    Raise a ValueError indicating that the token was not found.

    This method is called when the lemma of a token cannot be determined using other lemmatization strategies.
    It raises a ValueError with an appropriate error message indicating that the token was not found.

    Args:
        token (str): The token for which the lemma could not be determined.
        lang (str): The language of the token.

    Raises:
        ValueError: The token was not found and its lemma cannot be determined.
    """
    raise ValueError(f"Token not found: {token}")