Conditions | 132 |
Total Lines | 249 |
Code Lines | 201 |
Lines | 0 |
Ratio | 0 % |
Tests | 197 |
CRAP Score | 132 |
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._snowball.porter() 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 -*- |
||
116 | r1_prefixes (set): Prefixes to consider |
||
117 | |||
118 | Returns: |
||
119 | bool: True iff term is a short word |
||
120 | |||
121 | """ |
||
122 | 1 | if self._sb_r1(term, r1_prefixes) == len( |
|
123 | term |
||
124 | ) and self._sb_ends_in_short_syllable(term): |
||
125 | 1 | return True |
|
126 | 1 | return False |
|
127 | |||
128 | 1 | def _sb_has_vowel(self, term): |
|
129 | """Return Porter helper function _sb_has_vowel value. |
||
130 | |||
131 | Args: |
||
132 | term (str): The term to examine |
||
133 | |||
134 | Returns: |
||
135 | bool: True iff a vowel exists in the term (as defined in the Porter |
||
136 | stemmer definition) |
||
137 | |||
138 | """ |
||
139 | 1 | for letter in term: |
|
140 | 1 | if letter in self._vowels: |
|
141 | 1 | return True |
|
142 | 1 | return False |
|
143 | |||
144 | |||
145 | if __name__ == '__main__': |
||
146 | import doctest |
||
147 | |||
148 | doctest.testmod() |
||
149 |