| Conditions | 21 |
| Total Lines | 80 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 37 |
| CRAP Score | 21 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like abydos.stemmer._SnowballNorwegian.SnowballNorwegian.stem() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # -*- coding: utf-8 -*- |
||
| 68 | 1 | def stem(self, word): |
|
| 69 | """Return Snowball Norwegian stem. |
||
| 70 | |||
| 71 | Args: |
||
| 72 | word (str): The word to stem |
||
| 73 | |||
| 74 | Returns: |
||
| 75 | str: Word stem |
||
| 76 | |||
| 77 | Examples: |
||
| 78 | >>> stmr = SnowballNorwegian() |
||
| 79 | >>> stmr.stem('lese') |
||
| 80 | 'les' |
||
| 81 | >>> stmr.stem('suspensjon') |
||
| 82 | 'suspensjon' |
||
| 83 | >>> stmr.stem('sikkerhet') |
||
| 84 | 'sikker' |
||
| 85 | |||
| 86 | """ |
||
| 87 | # lowercase, normalize, and compose |
||
| 88 | 1 | word = normalize('NFC', text_type(word.lower())) |
|
| 89 | |||
| 90 | 1 | r1_start = min(max(3, self._sb_r1(word)), len(word)) |
|
| 91 | |||
| 92 | # Step 1 |
||
| 93 | 1 | _r1 = word[r1_start:] |
|
| 94 | 1 | if _r1[-7:] == 'hetenes': |
|
| 95 | 1 | word = word[:-7] |
|
| 96 | 1 | elif _r1[-6:] in {'hetene', 'hetens'}: |
|
| 97 | 1 | word = word[:-6] |
|
| 98 | 1 | elif _r1[-5:] in {'heten', 'heter', 'endes'}: |
|
| 99 | 1 | word = word[:-5] |
|
| 100 | 1 | elif _r1[-4:] in {'ande', 'ende', 'edes', 'enes', 'erte'}: |
|
| 101 | 1 | if word[-4:] == 'erte': |
|
| 102 | 1 | word = word[:-2] |
|
| 103 | else: |
||
| 104 | 1 | word = word[:-4] |
|
| 105 | 1 | elif _r1[-3:] in { |
|
| 106 | 'ede', |
||
| 107 | 'ane', |
||
| 108 | 'ene', |
||
| 109 | 'ens', |
||
| 110 | 'ers', |
||
| 111 | 'ets', |
||
| 112 | 'het', |
||
| 113 | 'ast', |
||
| 114 | 'ert', |
||
| 115 | }: |
||
| 116 | 1 | if word[-3:] == 'ert': |
|
| 117 | 1 | word = word[:-1] |
|
| 118 | else: |
||
| 119 | 1 | word = word[:-3] |
|
| 120 | 1 | elif _r1[-2:] in {'en', 'ar', 'er', 'as', 'es', 'et'}: |
|
| 121 | 1 | word = word[:-2] |
|
| 122 | 1 | elif _r1[-1:] in {'a', 'e'}: |
|
| 123 | 1 | word = word[:-1] |
|
| 124 | 1 | elif _r1[-1:] == 's': |
|
| 125 | 1 | if (len(word) > 1 and word[-2] in self._s_endings) or ( |
|
| 126 | len(word) > 2 |
||
| 127 | and word[-2] == 'k' |
||
| 128 | and word[-3] not in self._vowels |
||
| 129 | ): |
||
| 130 | 1 | word = word[:-1] |
|
| 131 | |||
| 132 | # Step 2 |
||
| 133 | 1 | if word[r1_start:][-2:] in {'dt', 'vt'}: |
|
| 134 | 1 | word = word[:-1] |
|
| 135 | |||
| 136 | # Step 3 |
||
| 137 | 1 | _r1 = word[r1_start:] |
|
| 138 | 1 | if _r1[-7:] == 'hetslov': |
|
| 139 | 1 | word = word[:-7] |
|
| 140 | 1 | elif _r1[-4:] in {'eleg', 'elig', 'elov', 'slov'}: |
|
| 141 | 1 | word = word[:-4] |
|
| 142 | 1 | elif _r1[-3:] in {'leg', 'eig', 'lig', 'els', 'lov'}: |
|
| 143 | 1 | word = word[:-3] |
|
| 144 | 1 | elif _r1[-2:] == 'ig': |
|
| 145 | 1 | word = word[:-2] |
|
| 146 | |||
| 147 | 1 | return word |
|
| 148 | |||
| 177 |
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.