| 654 | } |
| 655 | |
| 656 | static int LevenshteinDistancesUTF8_init(LevenshteinDistancesUTF8 *self, PyObject *args, PyObject *kwargs) { |
| 657 | int match = 0, mismatch = 1, open = 1, extend = 1; |
| 658 | PyObject *capabilities_tuple = NULL; |
| 659 | sz_capability_t capabilities = default_hardware_capabilities; |
| 660 | |
| 661 | static char *kwlist[] = {"match", "mismatch", "open", "extend", "capabilities", NULL}; |
| 662 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iiiiO", kwlist, &match, &mismatch, &open, &extend, |
| 663 | &capabilities_tuple)) |
| 664 | return -1; |
| 665 | |
| 666 | // Validate range of values |
| 667 | if (match < -128 || match > 127) { |
| 668 | PyErr_SetString(PyExc_ValueError, "match cost must fit in 8-bit signed integer"); |
| 669 | return -1; |
| 670 | } |
| 671 | if (mismatch < -128 || mismatch > 127) { |
| 672 | PyErr_SetString(PyExc_ValueError, "mismatch cost must fit in 8-bit signed integer"); |
| 673 | return -1; |
| 674 | } |
| 675 | if (open < -128 || open > 127) { |
| 676 | PyErr_SetString(PyExc_ValueError, "open cost must fit in 8-bit signed integer"); |
| 677 | return -1; |
| 678 | } |
| 679 | if (extend < -128 || extend > 127) { |
| 680 | PyErr_SetString(PyExc_ValueError, "extend cost must fit in 8-bit signed integer"); |
| 681 | return -1; |
| 682 | } |
| 683 | |
| 684 | // Parse capabilities if provided |
| 685 | if (capabilities_tuple) { |
| 686 | if (parse_and_intersect_capabilities(capabilities_tuple, &capabilities) != 0) { return -1; } |
| 687 | } |
| 688 | |
| 689 | char const *error_detail = NULL; |
| 690 | sz_status_t status = szs_levenshtein_distances_utf8_init(match, mismatch, open, extend, NULL, capabilities, |
| 691 | &self->handle, &error_detail); |
| 692 | |
| 693 | if (status != sz_success_k) { |
| 694 | set_stringzilla_error(status, error_detail, "UTF-8 Levenshtein distances initialization"); |
| 695 | return -1; |
| 696 | } |
| 697 | snprintf(self->description, sizeof(self->description), "%d,%d,%d,%d", match, mismatch, open, extend); |
| 698 | self->capabilities = capabilities; |
| 699 | return 0; |
| 700 | } |
| 701 | |
| 702 | static PyObject *LevenshteinDistancesUTF8_repr(LevenshteinDistancesUTF8 *self) { |
| 703 | return PyUnicode_FromFormat("LevenshteinDistancesUTF8(match,mismatch,open,extend=%s)", self->description); |
nothing calls this directly
no test coverage detected
searching dependent graphs…