| @@ 439-482 (lines=44) @@ | ||
| 436 | def _haase_code(word): |
|
| 437 | sdx = '' |
|
| 438 | for i in range(len(word)): |
|
| 439 | if word[i] in _vowels: |
|
| 440 | sdx += '9' |
|
| 441 | elif word[i] == 'B': |
|
| 442 | sdx += '1' |
|
| 443 | elif word[i] == 'P': |
|
| 444 | if _before(word, i, {'H'}): |
|
| 445 | sdx += '3' |
|
| 446 | else: |
|
| 447 | sdx += '1' |
|
| 448 | elif word[i] in {'D', 'T'}: |
|
| 449 | if _before(word, i, {'C', 'S', 'Z'}): |
|
| 450 | sdx += '8' |
|
| 451 | else: |
|
| 452 | sdx += '2' |
|
| 453 | elif word[i] in {'F', 'V', 'W'}: |
|
| 454 | sdx += '3' |
|
| 455 | elif word[i] in {'G', 'K', 'Q'}: |
|
| 456 | sdx += '4' |
|
| 457 | elif word[i] == 'C': |
|
| 458 | if _after(word, i, {'S', 'Z'}): |
|
| 459 | sdx += '8' |
|
| 460 | elif i == 0: |
|
| 461 | if _before( |
|
| 462 | word, i, {'A', 'H', 'K', 'L', 'O', 'Q', 'R', 'U', 'X'} |
|
| 463 | ): |
|
| 464 | sdx += '4' |
|
| 465 | else: |
|
| 466 | sdx += '8' |
|
| 467 | elif _before(word, i, {'A', 'H', 'K', 'O', 'Q', 'U', 'X'}): |
|
| 468 | sdx += '4' |
|
| 469 | else: |
|
| 470 | sdx += '8' |
|
| 471 | elif word[i] == 'X': |
|
| 472 | if _after(word, i, {'C', 'K', 'Q'}): |
|
| 473 | sdx += '8' |
|
| 474 | else: |
|
| 475 | sdx += '48' |
|
| 476 | elif word[i] == 'L': |
|
| 477 | sdx += '5' |
|
| 478 | elif word[i] in {'M', 'N'}: |
|
| 479 | sdx += '6' |
|
| 480 | elif word[i] == 'R': |
|
| 481 | sdx += '7' |
|
| 482 | elif word[i] in {'S', 'Z'}: |
|
| 483 | sdx += '8' |
|
| 484 | ||
| 485 | sdx = _delete_consecutive_repeats(sdx) |
|
| @@ 133-176 (lines=44) @@ | ||
| 130 | return sdx |
|
| 131 | ||
| 132 | for i in range(len(word)): |
|
| 133 | if word[i] in _vowels: |
|
| 134 | sdx += '0' |
|
| 135 | elif word[i] == 'B': |
|
| 136 | sdx += '1' |
|
| 137 | elif word[i] == 'P': |
|
| 138 | if _before(word, i, {'H'}): |
|
| 139 | sdx += '3' |
|
| 140 | else: |
|
| 141 | sdx += '1' |
|
| 142 | elif word[i] in {'D', 'T'}: |
|
| 143 | if _before(word, i, {'C', 'S', 'Z'}): |
|
| 144 | sdx += '8' |
|
| 145 | else: |
|
| 146 | sdx += '2' |
|
| 147 | elif word[i] in {'F', 'V', 'W'}: |
|
| 148 | sdx += '3' |
|
| 149 | elif word[i] in {'G', 'K', 'Q'}: |
|
| 150 | sdx += '4' |
|
| 151 | elif word[i] == 'C': |
|
| 152 | if _after(word, i, {'S', 'Z'}): |
|
| 153 | sdx += '8' |
|
| 154 | elif i == 0: |
|
| 155 | if _before( |
|
| 156 | word, i, {'A', 'H', 'K', 'L', 'O', 'Q', 'R', 'U', 'X'} |
|
| 157 | ): |
|
| 158 | sdx += '4' |
|
| 159 | else: |
|
| 160 | sdx += '8' |
|
| 161 | elif _before(word, i, {'A', 'H', 'K', 'O', 'Q', 'U', 'X'}): |
|
| 162 | sdx += '4' |
|
| 163 | else: |
|
| 164 | sdx += '8' |
|
| 165 | elif word[i] == 'X': |
|
| 166 | if _after(word, i, {'C', 'K', 'Q'}): |
|
| 167 | sdx += '8' |
|
| 168 | else: |
|
| 169 | sdx += '48' |
|
| 170 | elif word[i] == 'L': |
|
| 171 | sdx += '5' |
|
| 172 | elif word[i] in {'M', 'N'}: |
|
| 173 | sdx += '6' |
|
| 174 | elif word[i] == 'R': |
|
| 175 | sdx += '7' |
|
| 176 | elif word[i] in {'S', 'Z'}: |
|
| 177 | sdx += '8' |
|
| 178 | ||
| 179 | sdx = _delete_consecutive_repeats(sdx) |
|