@@ 233-279 (lines=47) @@ | ||
230 | def _haase_code(word: str) -> str: |
|
231 | sdx = '' |
|
232 | for i in range(len(word)): |
|
233 | if word[i] in self._uc_v_set: |
|
234 | sdx += '9' |
|
235 | elif word[i] == 'B': |
|
236 | sdx += '1' |
|
237 | elif word[i] == 'P': |
|
238 | if _before(word, i, {'H'}): |
|
239 | sdx += '3' |
|
240 | else: |
|
241 | sdx += '1' |
|
242 | elif word[i] in {'D', 'T'}: |
|
243 | if _before(word, i, {'C', 'S', 'Z'}): |
|
244 | sdx += '8' |
|
245 | else: |
|
246 | sdx += '2' |
|
247 | elif word[i] in {'F', 'V', 'W'}: |
|
248 | sdx += '3' |
|
249 | elif word[i] in {'G', 'K', 'Q'}: |
|
250 | sdx += '4' |
|
251 | elif word[i] == 'C': |
|
252 | if _after(word, i, {'S', 'Z'}): |
|
253 | sdx += '8' |
|
254 | elif i == 0: |
|
255 | if _before( |
|
256 | word, |
|
257 | i, |
|
258 | {'A', 'H', 'K', 'L', 'O', 'Q', 'R', 'U', 'X'}, |
|
259 | ): |
|
260 | sdx += '4' |
|
261 | else: |
|
262 | sdx += '8' |
|
263 | elif _before(word, i, {'A', 'H', 'K', 'O', 'Q', 'U', 'X'}): |
|
264 | sdx += '4' |
|
265 | else: |
|
266 | sdx += '8' |
|
267 | elif word[i] == 'X': |
|
268 | if _after(word, i, {'C', 'K', 'Q'}): |
|
269 | sdx += '8' |
|
270 | else: |
|
271 | sdx += '48' |
|
272 | elif word[i] == 'L': |
|
273 | sdx += '5' |
|
274 | elif word[i] in {'M', 'N'}: |
|
275 | sdx += '6' |
|
276 | elif word[i] == 'R': |
|
277 | sdx += '7' |
|
278 | elif word[i] in {'S', 'Z'}: |
|
279 | sdx += '8' |
|
280 | ||
281 | sdx = self._delete_consecutive_repeats(sdx) |
|
282 |
@@ 142-186 (lines=45) @@ | ||
139 | return sdx |
|
140 | ||
141 | for i in range(len(word)): |
|
142 | if word[i] in self._uc_v_set: |
|
143 | sdx += '0' |
|
144 | elif word[i] == 'B': |
|
145 | sdx += '1' |
|
146 | elif word[i] == 'P': |
|
147 | if _before(word, i, {'H'}): |
|
148 | sdx += '3' |
|
149 | else: |
|
150 | sdx += '1' |
|
151 | elif word[i] in {'D', 'T'}: |
|
152 | if _before(word, i, {'C', 'S', 'Z'}): |
|
153 | sdx += '8' |
|
154 | else: |
|
155 | sdx += '2' |
|
156 | elif word[i] in {'F', 'V', 'W'}: |
|
157 | sdx += '3' |
|
158 | elif word[i] in {'G', 'K', 'Q'}: |
|
159 | sdx += '4' |
|
160 | elif word[i] == 'C': |
|
161 | if _after(word, i, {'S', 'Z'}): |
|
162 | sdx += '8' |
|
163 | elif i == 0: |
|
164 | if _before( |
|
165 | word, i, {'A', 'H', 'K', 'L', 'O', 'Q', 'R', 'U', 'X'} |
|
166 | ): |
|
167 | sdx += '4' |
|
168 | else: |
|
169 | sdx += '8' |
|
170 | elif _before(word, i, {'A', 'H', 'K', 'O', 'Q', 'U', 'X'}): |
|
171 | sdx += '4' |
|
172 | else: |
|
173 | sdx += '8' |
|
174 | elif word[i] == 'X': |
|
175 | if _after(word, i, {'C', 'K', 'Q'}): |
|
176 | sdx += '8' |
|
177 | else: |
|
178 | sdx += '48' |
|
179 | elif word[i] == 'L': |
|
180 | sdx += '5' |
|
181 | elif word[i] in {'M', 'N'}: |
|
182 | sdx += '6' |
|
183 | elif word[i] == 'R': |
|
184 | sdx += '7' |
|
185 | elif word[i] in {'S', 'Z'}: |
|
186 | sdx += '8' |
|
187 | ||
188 | sdx = self._delete_consecutive_repeats(sdx) |
|
189 |