| Total Complexity | 6 |
| Total Lines | 31 |
| Duplicated Lines | 74.19 % |
| Changes | 0 | ||
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): |
|
|
|
|||
| 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 |