Lemmatizer
Lemmatizer module. Provides classes for lemmatizing token and full texts.
- Lemmatizer: Class for performing token and full text lemmatization.
- is_known(): A legacy function that wraps the Lemmatizer's [is_known()][simplemma.lemmatizer.Lemmatizer.is_known] method.
- lemmatize(): A legacy function that wraps the Lemmatizer's lemmatize() method.
- text_lemmatizer(): A legacy function that wraps the Lemmatizer's text_lemmatizer() method.
- lemma_iterator(): A legacy function that wraps the Lemmatizer's lemma_iterator() method.
Classes
Lemmatizer
Lemmatizer class for performing token lemmatization.
Source code in simplemma/lemmatizer.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
Functions
__init__(cache_max_size=1048576, tokenizer=RegexTokenizer(), lemmatization_strategy=DefaultStrategy(), fallback_lemmatization_strategy=ToLowercaseFallbackStrategy())
Initialize the Lemmatizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_max_size |
int
|
The maximum size of the cache for the lemmatization results.
Defaults to |
1048576
|
tokenizer |
Tokenizer
|
The tokenizer to use for tokenization.
Defaults to |
RegexTokenizer()
|
lemmatization_strategy |
LemmatizationStrategy
|
The lemmatization strategy to use.
Defaults to |
DefaultStrategy()
|
fallback_lemmatization_strategy |
LemmatizationFallbackStrategy
|
The fallback lemmatization strategy to use.
Defaults to |
ToLowercaseFallbackStrategy()
|
Source code in simplemma/lemmatizer.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
get_lemmas_in_text(text, lang)
Get an iterator over lemmatized tokens in a text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The text to process. |
required |
lang |
Union[str, Tuple[str, ...]]
|
The language or languages for lemmatization. |
required |
Yields:
Name | Type | Description |
---|---|---|
str |
str
|
The lemmatized tokens in the text. |
Source code in simplemma/lemmatizer.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
lemmatize(token, lang)
Get the lemmatized form of a given word in the specified language(s).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
The token to lemmatize. |
required |
lang |
Union[str, Tuple[str, ...]]
|
The language or languages for lemmatization. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The lemmatized form of the token. |
Source code in simplemma/lemmatizer.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
Functions
is_known(token, lang)
Check if a token is known in the specified language(s).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
The token to check. |
required |
lang |
Union[str, Tuple[str, ...]]
|
The language or languages to check in. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the token is known, False otherwise. |
Source code in simplemma/lemmatizer.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
lemma_iterator(text, lang, greedy=False)
Iterate over lemmatized tokens in a text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The text to iterate over. |
required |
lang |
Union[str, Tuple[str, ...]]
|
The language or languages for lemmatization. |
required |
greedy |
bool
|
A flag indicating whether to use greedy lemmatization (default: False). |
False
|
tokenizer |
The tokenizer to use (default: RegexTokenizer()). |
required |
Yields:
Name | Type | Description |
---|---|---|
str |
str
|
The lemmatized tokens in the text. |
Source code in simplemma/lemmatizer.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
lemmatize(token, lang, greedy=False)
Lemmatize a token in the specified language(s).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
The token to lemmatize. |
required |
lang |
Union[str, Tuple[str, ...]]
|
The language or languages for lemmatization. |
required |
greedy |
bool
|
A flag indicating whether to use greedy lemmatization (default: False). |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The lemmatized form of the token. |
Source code in simplemma/lemmatizer.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
text_lemmatizer(text, lang, greedy=False)
Lemmatize a text in the specified language(s).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text |
str
|
The text to lemmatize. |
required |
lang |
Union[str, Tuple[str, ...]]
|
The language or languages for lemmatization. |
required |
greedy |
bool
|
A flag indicating whether to use greedy lemmatization (default: False). |
False
|
tokenizer |
The tokenizer to use (default: RegexTokenizer()). |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: The list of lemmatized tokens. |
Source code in simplemma/lemmatizer.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|