Rules Strategy
This module defines the RulesStrategy
class, which is a concrete implementation of the LemmatizationStrategy
protocol.
It provides lemmatization by applying pre-defined rules for each language.
Classes
RulesStrategy
Bases: LemmatizationStrategy
This class represents a lemmatization strategy that performs lemmatization by applying pre-defined rules for each language.
It implements the LemmatizationStrategy
protocol.
Source code in simplemma/strategies/rules.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
Functions
__init__(rules=DEFAULT_RULES)
Initialize the Rules Strategy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rules |
Dict[str, Callable[[str], Optional[str]]]
|
A dictionary of pre-defined rules for various languages.
Defaults to |
DEFAULT_RULES
|
Source code in simplemma/strategies/rules.py
20 21 22 23 24 25 26 27 28 29 30 31 |
|
get_lemma(token, lang)
Get Lemma using Rules Strategy
This method performs lemmatization by applying pre-defined rules for each language. It checks if the language has pre-defined rules defined. If rules are defined, it applies the corresponding rule on the token to get the lemma. If a lemma is found, it is returned. If no rules are defined for the language or no lemma is found, None is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
The input token to lemmatize. |
required |
lang |
str
|
The language code for the token's language. |
required |
Returns:
Type | Description |
---|---|
Optional[str]
|
Optional[str]: The lemma for the token, or None if no lemma is found. |
Source code in simplemma/strategies/rules.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|