Completed
Push — master ( cf5fd0...1b4762 )
by Osma
15s queued 12s
created

annif.analyzer.voikko   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 74.19 %

Importance

Changes 0
Metric Value
eloc 20
dl 23
loc 31
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A VoikkoAnalyzer.__init__() 4 4 1
A VoikkoAnalyzer.__getstate__() 6 6 1
A VoikkoAnalyzer._normalize_word() 8 8 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
"""Voikko analyzer for Annif, based on libvoikko library."""
2
3
import functools
4
import voikko.libvoikko
5
from . import analyzer
6
7
8 View Code Duplication
class VoikkoAnalyzer(analyzer.Analyzer):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
    name = "voikko"
10
11
    def __init__(self, param, **kwargs):
12
        self.param = param
13
        self.voikko = None
14
        super().__init__(**kwargs)
15
16
    def __getstate__(self):
17
        """Return the state of the object for pickling purposes. The Voikko
18
        instance is set to None because as a ctypes object it cannot be
19
        pickled."""
20
21
        return {'param': self.param, 'voikko': None}
22
23
    @functools.lru_cache(maxsize=500000)
24
    def _normalize_word(self, word):
25
        if self.voikko is None:
26
            self.voikko = voikko.libvoikko.Voikko(self.param)
27
        result = self.voikko.analyze(word)
28
        if len(result) > 0 and 'BASEFORM' in result[0]:
29
            return result[0]['BASEFORM']
30
        return word
31