| @@ 325-368 (lines=44) @@ | ||
| 322 | def _haase_code(word): |
|
| 323 | sdx = '' |
|
| 324 | for i in range(len(word)): |
|
| 325 | if word[i] in _vowels: |
|
| 326 | sdx += '9' |
|
| 327 | elif word[i] == 'B': |
|
| 328 | sdx += '1' |
|
| 329 | elif word[i] == 'P': |
|
| 330 | if _before(word, i, {'H'}): |
|
| 331 | sdx += '3' |
|
| 332 | else: |
|
| 333 | sdx += '1' |
|
| 334 | elif word[i] in {'D', 'T'}: |
|
| 335 | if _before(word, i, {'C', 'S', 'Z'}): |
|
| 336 | sdx += '8' |
|
| 337 | else: |
|
| 338 | sdx += '2' |
|
| 339 | elif word[i] in {'F', 'V', 'W'}: |
|
| 340 | sdx += '3' |
|
| 341 | elif word[i] in {'G', 'K', 'Q'}: |
|
| 342 | sdx += '4' |
|
| 343 | elif word[i] == 'C': |
|
| 344 | if _after(word, i, {'S', 'Z'}): |
|
| 345 | sdx += '8' |
|
| 346 | elif i == 0: |
|
| 347 | if _before(word, i, {'A', 'H', 'K', 'L', 'O', 'Q', 'R', |
|
| 348 | 'U', 'X'}): |
|
| 349 | sdx += '4' |
|
| 350 | else: |
|
| 351 | sdx += '8' |
|
| 352 | elif _before(word, i, {'A', 'H', 'K', 'O', 'Q', 'U', 'X'}): |
|
| 353 | sdx += '4' |
|
| 354 | else: |
|
| 355 | sdx += '8' |
|
| 356 | elif word[i] == 'X': |
|
| 357 | if _after(word, i, {'C', 'K', 'Q'}): |
|
| 358 | sdx += '8' |
|
| 359 | else: |
|
| 360 | sdx += '48' |
|
| 361 | elif word[i] == 'L': |
|
| 362 | sdx += '5' |
|
| 363 | elif word[i] in {'M', 'N'}: |
|
| 364 | sdx += '6' |
|
| 365 | elif word[i] == 'R': |
|
| 366 | sdx += '7' |
|
| 367 | elif word[i] in {'S', 'Z'}: |
|
| 368 | sdx += '8' |
|
| 369 | ||
| 370 | sdx = _delete_consecutive_repeats(sdx) |
|
| 371 | ||
| @@ 98-141 (lines=44) @@ | ||
| 95 | return sdx |
|
| 96 | ||
| 97 | for i in range(len(word)): |
|
| 98 | if word[i] in _vowels: |
|
| 99 | sdx += '0' |
|
| 100 | elif word[i] == 'B': |
|
| 101 | sdx += '1' |
|
| 102 | elif word[i] == 'P': |
|
| 103 | if _before(word, i, {'H'}): |
|
| 104 | sdx += '3' |
|
| 105 | else: |
|
| 106 | sdx += '1' |
|
| 107 | elif word[i] in {'D', 'T'}: |
|
| 108 | if _before(word, i, {'C', 'S', 'Z'}): |
|
| 109 | sdx += '8' |
|
| 110 | else: |
|
| 111 | sdx += '2' |
|
| 112 | elif word[i] in {'F', 'V', 'W'}: |
|
| 113 | sdx += '3' |
|
| 114 | elif word[i] in {'G', 'K', 'Q'}: |
|
| 115 | sdx += '4' |
|
| 116 | elif word[i] == 'C': |
|
| 117 | if _after(word, i, {'S', 'Z'}): |
|
| 118 | sdx += '8' |
|
| 119 | elif i == 0: |
|
| 120 | if _before(word, i, {'A', 'H', 'K', 'L', 'O', 'Q', 'R', 'U', |
|
| 121 | 'X'}): |
|
| 122 | sdx += '4' |
|
| 123 | else: |
|
| 124 | sdx += '8' |
|
| 125 | elif _before(word, i, {'A', 'H', 'K', 'O', 'Q', 'U', 'X'}): |
|
| 126 | sdx += '4' |
|
| 127 | else: |
|
| 128 | sdx += '8' |
|
| 129 | elif word[i] == 'X': |
|
| 130 | if _after(word, i, {'C', 'K', 'Q'}): |
|
| 131 | sdx += '8' |
|
| 132 | else: |
|
| 133 | sdx += '48' |
|
| 134 | elif word[i] == 'L': |
|
| 135 | sdx += '5' |
|
| 136 | elif word[i] in {'M', 'N'}: |
|
| 137 | sdx += '6' |
|
| 138 | elif word[i] == 'R': |
|
| 139 | sdx += '7' |
|
| 140 | elif word[i] in {'S', 'Z'}: |
|
| 141 | sdx += '8' |
|
| 142 | ||
| 143 | sdx = _delete_consecutive_repeats(sdx) |
|
| 144 | ||