| @@ 176-189 (lines=14) @@ | ||
| 173 | if backtrace: |
|
| 174 | trace_mat[i + 1, j + 1] = int(np.argmin(opts)) |
|
| 175 | ||
| 176 | if self._mode == 'osa': |
|
| 177 | if ( |
|
| 178 | i + 1 > 1 |
|
| 179 | and j + 1 > 1 |
|
| 180 | and src[i] == tar[j - 1] |
|
| 181 | and src[i - 1] == tar[j] |
|
| 182 | ): |
|
| 183 | # transposition |
|
| 184 | d_mat[i + 1, j + 1] = min( |
|
| 185 | d_mat[i + 1, j + 1], |
|
| 186 | d_mat[i - 1, j - 1] + trans_cost, |
|
| 187 | ) |
|
| 188 | if backtrace: |
|
| 189 | trace_mat[i + 1, j + 1] = 2 |
|
| 190 | if backtrace: |
|
| 191 | return d_mat, trace_mat |
|
| 192 | return d_mat |
|
| @@ 216-228 (lines=13) @@ | ||
| 213 | if backtrace: |
|
| 214 | trace_mat[i + 1, j + 1] = int(np.argmin(opts)) |
|
| 215 | ||
| 216 | if self._mode == 'osa': |
|
| 217 | if ( |
|
| 218 | i + 1 > 1 |
|
| 219 | and j + 1 > 1 |
|
| 220 | and src[i] == tar[j - 1] |
|
| 221 | and src[i - 1] == tar[j] |
|
| 222 | ): |
|
| 223 | # transposition |
|
| 224 | d_mat[i + 1, j + 1] = min( |
|
| 225 | d_mat[i + 1, j + 1], d_mat[i - 1, j - 1] + cost |
|
| 226 | ) |
|
| 227 | if backtrace: |
|
| 228 | trace_mat[i + 1, j + 1] = 2 |
|
| 229 | if backtrace: |
|
| 230 | return d_mat, trace_mat |
|
| 231 | return d_mat |
|