Code Duplication    Length = 45-47 lines in 2 locations

abydos/phonetic/_Haase.py 1 location

@@ 165-211 (lines=47) @@
162
        def _haase_code(word):
163
            sdx = ''
164
            for i in range(len(word)):
165
                if word[i] in self._uc_v_set:
166
                    sdx += '9'
167
                elif word[i] == 'B':
168
                    sdx += '1'
169
                elif word[i] == 'P':
170
                    if _before(word, i, {'H'}):
171
                        sdx += '3'
172
                    else:
173
                        sdx += '1'
174
                elif word[i] in {'D', 'T'}:
175
                    if _before(word, i, {'C', 'S', 'Z'}):
176
                        sdx += '8'
177
                    else:
178
                        sdx += '2'
179
                elif word[i] in {'F', 'V', 'W'}:
180
                    sdx += '3'
181
                elif word[i] in {'G', 'K', 'Q'}:
182
                    sdx += '4'
183
                elif word[i] == 'C':
184
                    if _after(word, i, {'S', 'Z'}):
185
                        sdx += '8'
186
                    elif i == 0:
187
                        if _before(
188
                            word,
189
                            i,
190
                            {'A', 'H', 'K', 'L', 'O', 'Q', 'R', 'U', 'X'},
191
                        ):
192
                            sdx += '4'
193
                        else:
194
                            sdx += '8'
195
                    elif _before(word, i, {'A', 'H', 'K', 'O', 'Q', 'U', 'X'}):
196
                        sdx += '4'
197
                    else:
198
                        sdx += '8'
199
                elif word[i] == 'X':
200
                    if _after(word, i, {'C', 'K', 'Q'}):
201
                        sdx += '8'
202
                    else:
203
                        sdx += '48'
204
                elif word[i] == 'L':
205
                    sdx += '5'
206
                elif word[i] in {'M', 'N'}:
207
                    sdx += '6'
208
                elif word[i] == 'R':
209
                    sdx += '7'
210
                elif word[i] in {'S', 'Z'}:
211
                    sdx += '8'
212
213
            sdx = self._delete_consecutive_repeats(sdx)
214

abydos/phonetic/_Koelner.py 1 location

@@ 129-173 (lines=45) @@
126
            return sdx
127
128
        for i in range(len(word)):
129
            if word[i] in self._uc_v_set:
130
                sdx += '0'
131
            elif word[i] == 'B':
132
                sdx += '1'
133
            elif word[i] == 'P':
134
                if _before(word, i, {'H'}):
135
                    sdx += '3'
136
                else:
137
                    sdx += '1'
138
            elif word[i] in {'D', 'T'}:
139
                if _before(word, i, {'C', 'S', 'Z'}):
140
                    sdx += '8'
141
                else:
142
                    sdx += '2'
143
            elif word[i] in {'F', 'V', 'W'}:
144
                sdx += '3'
145
            elif word[i] in {'G', 'K', 'Q'}:
146
                sdx += '4'
147
            elif word[i] == 'C':
148
                if _after(word, i, {'S', 'Z'}):
149
                    sdx += '8'
150
                elif i == 0:
151
                    if _before(
152
                        word, i, {'A', 'H', 'K', 'L', 'O', 'Q', 'R', 'U', 'X'}
153
                    ):
154
                        sdx += '4'
155
                    else:
156
                        sdx += '8'
157
                elif _before(word, i, {'A', 'H', 'K', 'O', 'Q', 'U', 'X'}):
158
                    sdx += '4'
159
                else:
160
                    sdx += '8'
161
            elif word[i] == 'X':
162
                if _after(word, i, {'C', 'K', 'Q'}):
163
                    sdx += '8'
164
                else:
165
                    sdx += '48'
166
            elif word[i] == 'L':
167
                sdx += '5'
168
            elif word[i] in {'M', 'N'}:
169
                sdx += '6'
170
            elif word[i] == 'R':
171
                sdx += '7'
172
            elif word[i] in {'S', 'Z'}:
173
                sdx += '8'
174
175
        sdx = self._delete_consecutive_repeats(sdx)
176