| @@ 183-229 (lines=47) @@ | ||
| 180 | def _haase_code(word): |
|
| 181 | sdx = '' |
|
| 182 | for i in range(len(word)): |
|
| 183 | if word[i] in self._uc_v_set: |
|
| 184 | sdx += '9' |
|
| 185 | elif word[i] == 'B': |
|
| 186 | sdx += '1' |
|
| 187 | elif word[i] == 'P': |
|
| 188 | if _before(word, i, {'H'}): |
|
| 189 | sdx += '3' |
|
| 190 | else: |
|
| 191 | sdx += '1' |
|
| 192 | elif word[i] in {'D', 'T'}: |
|
| 193 | if _before(word, i, {'C', 'S', 'Z'}): |
|
| 194 | sdx += '8' |
|
| 195 | else: |
|
| 196 | sdx += '2' |
|
| 197 | elif word[i] in {'F', 'V', 'W'}: |
|
| 198 | sdx += '3' |
|
| 199 | elif word[i] in {'G', 'K', 'Q'}: |
|
| 200 | sdx += '4' |
|
| 201 | elif word[i] == 'C': |
|
| 202 | if _after(word, i, {'S', 'Z'}): |
|
| 203 | sdx += '8' |
|
| 204 | elif i == 0: |
|
| 205 | if _before( |
|
| 206 | word, |
|
| 207 | i, |
|
| 208 | {'A', 'H', 'K', 'L', 'O', 'Q', 'R', 'U', 'X'}, |
|
| 209 | ): |
|
| 210 | sdx += '4' |
|
| 211 | else: |
|
| 212 | sdx += '8' |
|
| 213 | elif _before(word, i, {'A', 'H', 'K', 'O', 'Q', 'U', 'X'}): |
|
| 214 | sdx += '4' |
|
| 215 | else: |
|
| 216 | sdx += '8' |
|
| 217 | elif word[i] == 'X': |
|
| 218 | if _after(word, i, {'C', 'K', 'Q'}): |
|
| 219 | sdx += '8' |
|
| 220 | else: |
|
| 221 | sdx += '48' |
|
| 222 | elif word[i] == 'L': |
|
| 223 | sdx += '5' |
|
| 224 | elif word[i] in {'M', 'N'}: |
|
| 225 | sdx += '6' |
|
| 226 | elif word[i] == 'R': |
|
| 227 | sdx += '7' |
|
| 228 | elif word[i] in {'S', 'Z'}: |
|
| 229 | sdx += '8' |
|
| 230 | ||
| 231 | sdx = self._delete_consecutive_repeats(sdx) |
|
| 232 | ||
| @@ 146-190 (lines=45) @@ | ||
| 143 | return sdx |
|
| 144 | ||
| 145 | for i in range(len(word)): |
|
| 146 | if word[i] in self._uc_v_set: |
|
| 147 | sdx += '0' |
|
| 148 | elif word[i] == 'B': |
|
| 149 | sdx += '1' |
|
| 150 | elif word[i] == 'P': |
|
| 151 | if _before(word, i, {'H'}): |
|
| 152 | sdx += '3' |
|
| 153 | else: |
|
| 154 | sdx += '1' |
|
| 155 | elif word[i] in {'D', 'T'}: |
|
| 156 | if _before(word, i, {'C', 'S', 'Z'}): |
|
| 157 | sdx += '8' |
|
| 158 | else: |
|
| 159 | sdx += '2' |
|
| 160 | elif word[i] in {'F', 'V', 'W'}: |
|
| 161 | sdx += '3' |
|
| 162 | elif word[i] in {'G', 'K', 'Q'}: |
|
| 163 | sdx += '4' |
|
| 164 | elif word[i] == 'C': |
|
| 165 | if _after(word, i, {'S', 'Z'}): |
|
| 166 | sdx += '8' |
|
| 167 | elif i == 0: |
|
| 168 | if _before( |
|
| 169 | word, i, {'A', 'H', 'K', 'L', 'O', 'Q', 'R', 'U', 'X'} |
|
| 170 | ): |
|
| 171 | sdx += '4' |
|
| 172 | else: |
|
| 173 | sdx += '8' |
|
| 174 | elif _before(word, i, {'A', 'H', 'K', 'O', 'Q', 'U', 'X'}): |
|
| 175 | sdx += '4' |
|
| 176 | else: |
|
| 177 | sdx += '8' |
|
| 178 | elif word[i] == 'X': |
|
| 179 | if _after(word, i, {'C', 'K', 'Q'}): |
|
| 180 | sdx += '8' |
|
| 181 | else: |
|
| 182 | sdx += '48' |
|
| 183 | elif word[i] == 'L': |
|
| 184 | sdx += '5' |
|
| 185 | elif word[i] in {'M', 'N'}: |
|
| 186 | sdx += '6' |
|
| 187 | elif word[i] == 'R': |
|
| 188 | sdx += '7' |
|
| 189 | elif word[i] in {'S', 'Z'}: |
|
| 190 | sdx += '8' |
|
| 191 | ||
| 192 | sdx = self._delete_consecutive_repeats(sdx) |
|
| 193 | ||