Conditions | 23 |
Total Lines | 99 |
Code Lines | 65 |
Lines | 36 |
Ratio | 36.36 % |
Tests | 44 |
CRAP Score | 23 |
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._SnowballDanish.SnowballDanish.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 -*- |
||
71 | 1 | def stem(self, word): |
|
72 | """Return Snowball Danish stem. |
||
73 | |||
74 | Args: |
||
75 | word (str): The word to stem |
||
76 | |||
77 | Returns: |
||
78 | str: Word stem |
||
79 | |||
80 | Examples: |
||
81 | >>> stmr = SnowballDanish() |
||
82 | >>> stmr.stem('underviser') |
||
83 | 'undervis' |
||
84 | >>> stmr.stem('suspension') |
||
85 | 'suspension' |
||
86 | >>> stmr.stem('sikkerhed') |
||
87 | 'sikker' |
||
88 | |||
89 | """ |
||
90 | # lowercase, normalize, and compose |
||
91 | 1 | word = normalize('NFC', text_type(word.lower())) |
|
92 | |||
93 | 1 | r1_start = min(max(3, self._sb_r1(word)), len(word)) |
|
94 | |||
95 | # Step 1 |
||
96 | 1 | _r1 = word[r1_start:] |
|
97 | 1 | View Code Duplication | if _r1[-7:] == 'erendes': |
98 | 1 | word = word[:-7] |
|
99 | 1 | elif _r1[-6:] in {'erende', 'hedens'}: |
|
100 | 1 | word = word[:-6] |
|
101 | 1 | elif _r1[-5:] in { |
|
102 | 'ethed', |
||
103 | 'erede', |
||
104 | 'heden', |
||
105 | 'heder', |
||
106 | 'endes', |
||
107 | 'ernes', |
||
108 | 'erens', |
||
109 | 'erets', |
||
110 | }: |
||
111 | 1 | word = word[:-5] |
|
112 | 1 | elif _r1[-4:] in { |
|
113 | 'ered', |
||
114 | 'ende', |
||
115 | 'erne', |
||
116 | 'eren', |
||
117 | 'erer', |
||
118 | 'heds', |
||
119 | 'enes', |
||
120 | 'eres', |
||
121 | 'eret', |
||
122 | }: |
||
123 | 1 | word = word[:-4] |
|
124 | 1 | elif _r1[-3:] in {'hed', 'ene', 'ere', 'ens', 'ers', 'ets'}: |
|
125 | 1 | word = word[:-3] |
|
126 | 1 | elif _r1[-2:] in {'en', 'er', 'es', 'et'}: |
|
127 | 1 | word = word[:-2] |
|
128 | 1 | elif _r1[-1:] == 'e': |
|
129 | 1 | word = word[:-1] |
|
130 | 1 | elif _r1[-1:] == 's': |
|
131 | 1 | if len(word) > 1 and word[-2] in self._s_endings: |
|
132 | 1 | word = word[:-1] |
|
133 | |||
134 | # Step 2 |
||
135 | 1 | if word[r1_start:][-2:] in {'gd', 'dt', 'gt', 'kt'}: |
|
136 | 1 | word = word[:-1] |
|
137 | |||
138 | # Step 3 |
||
139 | 1 | if word[-4:] == 'igst': |
|
140 | 1 | word = word[:-2] |
|
141 | |||
142 | 1 | _r1 = word[r1_start:] |
|
143 | 1 | repeat_step2 = False |
|
144 | 1 | if _r1[-4:] == 'elig': |
|
145 | 1 | word = word[:-4] |
|
146 | 1 | repeat_step2 = True |
|
147 | 1 | elif _r1[-4:] == 'løst': |
|
148 | 1 | word = word[:-1] |
|
149 | 1 | elif _r1[-3:] in {'lig', 'els'}: |
|
150 | 1 | word = word[:-3] |
|
151 | 1 | repeat_step2 = True |
|
152 | 1 | elif _r1[-2:] == 'ig': |
|
153 | 1 | word = word[:-2] |
|
154 | 1 | repeat_step2 = True |
|
155 | |||
156 | 1 | if repeat_step2: |
|
157 | 1 | if word[r1_start:][-2:] in {'gd', 'dt', 'gt', 'kt'}: |
|
158 | 1 | word = word[:-1] |
|
159 | |||
160 | # Step 4 |
||
161 | 1 | if ( |
|
162 | len(word[r1_start:]) >= 1 |
||
163 | and len(word) >= 2 |
||
164 | and word[-1] == word[-2] |
||
165 | and word[-1] not in self._vowels |
||
166 | ): |
||
167 | 1 | word = word[:-1] |
|
168 | |||
169 | 1 | return word |
|
170 | |||
199 |
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.