| Conditions | 14 |
| Total Lines | 53 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 29 |
| CRAP Score | 14 |
| 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.distance._isg.ISG._isg_i() 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 -*- |
||
| 79 | 1 | def _isg_i(self, src, tar): |
|
| 80 | """Return an individual ISG similarity (not symmetric) for src to tar. |
||
| 81 | |||
| 82 | Parameters |
||
| 83 | ---------- |
||
| 84 | src : str |
||
| 85 | Source string for comparison |
||
| 86 | tar : str |
||
| 87 | Target string for comparison |
||
| 88 | |||
| 89 | Returns |
||
| 90 | ------- |
||
| 91 | float |
||
| 92 | The ISG similarity |
||
| 93 | |||
| 94 | |||
| 95 | .. versionadded:: 0.4.1 |
||
| 96 | |||
| 97 | """ |
||
| 98 | |||
| 99 | 1 | def _char_at(name, pos): |
|
| 100 | 1 | if pos >= len(name): |
|
| 101 | 1 | return None |
|
| 102 | 1 | return name[pos] |
|
| 103 | |||
| 104 | 1 | matches = 0 |
|
| 105 | 1 | for pos in range(len(src)): |
|
| 106 | 1 | s = _char_at(src, pos) |
|
| 107 | 1 | t = set(tar[max(0, pos - 1) : pos + 3]) |
|
| 108 | 1 | if s and s in t: |
|
| 109 | 1 | matches += 1 |
|
| 110 | 1 | continue |
|
| 111 | |||
| 112 | 1 | if self._full_guth: |
|
| 113 | 1 | s = set(src[max(0, pos - 1) : pos + 3]) |
|
| 114 | 1 | t = _char_at(tar, pos) |
|
| 115 | 1 | if t and t in s: |
|
| 116 | 1 | matches += 1 |
|
| 117 | 1 | continue |
|
| 118 | |||
| 119 | 1 | s = _char_at(src, pos + 1) |
|
| 120 | 1 | t = _char_at(tar, pos + 1) |
|
| 121 | 1 | if s and t and s == t: |
|
| 122 | 1 | matches += 1 |
|
| 123 | 1 | continue |
|
| 124 | |||
| 125 | 1 | s = _char_at(src, pos + 2) |
|
| 126 | 1 | t = _char_at(tar, pos + 2) |
|
| 127 | 1 | if s and t and s == t: |
|
| 128 | 1 | matches += 1 |
|
| 129 | 1 | continue |
|
| 130 | |||
| 131 | 1 | return matches / (len(src) + len(tar) - matches) |
|
| 132 | |||
| 177 |