SnowballAnalyzer.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
"""Snowball analyzer for Annif, based on nltk Snowball stemmer."""
2
3
from __future__ import annotations
4
5
import functools
6
7
from . import analyzer
8
9
10
class SnowballAnalyzer(analyzer.Analyzer):
11
    name = "snowball"
12
13
    def __init__(self, param: str, **kwargs) -> None:
14
        self.param = param
15
        import nltk.stem.snowball
16
17
        self.stemmer = nltk.stem.snowball.SnowballStemmer(param)
18
        super().__init__(**kwargs)
19
20
    @functools.lru_cache(maxsize=500000)
21
    def _normalize_word(self, word: str) -> str:
22
        return self.stemmer.stem(word.lower())
23